Permalink
Browse files

tests: Dynamic app selectors fo v1 and v2 apps

  • Loading branch information...
samccone committed Jun 5, 2015
1 parent bacc2c8 commit 90619f55c70ee70fb40caa8277cc1b4a1ccaeefa
Showing with 39 additions and 14 deletions.
  1. +38 −12 tests/page.js
  2. +0 −1 tests/test.js
  3. +1 −1 tests/testOperations.js
View
@@ -1,8 +1,8 @@
'use strict';
var webdriver = require('selenium-webdriver');
-
var idSelectors = false;
+
module.exports = function Page(browser) {
// ----------------- utility methods
@@ -16,7 +16,35 @@ module.exports = function Page(browser) {
};
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) {
@@ -38,15 +66,15 @@ module.exports = function Page(browser) {
// elements which *might* be present in the DOM, hence the try/get name.
this.tryGetMainSectionElement = function () {
- return this.tryFindByXpath('//section[@id="main"]');
+ return this.tryFindByXpath(this.getMainSectionXpath());
};
this.tryGetFooterElement = function () {
- return this.tryFindByXpath('//footer[@id="footer"]');
+ return this.tryFindByXpath(this.getFooterSectionXpath());
};
this.tryGetClearCompleteButton = function () {
- return this.tryFindByXpath('//button[@id="clear-completed"]');
+ return this.tryFindByXpath(this.getCompletedButtonXpath());
};
this.tryGetToggleForItemAtIndex = function (index) {
@@ -61,9 +89,7 @@ module.exports = function Page(browser) {
// ----------------- DOM element access methods
this.getFocussedElementId = function () {
- return browser.switchTo().activeElement().getAttribute('id').then(function (id) {
- return id;
- });
+ return browser.switchTo().activeElement().getAttribute(!idSelectors ? 'id' : 'class');
};
this.getEditInputForItemAtIndex = function (index) {
@@ -72,11 +98,11 @@ module.exports = function Page(browser) {
};
this.getItemInputField = function () {
- return this.findByXpath('//input[@id="new-todo"]');
+ return this.findByXpath(this.getNewInputXpath());
};
this.getMarkAllCompletedCheckBox = function () {
- return this.findByXpath('//input[@id="toggle-all"]');
+ return this.findByXpath(this.getToggleAllXpath());
};
this.getItemElements = function () {
@@ -88,15 +114,15 @@ module.exports = function Page(browser) {
};
this.getItemsCountElement = function () {
- return this.findByXpath('//span[@id="todo-count"]');
+ return this.findByXpath(this.getCountXpath());
};
this.getItemLabelAtIndex = function (index) {
return this.findByXpath(this.xPathForItemAtIndex(index) + '//label');
};
this.getFilterElements = function () {
- return this.tryFindByXpath('//ul[@id="filters"]//a');
+ return this.tryFindByXpath(this.getFilterElementsXpath());
};
this.getItemLabels = function () {
View
@@ -211,7 +211,6 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
testOps.assertItems([TODO_ITEM_ONE, 'buy some sausages', TODO_ITEM_THREE]);
});
-
});
test.describe('Editing', function () {
View
@@ -24,7 +24,7 @@ function TestOperations(page) {
this.assertFocussedElementId = function (expectedId) {
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);
});
};

0 comments on commit 90619f5

Please sign in to comment.