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