2017-05-09 23:40:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('../helpers/config');
|
|
|
|
const webdriver = require('selenium-webdriver');
|
|
|
|
const By = webdriver.By;
|
|
|
|
const until = webdriver.until;
|
|
|
|
|
2017-05-10 14:18:35 +00:00
|
|
|
module.exports = driver => ({
|
|
|
|
driver,
|
|
|
|
elements: {},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
element(key) {
|
2017-05-10 14:18:35 +00:00
|
|
|
return this.driver.findElement(By.css(this.elements[key] || key));
|
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
2017-05-16 00:47:35 +00:00
|
|
|
navigate(path) {
|
|
|
|
this.driver.navigate().to(config.baseUrl + (path || this.url));
|
2017-05-09 23:40:02 +00:00
|
|
|
return this.waitUntilVisible();
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
waitUntilVisible() {
|
2017-05-10 14:18:35 +00:00
|
|
|
let selector = this.elements[this.elementToWaitFor];
|
|
|
|
if (!selector && this.url) {
|
|
|
|
selector = 'body.page--' + (this.url.substring(1).replace(/\//g, '--') || 'home');
|
2017-05-09 23:40:02 +00:00
|
|
|
}
|
|
|
|
return selector ? this.driver.wait(until.elementLocated(By.css(selector))) : this.driver.sleep(1000);
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
submit() {
|
|
|
|
return this.element('submitButton').click();
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
click(key) {
|
|
|
|
return this.element(key).click();
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
getText(key) {
|
|
|
|
return this.element(key).getText();
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
getValue(key) {
|
|
|
|
return this.element(key).getAttribute('value');
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
setValue(key, value) {
|
|
|
|
return this.element(key).sendKeys(value);
|
2017-05-10 14:18:35 +00:00
|
|
|
},
|
2017-05-09 23:40:02 +00:00
|
|
|
|
|
|
|
containsText(str) {
|
|
|
|
// let text = await driver.findElement({ css: 'body' }).getText();
|
|
|
|
return this.driver.executeScript(`
|
|
|
|
return (document.documentElement.textContent || document.documentElement.innerText).indexOf('${str}') > -1;
|
|
|
|
`);
|
|
|
|
}
|
2017-05-10 14:18:35 +00:00
|
|
|
});
|