mirror of
https://github.com/appium/appium.git
synced 2026-02-11 04:20:00 -06:00
add tests for new '-real xpath' temporary loc strat
and test for new real xml page source
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user