2019-01-30 15:47:03 +00:00
|
|
|
require("chromedriver");
|
|
|
|
import chrome from 'selenium-webdriver/chrome';
|
2019-02-12 22:23:43 +00:00
|
|
|
import SeleniumWebdriver, { WebDriver } from "selenium-webdriver";
|
2019-01-30 15:47:03 +00:00
|
|
|
|
2019-02-12 22:23:43 +00:00
|
|
|
export async function StartDriver() {
|
2019-02-04 22:23:59 +00:00
|
|
|
let options = new chrome.Options();
|
|
|
|
|
|
|
|
if (process.env['HEADLESS'] == 'y') {
|
|
|
|
options = options.headless();
|
|
|
|
}
|
2019-01-30 15:47:03 +00:00
|
|
|
|
2019-02-12 22:23:43 +00:00
|
|
|
const driver = new SeleniumWebdriver.Builder()
|
|
|
|
.forBrowser("chrome")
|
|
|
|
.setChromeOptions(options)
|
|
|
|
.build();
|
|
|
|
return driver;
|
|
|
|
}
|
2019-02-09 22:20:37 +00:00
|
|
|
|
2019-02-12 22:23:43 +00:00
|
|
|
export async function StopDriver(driver: WebDriver) {
|
|
|
|
return await driver.quit();
|
|
|
|
}
|
2019-01-30 15:47:03 +00:00
|
|
|
|
2019-02-12 22:23:43 +00:00
|
|
|
export default function(forEach: boolean = false) {
|
2019-02-09 22:20:37 +00:00
|
|
|
if (forEach) {
|
2019-02-12 22:23:43 +00:00
|
|
|
beforeEach(async function() {
|
|
|
|
this.driver = await StartDriver();
|
|
|
|
});
|
|
|
|
afterEach(async function() {
|
|
|
|
await StopDriver(this.driver);
|
|
|
|
});
|
2019-02-09 22:20:37 +00:00
|
|
|
} else {
|
2019-02-12 22:23:43 +00:00
|
|
|
before(async function() {
|
|
|
|
this.driver = await StartDriver();
|
|
|
|
});
|
|
|
|
after(async function() {
|
|
|
|
await StopDriver(this.driver)
|
|
|
|
});
|
2019-02-09 22:20:37 +00:00
|
|
|
}
|
2019-01-30 15:47:03 +00:00
|
|
|
}
|