2018-07-05 14:16:36 -04:00
|
|
|
const webdriver = require('selenium-webdriver');
|
2017-08-11 16:13:52 -04:00
|
|
|
|
2018-05-31 11:52:57 -04:00
|
|
|
const headless = process.env.SMOKE_HEADLESS || false;
|
2018-06-25 15:17:15 -04:00
|
|
|
const remote = process.env.SMOKE_REMOTE || false;
|
|
|
|
const {SAUCE_USERNAME, SAUCE_ACCESS_KEY} = process.env;
|
2018-05-31 11:52:57 -04:00
|
|
|
|
|
|
|
const getDriver = function () {
|
|
|
|
const chromeCapabilities = webdriver.Capabilities.chrome();
|
|
|
|
let args = [];
|
|
|
|
if (headless) {
|
|
|
|
args.push('--headless');
|
|
|
|
args.push('window-size=1024,1680');
|
|
|
|
args.push('--no-sandbox');
|
|
|
|
}
|
|
|
|
chromeCapabilities.set('chromeOptions', {args});
|
|
|
|
const newDriver = new webdriver.Builder()
|
|
|
|
.forBrowser('chrome')
|
|
|
|
.withCapabilities(chromeCapabilities)
|
|
|
|
.build();
|
|
|
|
return newDriver;
|
|
|
|
};
|
|
|
|
|
2018-06-25 15:17:15 -04:00
|
|
|
const getSauceDriver = function (username, accessKey, configs) {
|
|
|
|
let driver = new webdriver.Builder()
|
|
|
|
.withCapabilities({
|
|
|
|
browserName: configs.browserName,
|
|
|
|
platform: configs.platform,
|
|
|
|
version: configs.version,
|
|
|
|
username: username,
|
|
|
|
accessKey: accessKey,
|
|
|
|
name: 'smoke test scratch-www'
|
|
|
|
})
|
|
|
|
.usingServer(`http://${username}:${accessKey
|
|
|
|
}@ondemand.saucelabs.com:80/wd/hub`)
|
|
|
|
.build();
|
|
|
|
return driver;
|
|
|
|
};
|
|
|
|
// Driver configs can be generated with the Sauce Platform Configurator
|
|
|
|
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator
|
|
|
|
const driverConfig = {
|
|
|
|
browserName: 'chrome',
|
|
|
|
platform: 'macOS 10.13',
|
|
|
|
version: '67.0'
|
|
|
|
};
|
2018-07-05 14:16:36 -04:00
|
|
|
let driver;
|
2018-06-25 15:17:15 -04:00
|
|
|
if (remote === 'true'){
|
|
|
|
driver = getSauceDriver(SAUCE_USERNAME, SAUCE_ACCESS_KEY, driverConfig);
|
|
|
|
} else {
|
|
|
|
driver = getDriver();
|
|
|
|
}
|
2017-08-11 16:13:52 -04:00
|
|
|
|
|
|
|
const {By, until} = webdriver;
|
|
|
|
|
|
|
|
const findByXpath = (xpath) => {
|
|
|
|
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
|
|
|
};
|
|
|
|
|
|
|
|
const clickXpath = (xpath) => {
|
|
|
|
return findByXpath(xpath).then(el => el.click());
|
|
|
|
};
|
|
|
|
|
|
|
|
const clickText = (text) => {
|
|
|
|
return clickXpath(`//*[contains(text(), '${text}')]`);
|
|
|
|
};
|
|
|
|
|
2017-10-23 21:17:55 -04:00
|
|
|
const findText = (text) => {
|
|
|
|
return driver.wait(until.elementLocated(By.xpath(`//*[contains(text(), '${text}')]`), 5 * 1000));
|
|
|
|
};
|
|
|
|
|
2017-08-11 16:13:52 -04:00
|
|
|
const clickButton = (text) => {
|
|
|
|
return clickXpath(`//button[contains(text(), '${text}')]`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const findByCss = (css) => {
|
|
|
|
return driver.wait(until.elementLocated(By.css(css), 1000 * 5));
|
|
|
|
};
|
|
|
|
|
2018-05-17 11:33:21 -04:00
|
|
|
const clickCss = (css) => {
|
|
|
|
return findByCss(css).then(el => el.click());
|
|
|
|
};
|
|
|
|
|
2017-08-11 16:13:52 -04:00
|
|
|
const getLogs = (whitelist) => {
|
|
|
|
return driver.manage()
|
|
|
|
.logs()
|
|
|
|
.get('browser')
|
|
|
|
.then((entries) => {
|
|
|
|
return entries.filter((entry) => {
|
|
|
|
const message = entry.message;
|
|
|
|
for (let i = 0; i < whitelist.length; i++) {
|
|
|
|
if (message.indexOf(whitelist[i]) !== -1) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
// console.warn('Ignoring whitelisted error: ' + whitelist[i]);
|
|
|
|
return false;
|
|
|
|
} else if (entry.level !== 'SEVERE') {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
// console.warn('Ignoring non-SEVERE entry: ' + message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-30 11:53:12 -05:00
|
|
|
return true;
|
2017-08-11 16:13:52 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
webdriver,
|
|
|
|
By,
|
|
|
|
until,
|
|
|
|
driver,
|
|
|
|
clickXpath,
|
|
|
|
findByXpath,
|
|
|
|
clickText,
|
2017-10-23 21:17:55 -04:00
|
|
|
findText,
|
2017-08-11 16:13:52 -04:00
|
|
|
clickButton,
|
|
|
|
findByCss,
|
2018-05-17 11:33:21 -04:00
|
|
|
clickCss,
|
2018-05-31 11:52:57 -04:00
|
|
|
getLogs,
|
2018-06-25 15:17:15 -04:00
|
|
|
getDriver,
|
|
|
|
getSauceDriver
|
2017-08-11 16:13:52 -04:00
|
|
|
};
|