Commit 58b0619f authored by Arthur Verschaeve's avatar Arthur Verschaeve

Merge pull request #1370 from tastejs/sjs/fix-stale

fix stale element errors
parents 266ea64a 8ccca748
...@@ -43,8 +43,28 @@ module.exports = function Page(browser) { ...@@ -43,8 +43,28 @@ module.exports = function Page(browser) {
return !idSelectors ? '//span[@id="todo-count"]' : '//span[contains(@class, "todo-count")]'; return !idSelectors ? '//span[@id="todo-count"]' : '//span[contains(@class, "todo-count")]';
}; };
this.getFilterElementsXpath = function () { this.getFiltersElementXpath = function () {
return !idSelectors ? '//ul[@id="filters"]//a' : '//ul[contains(@class, "filters")]//a'; return !idSelectors ? '//ul[@id="filters"]' : '//ul[contains(@class, "filters")]';
};
this.getFilterXpathByIndex = function (index) {
return this.getFiltersElementXpath() + '/li[' + index + ']/a';
};
this.getSelectedFilterXPathByIndex = function (index) {
return this.getFilterXpathByIndex(index) + '[contains(@class, "selected")]';
};
this.getFilterAllXpath = function () {
return this.getFilterXpathByIndex(1);
};
this.getFilterActiveXpath = function () {
return this.getFilterXpathByIndex(2);
};
this.getFilterCompletedXpath = function () {
return this.getFilterXpathByIndex(3);
}; };
this.xPathForItemAtIndex = function (index) { this.xPathForItemAtIndex = function (index) {
...@@ -121,10 +141,6 @@ module.exports = function Page(browser) { ...@@ -121,10 +141,6 @@ module.exports = function Page(browser) {
return this.findByXpath(this.xPathForItemAtIndex(index) + '//label'); return this.findByXpath(this.xPathForItemAtIndex(index) + '//label');
}; };
this.getFilterElements = function () {
return this.tryFindByXpath(this.getFilterElementsXpath());
};
this.getItemLabels = function () { this.getItemLabels = function () {
var xpath = this.getTodoListXpath() + '/li//label'; var xpath = this.getTodoListXpath() + '/li//label';
return this.tryFindByXpath(xpath); return this.tryFindByXpath(xpath);
...@@ -211,20 +227,14 @@ module.exports = function Page(browser) { ...@@ -211,20 +227,14 @@ module.exports = function Page(browser) {
}; };
this.filterByActiveItems = function () { this.filterByActiveItems = function () {
return this.getFilterElements().then(function (filters) { return this.findByXpath(this.getFilterActiveXpath()).click();
filters[1].click();
});
}; };
this.filterByCompletedItems = function () { this.filterByCompletedItems = function () {
return this.getFilterElements().then(function (filters) { return this.findByXpath(this.getFilterCompletedXpath()).click();
filters[2].click();
});
}; };
this.filterByAllItems = function () { this.filterByAllItems = function () {
return this.getFilterElements().then(function (filters) { return this.findByXpath(this.getFilterAllXpath()).click();
filters[0].click();
});
}; };
}; };
...@@ -173,30 +173,10 @@ function TestOperations(page) { ...@@ -173,30 +173,10 @@ function TestOperations(page) {
}); });
}; };
function isSelected(cssClass) {
return cssClass.indexOf('selected') !== -1;
}
this.assertFilterAtIndexIsSelected = function (selectedIndex) { this.assertFilterAtIndexIsSelected = function (selectedIndex) {
page.getFilterElements().then(function (filterElements) { page.findByXpath(page.getSelectedFilterXPathByIndex(selectedIndex + 1))
.then(function (elm) {
// create an array of promises, each one holding a test assert.notEqual(undefined, elm, 'the filter / route at index ' + selectedIndex + ' should have been selected');
var tests = [];
// push a test into the array, avoiding the classic JS for loops + closures issue!
function pushTest(itemIndex) {
tests.push(filterElements[itemIndex].getAttribute('class').then(function (cssClass) {
assert(selectedIndex === itemIndex ? isSelected(cssClass) : !isSelected(cssClass),
'the filter / route at index ' + selectedIndex + ' should have been selected');
}));
}
for (var i = 0; i < 3; i++) {
pushTest(i);
}
// execute all the tests
return Q.all(tests);
}); });
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment