Commit 8ccca748 authored by Sam Saccone's avatar Sam Saccone

stale element fix for selected filter.

parent b594e306
...@@ -47,16 +47,24 @@ module.exports = function Page(browser) { ...@@ -47,16 +47,24 @@ module.exports = function Page(browser) {
return !idSelectors ? '//ul[@id="filters"]' : '//ul[contains(@class, "filters")]'; 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 () { this.getFilterAllXpath = function () {
return this.getFiltersElementXpath() + '/li[1]/a'; return this.getFilterXpathByIndex(1);
}; };
this.getFilterActiveXpath = function () { this.getFilterActiveXpath = function () {
return this.getFiltersElementXpath() + '/li[2]/a'; return this.getFilterXpathByIndex(2);
}; };
this.getFilterCompletedXpath = function () { this.getFilterCompletedXpath = function () {
return this.getFiltersElementXpath() + '/li[3]/a'; return this.getFilterXpathByIndex(3);
}; };
this.xPathForItemAtIndex = function (index) { this.xPathForItemAtIndex = function (index) {
...@@ -133,10 +141,6 @@ module.exports = function Page(browser) { ...@@ -133,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);
......
...@@ -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