2019-01-30 15:47:03 +00:00
|
|
|
require("chromedriver");
|
|
|
|
import chrome from 'selenium-webdriver/chrome';
|
2019-03-27 22:09:01 +00:00
|
|
|
import SeleniumWebdriver, { WebDriver, ProxyConfig } from "selenium-webdriver";
|
2019-01-30 15:47:03 +00:00
|
|
|
|
2019-03-27 22:09:01 +00:00
|
|
|
export async function StartDriver(proxy?: ProxyConfig) {
|
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-03-27 22:09:01 +00:00
|
|
|
let driverBuilder = new SeleniumWebdriver.Builder()
|
|
|
|
.forBrowser("chrome");
|
|
|
|
|
|
|
|
if (proxy) {
|
|
|
|
options = options.addArguments(`--proxy-server=${proxy.httpProxy}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
driverBuilder = driverBuilder.setChromeOptions(options);
|
|
|
|
return await driverBuilder.build();
|
2019-02-12 22:23:43 +00:00
|
|
|
}
|
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
|
|
|
}
|