diff --git a/test/functional/common/setup-base.js b/test/functional/common/setup-base.js index edc5e22f3..245c54c15 100644 --- a/test/functional/common/setup-base.js +++ b/test/functional/common/setup-base.js @@ -10,6 +10,14 @@ chai.should(); chaiAsPromised.transferPromiseness = wd.transferPromiseness; require("colors"); +wd.addPromiseChainMethod('elementByRealXPath', function (selector) { + return this.element('-real xpath', selector); +}); + +wd.addPromiseChainMethod('elementsByRealXPath', function (selector) { + return this.elements('-real xpath', selector); +}); + module.exports = function (context, desired, opts) { context.timeout(env.MOCHA_INIT_TIMEOUT); diff --git a/test/functional/ios/testapp/source-specs.js b/test/functional/ios/testapp/source-specs.js index 5f3c88edf..c197b7c54 100644 --- a/test/functional/ios/testapp/source-specs.js +++ b/test/functional/ios/testapp/source-specs.js @@ -1,13 +1,15 @@ "use strict"; -var setup = require("../../common/setup-base"), - desired = require('./desired'); +var setup = require("../../common/setup-base") + , xpath = require("xpath") + , XMLDom = require("xmldom").DOMParser + , desired = require('./desired'); describe('testapp - source -', function () { var driver; setup(this, desired).then(function (d) { driver = d; }); - return it('should return the page source', function (done) { + it('should return the page source as json', function (done) { driver.source().then(function (source) { var obj = JSON.parse(source); obj.should.exist; @@ -18,4 +20,13 @@ describe('testapp - source -', function () { obj.children[0].children[4].visible.should.be.ok; }).nodeify(done); }); + + it('should return page source as xml', function (done) { + driver.execute("mobile: source", [{type: "xml"}]) + .then(function (source) { + var dom = new XMLDom().parseFromString(source); + var nodes = xpath.select('//UIAButton', dom); + nodes.length.should.equal(6); + }).nodeify(done); + }); }); diff --git a/test/functional/ios/uicatalog/find-element-specs.js b/test/functional/ios/uicatalog/find-element-specs.js index d289cb3ed..b1c9520f7 100644 --- a/test/functional/ios/uicatalog/find-element-specs.js +++ b/test/functional/ios/uicatalog/find-element-specs.js @@ -119,7 +119,7 @@ describe('uicatalog - find element -', function () { }); - describe('findElement(s)ByXpath', function () { + describe('findElement(s)ByXPath', function () { var setupXpath = function (driver) { return driver.elementByTagName('tableCell').click(); }; @@ -206,6 +206,93 @@ describe('uicatalog - find element -', function () { }); }); + describe('findElement(s)ByRealXPath', function () { + var setupXpath = function (driver) { + return driver.elementByTagName('tableCell').click(); + }; + + if (process.env.FAST_TESTS) { + afterEach(function (done) { + driver + .back() + .nodeify(done); + }); + } + + it('should return the last button', function (done) { + driver + .resolve(setupXpath(driver)) + .elementByRealXPath("//UIAButton[last()]").text() + .should.become("Add contact") + .nodeify(done); + }); + it('should return a single element', function (done) { + driver + .resolve(setupXpath(driver)) + .elementByRealXPath("//UIAButton").text() + .should.become("Back") + .nodeify(done); + }); + it('should return multiple elements', function (done) { + driver + .resolve(setupXpath(driver)) + .elementsByRealXPath("//UIAButton") + .should.eventually.have.length.above(5) + .nodeify(done); + }); + it('should filter by name', function (done) { + driver + .resolve(setupXpath(driver)) + .elementByRealXPath("//UIAButton[@name='Rounded']").text() + .should.become("Rounded") + .nodeify(done); + }); + it('should know how to restrict root-level elements', function (done) { + driver + .resolve(setupXpath(driver)) + .elementByRealXPath("/UIAButton") + .should.be.rejectedWith(/status: 7/) + .nodeify(done); + }); + it('should search an extended path by child', function (done) { + driver + .resolve(setupXpath(driver)) + .then(function () { + return spinWait(function () { + return driver.elementByRealXPath("//UIANavigationBar/UIAStaticText") + .text().should.become('Buttons'); + }); + }).nodeify(done); + }); + it('should search an extended path by descendant', function (done) { + driver + .resolve(setupXpath(driver)) + .elementsByRealXPath("//UIATableCell//UIAButton").then(function (els) { + return Q.all(_(els).map(function (el) { return el.text(); })); + }).then(function (texts) { + texts.should.not.include("Button"); + texts.should.include("Gray"); + }).nodeify(done); + }); + it('should filter by indices', function (done) { + driver + .resolve(setupXpath(driver)) + .then(function () { + return spinWait(function () { + return driver.elementByRealXPath("//UIATableCell[2]//UIAStaticText[1]").getAttribute('name') + .should.become("ButtonsViewController.m:\r(UIButton *)grayButton"); + }); + }).nodeify(done); + }); + it('should filter by partial text', function (done) { + driver + .resolve(setupXpath(driver)) + .elementByRealXPath("//UIATableCell//UIAButton[contains(@name, 'Gr')]").text() + .should.become("Gray") + .nodeify(done); + }); + }); + describe('FindElement(s)ByUIAutomation', function () { var byUIA = '-ios uiautomation';