Skip to content

Commit

Permalink
add tests for new '-real xpath' temporary loc strat
Browse files Browse the repository at this point in the history
and test for new real xml page source
  • Loading branch information
jlipps committed Mar 27, 2014
1 parent af2427a commit d0474f3
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
8 changes: 8 additions & 0 deletions test/functional/common/setup-base.js
Expand Up @@ -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);

Expand Down
17 changes: 14 additions & 3 deletions 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;
Expand All @@ -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);
});
});
89 changes: 88 additions & 1 deletion test/functional/ios/uicatalog/find-element-specs.js
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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';

Expand Down

0 comments on commit d0474f3

Please sign in to comment.