authelia/test/helpers/context/WithDriver.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

require("chromedriver");
import chrome from 'selenium-webdriver/chrome';
import SeleniumWebdriver, { WebDriver, ProxyConfig } from "selenium-webdriver";
export async function StartDriver(proxy?: ProxyConfig) {
let options = new chrome.Options();
if (process.env['HEADLESS'] == 'y') {
options = options.headless();
}
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-09 22:20:37 +00:00
export async function StopDriver(driver: WebDriver) {
return await driver.quit();
}
export default function(forEach: boolean = false) {
2019-02-09 22:20:37 +00:00
if (forEach) {
beforeEach(async function() {
this.driver = await StartDriver();
});
afterEach(async function() {
await StopDriver(this.driver);
});
2019-02-09 22:20:37 +00:00
} else {
before(async function() {
this.driver = await StartDriver();
});
after(async function() {
await StopDriver(this.driver)
});
2019-02-09 22:20:37 +00:00
}
}