New project structure
Beta of extract.js for extracting english locale
This commit is contained in:
parent
e18d2b2f84
commit
2edbd67205
247 changed files with 6405 additions and 4237 deletions
77
server/test/e2e/lib/web.js
Normal file
77
server/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