Commit 26ceac57 authored by Oskar Gustafsson's avatar Oskar Gustafsson Committed by Sam Saccone

Improve test suite robustness. (#1646)

..by waiting for DOM states instead of checking them only once.
parent aa9b051b
This diff is collapsed.
'use strict'; 'use strict';
var webdriver = require('selenium-webdriver');
var Page = require('./page'); var Page = require('./page');
module.exports = function PageLaxMode(browser) { module.exports = function PageLaxMode() {
Page.apply(this, [browser]);
Page.apply(this, arguments);
this.tryGetMainSectionElement = function () { this.getMainSectionCss = function () {
return this.tryFindByXpath('//section//section'); return 'section section';
}; };
this.tryGetFooterElement = function () { this.getFooterSectionCss = function () {
return this.tryFindByXpath('//section//footer'); return 'section footer';
}; };
this.getTodoListXpath = function () { this.getListCss = function (suffixCss) {
return '(//section/ul | //section/div/ul | //ul[@id="todo-list"])'; return [
'section > ul',
'section > div > ul',
'ul#todo-list',
].map(function (listCss) {
return listCss + (suffixCss || '');
}).join(', ');
}; };
this.getMarkAllCompletedCheckBox = function () { this.getToggleAllCss = function () {
var xpath = '(//section/input[@type="checkbox"] | //section/*/input[@type="checkbox"] | //input[@id="toggle-all"])'; return [
return browser.findElement(webdriver.By.xpath(xpath)); 'section > input[type="checkbox"]',
'section > * > input[type="checkbox"]',
'input#toggle-all',
].join(', ');
}; };
this.tryGetClearCompleteButton = function () { this.getClearCompletedButtonCss = function () {
var xpath = '(//footer/button | //footer/*/button | //button[@id="clear-completed"])'; return [
return browser.findElements(webdriver.By.xpath(xpath)); 'footer > button',
'footer > * > button',
'button#clear-completed',
].join(', ');
}; };
this.getItemsCountElement = function () { this.getItemCountCss = function () {
var xpath = '(//footer/span | //footer/*/span)'; return [
return browser.findElement(webdriver.By.xpath(xpath)); 'footer > span',
'footer > * > span',
].join(', ');
}; };
this.getFilterElements = function () { this.getFilterCss = function (index) {
return browser.findElements(webdriver.By.xpath('//footer//ul//a')); return 'footer ul li:nth-child(' + (index + 1) + ') a';
}; };
this.getNewInputCss = function () {
this.getItemInputField = function () { return [
// allow a more generic method for locating the text getItemInputField 'header > input',
var xpath = '(//header/input | //header/*/input | //input[@id="new-todo"])'; 'header > * > input',
return browser.findElement(webdriver.By.xpath(xpath)); 'input#new-todo',
].join(', ');
}; };
this.tryGetToggleForItemAtIndex = function (index) { this.getListItemToggleCss = function (index) {
// the specification dictates that the checkbox should have the 'toggle' CSS class. Some implementations deviate from return this.getListItemCss(index, ' input[type="checkbox"]');
// this, hence in lax mode we simply look for any checkboxes within the specified 'li'.
var xpath = this.xPathForItemAtIndex(index) + '//input[@type="checkbox"]';
return browser.findElements(webdriver.By.xpath(xpath));
}; };
this.getEditInputForItemAtIndex = function (index) { this.getListItemInputCss = function (index) {
// the specification dictates that the input element that allows the user to edit a todo item should have a CSS return [
// class of 'edit'. In lax mode, we also look for an input of type 'text'. this.getListItemCss(index, ' input.edit'),
var xpath = '(' + this.xPathForItemAtIndex(index) + '//input[@type="text"]' + '|' + this.getListItemCss(index, ' input[type="text"]'),
this.xPathForItemAtIndex(index) + '//input[contains(@class,"edit")]' + ')'; ].join(', ');
return browser.findElement(webdriver.By.xpath(xpath));
}; };
}; };
This diff is collapsed.
This diff is collapsed.
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