Added waitUntilVisibleAfterRefresh and textsToWaitFor - both discussed with @witzig.
Page objects refactored to exploit textsToWaitFor if relevant. Login tests refactored for the newer API. Some additional tests in subscription. The rest at least included as "pending".
This commit is contained in:
parent
ccd37ac792
commit
bb2b3da9dd
14 changed files with 446 additions and 393 deletions
77
test/e2e/lib/web.js
Normal file
77
test/e2e/lib/web.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('./config');
|
||||
const By = require('selenium-webdriver').By;
|
||||
const url = require('url');
|
||||
const UrlPattern = require('url-pattern');
|
||||
const driver = require('./mocha-e2e').driver;
|
||||
const page = require('./page');
|
||||
|
||||
module.exports = (...extras) => page({
|
||||
|
||||
async navigate(pathOrParams) {
|
||||
let path;
|
||||
if (typeof pathOrParams === 'string') {
|
||||
path = pathOrParams;
|
||||
} else {
|
||||
const urlPattern = new UrlPattern(this.requestUrl || this.url);
|
||||
path = urlPattern.stringify(pathOrParams)
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(path);
|
||||
let absolutePath;
|
||||
if (parsedUrl.host) {
|
||||
absolutePath = path;
|
||||
} else {
|
||||
absolutePath = config.baseUrl + path;
|
||||
}
|
||||
|
||||
await driver.navigate().to(absolutePath);
|
||||
await this.waitUntilVisible();
|
||||
},
|
||||
|
||||
async ensureUrl(path) {
|
||||
const desiredUrl = path || this.url;
|
||||
|
||||
if (desiredUrl) {
|
||||
const currentUrl = url.parse(await driver.getCurrentUrl());
|
||||
const urlPattern = new UrlPattern(desiredUrl);
|
||||
const params = urlPattern.match(currentUrl.pathname);
|
||||
if (!params || config.baseUrl !== `${currentUrl.protocol}//${currentUrl.host}`) {
|
||||
throw new Error(`Unexpected URL. Expecting ${config.baseUrl}${this.url} got ${currentUrl.protocol}//${currentUrl.host}/${currentUrl.pathname}`);
|
||||
}
|
||||
|
||||
this.params = params;
|
||||
}
|
||||
},
|
||||
|
||||
async submit() {
|
||||
const submitButton = await this.getElement('submitButton');
|
||||
await submitButton.click();
|
||||
},
|
||||
|
||||
async waitForFlash() {
|
||||
await this.waitUntilVisible('div.alert:not(.js-warning)');
|
||||
},
|
||||
|
||||
async getFlash() {
|
||||
const elem = await driver.findElement(By.css('div.alert:not(.js-warning)'));
|
||||
return await elem.getText();
|
||||
},
|
||||
|
||||
async clearFlash() {
|
||||
await driver.executeScript(`
|
||||
var elements = document.getElementsByClassName('alert');
|
||||
while(elements.length > 0){
|
||||
elements[0].parentNode.removeChild(elements[0]);
|
||||
}
|
||||
`);
|
||||
},
|
||||
|
||||
async setValue(key, value) {
|
||||
const elem = await this.getElement(key);
|
||||
await elem.clear();
|
||||
await elem.sendKeys(value);
|
||||
}
|
||||
|
||||
}, ...extras);
|
Loading…
Add table
Add a link
Reference in a new issue