authelia/test/helpers/context/WithDriver.ts

31 lines
745 B
TypeScript
Raw Normal View History

require("chromedriver");
import chrome from 'selenium-webdriver/chrome';
import SeleniumWebdriver from "selenium-webdriver";
2019-02-09 22:20:37 +00:00
export default function(forEach: boolean = false) {
let options = new chrome.Options();
if (process.env['HEADLESS'] == 'y') {
options = options.headless();
}
2019-02-09 22:20:37 +00:00
function beforeBlock(this: Mocha.IHookCallbackContext) {
const driver = new SeleniumWebdriver.Builder()
.forBrowser("chrome")
.setChromeOptions(options)
.build();
this.driver = driver;
2019-02-09 22:20:37 +00:00
}
function afterBlock(this: Mocha.IHookCallbackContext) {
return this.driver.quit();
}
2019-02-09 22:20:37 +00:00
if (forEach) {
beforeEach(beforeBlock);
afterEach(afterBlock);
} else {
before(beforeBlock);
after(afterBlock);
}
}