This commit is contained in:
Jonathan Lipps 2013-02-15 16:41:07 -08:00
Родитель 75641cafec
Коммит 45efbf6d9d
3 изменённых файлов: 69 добавлений и 17 удалений

Просмотреть файл

@ -177,14 +177,12 @@ $.extend(au, {
return this._returnElems(elems);
}
, getElementsByType: function(type, ctx) {
var selector = type;
, convertSelector: function(selector) {
// some legacy: be backwards compatible, mechanic.js
switch (type) {
switch (selector) {
case 'tableView':
case 'textField':
selector = type.toLowerCase();
selector = selector.toLowerCase();
break;
case 'staticText':
selector = 'text';
@ -196,6 +194,11 @@ $.extend(au, {
selector = 'secure';
break;
}
return selector;
}
, getElementsByType: function(type, ctx) {
var selector = this.convertSelector(type);
var elems = [];
@ -251,8 +254,9 @@ $.extend(au, {
elems = $(_ctx);
for (var i = 0; i < xpObj.path.length; i++) {
var path = xpObj.path[i];
path.node = this.convertSelector(path.node);
if (path.search === "child") {
elems = elems.children(path.node);
elems = elems.childrenByType(path.node);
} else if (path.search === "desc") {
elems = elems.find(path.node);
}

Просмотреть файл

@ -296,6 +296,19 @@ var mechanic = (function() {
children: function(selector) {
return filtered(this.map(function(){ return slice.call(this.elements()) }), selector);
},
childrenByType: function(type) {
var result = this.map(function() {
var children = this.elements();
var filtered = [];
for (var i = 0; i < children.length; i++) {
if (children[i].isType(type)) {
filtered.push(children[i]);
}
}
return filtered;
});
return $(result);
},
siblings: function(selector) {
return filtered(this.map(function(i, el) {
return slice.call(el.parent().elements()).filter(function(child){ return child!==el });

Просмотреть файл

@ -2,6 +2,7 @@
"use strict";
var describeWd = require("../../helpers/driverblock.js").describeForApp('UICatalog')
, _ = require("underscore")
, should = require('should');
describeWd('findElementFromElement', function(h) {
@ -103,20 +104,54 @@ describeWd('findElement(s)ByXpath', function(h) {
});
});
});
it.only('should search an extended path', function(done) {
it('should know how to restrict root-level elements', function(done) {
setupXpath(h.driver, function() {
h.driver.source(function(err, s) {
console.log(s);
h.driver.elementByXPath("/button", function(err, el) {
should.exist(err);
err.status.should.equal(7);
done();
});
//h.driver.elementByXPath("button[@name='Rounded']", function(err, el) {
//should.not.exist(err);
//el.text(function(err, text) {
//should.not.exist(err);
//text.should.equal("Rounded");
//done();
//});
//});
});
});
it('should search an extended path by child', function(done) {
setupXpath(h.driver, function() {
h.driver.elementsByXPath("navigationBar/text", function(err, els) {
should.not.exist(err);
els[0].text(function(err, text) {
text.should.equal('Buttons');
done();
});
});
});
});
it('should search an extended path by descendant', function(done) {
setupXpath(h.driver, function() {
h.driver.elementsByXPath("cell//button", function(err, els) {
should.not.exist(err);
var texts = [];
_.each(els, function(el) {
el.text(function(err, text) {
texts.push(text);
if (texts.length === els.length) {
var hasNavButton = _.contains(texts, "Button");
hasNavButton.should.equal(false);
_.contains(texts, "Gray").should.equal(true);
done();
}
});
});
});
});
});
it('should filter by partial text', function(done) {
setupXpath(h.driver, function() {
h.driver.elementByXPath("cell//button[contains(@name, 'Gr')]", function(err, el) {
should.not.exist(err);
el.text(function(err, text) {
text.should.equal("Gray");
done();
});
});
});
});
});