From 1a3fa222cb973f4bbd968469ed161cf8d487c93e Mon Sep 17 00:00:00 2001 From: sebv Date: Thu, 27 Mar 2014 12:01:34 +0800 Subject: [PATCH] Only counting displayed elements --- .../ios/uicatalog/find-element-specs.js | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/test/functional/ios/uicatalog/find-element-specs.js b/test/functional/ios/uicatalog/find-element-specs.js index 39a546d77..4e63f7869 100644 --- a/test/functional/ios/uicatalog/find-element-specs.js +++ b/test/functional/ios/uicatalog/find-element-specs.js @@ -207,10 +207,24 @@ describe('uicatalog - find element -', function () { }); describe('FindElement(s)ByUIAutomation', function () { + var byUIA = '-ios_uiautomation'; + + // Running sequentially cause parallel runs crash appium + var filterDisplayed = function (els) { + var sequence = _.map(els, function (el) { + return function (displayedEls) { + return el.isDisplayed().then(function (isdisplayed) { + if (isdisplayed) displayedEls.push(el); + return displayedEls; + }); + }; + }); + return sequence.reduce(Q.when, new Q([])); + }; before(function (done) { driver - .element('-ios_uiautomation', '.navigationBars()[0]') + .element(byUIA, '.navigationBars()[0]') .getAttribute('name').then(function (name) { if (name !== 'UICatalog') { return driver.back().delay(2000); @@ -223,60 +237,60 @@ describe('uicatalog - find element -', function () { it('should process most basic UIAutomation query', function (done) { driver - .elements('-ios_uiautomation', '.elements()') + .elements(byUIA, '.elements()').then(filterDisplayed) .should.eventually.have.length(2) .nodeify(done); }); it('should process UIAutomation queries if user leaves out the first period', function (done) { driver - .elements('-ios_uiautomation', 'elements()') + .elements(byUIA, 'elements()').then(filterDisplayed) .should.eventually.have.length(2) .nodeify(done); }); it('should get a single element', function (done) { - driver.element('-ios_uiautomation', '.elements()[0]').getAttribute('name') + driver.element(byUIA, '.elements()[0]').getAttribute('name') .should.become('UICatalog') .nodeify(done); }); it('should get a single element', function (done) { - driver.element('-ios_uiautomation', '.elements()[1]').getAttribute('name') + driver.element(byUIA, '.elements()[1]').getAttribute('name') .should.become('Empty list') .nodeify(done); }); it('should get single element as array', function (done) { driver - .elements('-ios_uiautomation', '.tableViews()[0]') + .elements(byUIA, '.tableViews()[0]') .should.eventually.have.length(1) .nodeify(done); }); it('should find elements by index multiple times', function (done) { - driver.element('-ios_uiautomation', '.elements()[1].cells()[2]').getAttribute('name') + driver.element(byUIA, '.elements()[1].cells()[2]').getAttribute('name') .should.become('TextFields, Uses of UITextField') .nodeify(done); }); it('should find elements by name', function (done) { - driver.element('-ios_uiautomation', '.elements()["UICatalog"]').getAttribute('name') + driver.element(byUIA, '.elements()["UICatalog"]').getAttribute('name') .should.become('UICatalog') .nodeify(done); }); it('should find elements by name and index', function (done) { - driver.element('-ios_uiautomation', '.elements()["Empty list"].cells()[3]').getAttribute('name') + driver.element(byUIA, '.elements()["Empty list"].cells()[3]').getAttribute('name') .should.become('SearchBar, Use of UISearchBar') .nodeify(done); }); describe('start from a given context instead of root target', function () { it('should process a simple query', function (done) { - driver.element('-ios_uiautomation', '.elements()[1]').then(function (el) { + driver.element(byUIA, '.elements()[1]').then(function (el) { el - .elements('-ios_uiautomation', '.elements()') + .elements(byUIA, '.elements()') .should.eventually.have.length(12) .nodeify(done); }); }); it('should find elements by name', function (done) { - driver.element('-ios_uiautomation', '.elements()[1]').then(function (el) { + driver.element(byUIA, '.elements()[1]').then(function (el) { el - .element('-ios_uiautomation', '.elements()["Buttons, Various uses of UIButton"]') + .element(byUIA, '.elements()["Buttons, Various uses of UIButton"]') .should.eventually.exist .nodeify(done); });