2019-01-30 22:47:03 +07:00
|
|
|
require("chromedriver");
|
|
|
|
import chrome from 'selenium-webdriver/chrome';
|
|
|
|
import SeleniumWebdriver from "selenium-webdriver";
|
|
|
|
|
2019-02-10 05:20:37 +07:00
|
|
|
export default function(forEach: boolean = false) {
|
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-10 05:20:37 +07:00
|
|
|
function beforeBlock(this: Mocha.IHookCallbackContext) {
|
2019-01-30 22:47:03 +07:00
|
|
|
const driver = new SeleniumWebdriver.Builder()
|
|
|
|
.forBrowser("chrome")
|
2019-02-05 05:23:59 +07:00
|
|
|
.setChromeOptions(options)
|
2019-01-30 22:47:03 +07:00
|
|
|
.build();
|
|
|
|
this.driver = driver;
|
2019-02-10 05:20:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
function afterBlock(this: Mocha.IHookCallbackContext) {
|
|
|
|
return this.driver.quit();
|
|
|
|
}
|
2019-01-30 22:47:03 +07:00
|
|
|
|
2019-02-10 05:20:37 +07:00
|
|
|
if (forEach) {
|
|
|
|
beforeEach(beforeBlock);
|
|
|
|
afterEach(afterBlock);
|
|
|
|
} else {
|
|
|
|
before(beforeBlock);
|
|
|
|
after(afterBlock);
|
|
|
|
}
|
2019-01-30 22:47:03 +07:00
|
|
|
}
|