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) {
return !idSelectors ? '//span[@id="todo-count"]' : '//span[contains(@class, "todo-count")]';
};
this.getFilterElementsXpath = function () {
return !idSelectors ? '//ul[@id="filters"]//a' : '//ul[contains(@class, "filters")]//a';
this.getFiltersElementXpath = function () {
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) {
......@@ -121,10 +141,6 @@ module.exports = function Page(browser) {
return this.findByXpath(this.xPathForItemAtIndex(index) + '//label');
};
this.getFilterElements = function () {
return this.tryFindByXpath(this.getFilterElementsXpath());
};
this.getItemLabels = function () {
var xpath = this.getTodoListXpath() + '/li//label';
return this.tryFindByXpath(xpath);
......@@ -211,20 +227,14 @@ module.exports = function Page(browser) {
};
this.filterByActiveItems = function () {
return this.getFilterElements().then(function (filters) {
filters[1].click();
});
return this.findByXpath(this.getFilterActiveXpath()).click();
};
this.filterByCompletedItems = function () {
return this.getFilterElements().then(function (filters) {
filters[2].click();
});
return this.findByXpath(this.getFilterCompletedXpath()).click();
};
this.filterByAllItems = function () {
return this.getFilterElements().then(function (filters) {
filters[0].click();
});
return this.findByXpath(this.getFilterAllXpath()).click();
};
};
......@@ -173,30 +173,10 @@ function TestOperations(page) {
});
};
function isSelected(cssClass) {
return cssClass.indexOf('selected') !== -1;
}
this.assertFilterAtIndexIsSelected = function (selectedIndex) {
page.getFilterElements().then(function (filterElements) {
// create an array of promises, each one holding a test
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);
page.findByXpath(page.getSelectedFilterXPathByIndex(selectedIndex + 1))
.then(function (elm) {
assert.notEqual(undefined, elm, 'the filter / route at index ' + selectedIndex + ' should have been selected');
});
};
......
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