Commit c8051303 authored by Arthur Verschaeve's avatar Arthur Verschaeve

Merge pull request #1330 from samccone/sjs/test-id-work

test id => class work
parents 1dd17f9c 90619f55
'use strict'; 'use strict';
var webdriver = require('selenium-webdriver'); var webdriver = require('selenium-webdriver');
var idSelectors = false;
module.exports = function Page(browser) { module.exports = function Page(browser) {
...@@ -15,7 +16,35 @@ module.exports = function Page(browser) { ...@@ -15,7 +16,35 @@ module.exports = function Page(browser) {
}; };
this.getTodoListXpath = function () { this.getTodoListXpath = function () {
return '//ul[@id="todo-list"]'; return !idSelectors ? '//ul[@id="todo-list"]' : '//ul[@class="todo-list"]';
};
this.getMainSectionXpath = function () {
return !idSelectors ? '//section[@id="main"]' : '//section[contains(@class, "main")]';
};
this.getFooterSectionXpath = function () {
return !idSelectors ? '//footer[@id="footer"]' : '//footer[contains(@class, "footer")]';
};
this.getCompletedButtonXpath = function () {
return !idSelectors ? '//button[@id="clear-completed"]' : '//button[contains(@class, "clear-completed")]';
};
this.getNewInputXpath = function () {
return !idSelectors ? '//input[@id="new-todo"]' : '//input[contains(@class,"new-todo")]';
};
this.getToggleAllXpath = function () {
return !idSelectors ? '//input[@id="toggle-all"]' : '//input[contains(@class,"toggle-all")]';
};
this.getCountXpath = function () {
return !idSelectors ? '//span[@id="todo-count"]' : '//span[contains(@class, "todo-count")]';
};
this.getFilterElementsXpath = function () {
return !idSelectors ? '//ul[@id="filters"]//a' : '//ul[contains(@class, "filters")]';
}; };
this.xPathForItemAtIndex = function (index) { this.xPathForItemAtIndex = function (index) {
...@@ -37,15 +66,15 @@ module.exports = function Page(browser) { ...@@ -37,15 +66,15 @@ module.exports = function Page(browser) {
// elements which *might* be present in the DOM, hence the try/get name. // elements which *might* be present in the DOM, hence the try/get name.
this.tryGetMainSectionElement = function () { this.tryGetMainSectionElement = function () {
return this.tryFindByXpath('//section[@id="main"]'); return this.tryFindByXpath(this.getMainSectionXpath());
}; };
this.tryGetFooterElement = function () { this.tryGetFooterElement = function () {
return this.tryFindByXpath('//footer[@id="footer"]'); return this.tryFindByXpath(this.getFooterSectionXpath());
}; };
this.tryGetClearCompleteButton = function () { this.tryGetClearCompleteButton = function () {
return this.tryFindByXpath('//button[@id="clear-completed"]'); return this.tryFindByXpath(this.getCompletedButtonXpath());
}; };
this.tryGetToggleForItemAtIndex = function (index) { this.tryGetToggleForItemAtIndex = function (index) {
...@@ -60,9 +89,7 @@ module.exports = function Page(browser) { ...@@ -60,9 +89,7 @@ module.exports = function Page(browser) {
// ----------------- DOM element access methods // ----------------- DOM element access methods
this.getFocussedElementId = function () { this.getFocussedElementId = function () {
return browser.switchTo().activeElement().getAttribute('id').then(function (id) { return browser.switchTo().activeElement().getAttribute(!idSelectors ? 'id' : 'class');
return id;
});
}; };
this.getEditInputForItemAtIndex = function (index) { this.getEditInputForItemAtIndex = function (index) {
...@@ -71,11 +98,11 @@ module.exports = function Page(browser) { ...@@ -71,11 +98,11 @@ module.exports = function Page(browser) {
}; };
this.getItemInputField = function () { this.getItemInputField = function () {
return this.findByXpath('//input[@id="new-todo"]'); return this.findByXpath(this.getNewInputXpath());
}; };
this.getMarkAllCompletedCheckBox = function () { this.getMarkAllCompletedCheckBox = function () {
return this.findByXpath('//input[@id="toggle-all"]'); return this.findByXpath(this.getToggleAllXpath());
}; };
this.getItemElements = function () { this.getItemElements = function () {
...@@ -87,7 +114,7 @@ module.exports = function Page(browser) { ...@@ -87,7 +114,7 @@ module.exports = function Page(browser) {
}; };
this.getItemsCountElement = function () { this.getItemsCountElement = function () {
return this.findByXpath('//span[@id="todo-count"]'); return this.findByXpath(this.getCountXpath());
}; };
this.getItemLabelAtIndex = function (index) { this.getItemLabelAtIndex = function (index) {
...@@ -95,7 +122,7 @@ module.exports = function Page(browser) { ...@@ -95,7 +122,7 @@ module.exports = function Page(browser) {
}; };
this.getFilterElements = function () { this.getFilterElements = function () {
return this.tryFindByXpath('//ul[@id="filters"]//a'); return this.tryFindByXpath(this.getFilterElementsXpath());
}; };
this.getItemLabels = function () { this.getItemLabels = function () {
...@@ -110,8 +137,20 @@ module.exports = function Page(browser) { ...@@ -110,8 +137,20 @@ module.exports = function Page(browser) {
if (elms.length > 0) { if (elms.length > 0) {
return true; return true;
} else { } else {
throw new Error('Unable to find application root, did you start your local server?'); return browser.findElements(webdriver.By.css('.todoapp'));
} }
})
.then(function (elms) {
if (elms === true) {
return true;
}
if (elms.length) {
idSelectors = true;
return true;
}
throw new Error('Unable to find application root, did you start your local server?');
}); });
}; };
......
...@@ -140,8 +140,11 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -140,8 +140,11 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.describe('Mark all as completed', function () { test.describe('Mark all as completed', function () {
test.it('should allow me to mark all items as completed', function () { test.beforeEach(function () {
createStandardItems(); createStandardItems();
});
test.it('should allow me to mark all items as completed', function () {
page.clickMarkAllCompletedCheckBox(); page.clickMarkAllCompletedCheckBox();
testOps.assertItemAtIndexIsCompleted(0); testOps.assertItemAtIndexIsCompleted(0);
...@@ -150,7 +153,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -150,7 +153,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('should allow me to clear the completion state of all items', function () { test.it('should allow me to clear the completion state of all items', function () {
createStandardItems();
page.clickMarkAllCompletedCheckBox(); page.clickMarkAllCompletedCheckBox();
page.clickMarkAllCompletedCheckBox(); page.clickMarkAllCompletedCheckBox();
...@@ -160,7 +162,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -160,7 +162,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('complete all checkbox should update state when items are completed / cleared', function () { test.it('complete all checkbox should update state when items are completed / cleared', function () {
createStandardItems();
page.clickMarkAllCompletedCheckBox(); page.clickMarkAllCompletedCheckBox();
testOps.assertCompleteAllIsChecked(); testOps.assertCompleteAllIsChecked();
...@@ -210,10 +211,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -210,10 +211,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
testOps.assertItems([TODO_ITEM_ONE, 'buy some sausages', TODO_ITEM_THREE]); testOps.assertItems([TODO_ITEM_ONE, 'buy some sausages', TODO_ITEM_THREE]);
}); });
test.it('should show the remove button on hover', function () {
// assert(false);
});
}); });
test.describe('Editing', function () { test.describe('Editing', function () {
...@@ -285,14 +282,16 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -285,14 +282,16 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
test.describe('Clear completed button', function () { test.describe('Clear completed button', function () {
test.it('should display the correct text', function () { test.beforeEach(function () {
createStandardItems(); createStandardItems();
});
test.it('should display the correct text', function () {
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
testOps.assertClearCompleteButtonText('Clear completed'); testOps.assertClearCompleteButtonText('Clear completed');
}); });
test.it('should remove completed items when clicked', function () { test.it('should remove completed items when clicked', function () {
createStandardItems();
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
page.clickClearCompleteButton(); page.clickClearCompleteButton();
testOps.assertItemCount(2); testOps.assertItemCount(2);
...@@ -300,7 +299,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -300,7 +299,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('should be hidden when there are no items that are completed', function () { test.it('should be hidden when there are no items that are completed', function () {
createStandardItems();
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
testOps.assertClearCompleteButtonIsVisible(); testOps.assertClearCompleteButtonIsVisible();
page.clickClearCompleteButton(); page.clickClearCompleteButton();
...@@ -334,8 +332,10 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -334,8 +332,10 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.describe('Routing', function () { test.describe('Routing', function () {
test.it('should allow me to display active items', function () { test.beforeEach(function () {
createStandardItems(); createStandardItems();
});
test.it('should allow me to display active items', function () {
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
page.filterByActiveItems(); page.filterByActiveItems();
...@@ -362,7 +362,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -362,7 +362,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('should allow me to display completed items', function () { test.it('should allow me to display completed items', function () {
createStandardItems();
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
page.filterByCompletedItems(); page.filterByCompletedItems();
...@@ -370,7 +369,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -370,7 +369,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('should allow me to display all items', function () { test.it('should allow me to display all items', function () {
createStandardItems();
page.toggleItemAtIndex(1); page.toggleItemAtIndex(1);
// apply the other filters first, before returning to the 'all' state // apply the other filters first, before returning to the 'all' state
...@@ -382,8 +380,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -382,8 +380,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
}); });
test.it('should highlight the currently applied filter', function () { test.it('should highlight the currently applied filter', function () {
createStandardItems();
// initially 'all' should be selected // initially 'all' should be selected
testOps.assertFilterAtIndexIsSelected(0); testOps.assertFilterAtIndexIsSelected(0);
......
...@@ -22,9 +22,9 @@ function TestOperations(page) { ...@@ -22,9 +22,9 @@ function TestOperations(page) {
}); });
} }
this.assertFocussedElementId = function(expectedId) { this.assertFocussedElementId = function (expectedId) {
page.getFocussedElementId().then(function(id) { page.getFocussedElementId().then(function (id) {
assert.equal(id, expectedId, 'The focused element did not have the expected id ' + expectedId); assert.notEqual(-1, id.indexOf(expectedId), 'The focused element did not have the expected id ' + expectedId);
}); });
}; };
......
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