2021-02-04 19:15:23 +01:00
|
|
|
const { Browser } = require('selenium-webdriver');
|
|
|
|
const Driver = require('./driver');
|
|
|
|
const ChromeDriver = require('./chrome');
|
|
|
|
const FirefoxDriver = require('./firefox');
|
2019-12-11 20:14:58 +01:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
async function buildWebDriver({ responsive, port, timeOut } = {}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const browser = process.env.SELENIUM_BROWSER;
|
2020-01-14 18:34:38 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
driver: seleniumDriver,
|
|
|
|
extensionId,
|
|
|
|
extensionUrl,
|
2022-07-18 10:22:23 +02:00
|
|
|
} = await buildBrowserWebDriver(browser, { responsive, port });
|
2022-07-18 16:43:30 +02:00
|
|
|
const driver = new Driver(seleniumDriver, browser, extensionUrl, timeOut);
|
2020-01-20 23:40:01 +01:00
|
|
|
|
2020-01-16 19:35:50 +01:00
|
|
|
return {
|
|
|
|
driver,
|
|
|
|
extensionId,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-16 19:35:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function buildBrowserWebDriver(browser, webDriverOptions) {
|
2019-12-11 20:14:58 +01:00
|
|
|
switch (browser) {
|
|
|
|
case Browser.CHROME: {
|
2021-02-04 19:15:23 +01:00
|
|
|
return await ChromeDriver.build(webDriverOptions);
|
2019-12-11 20:14:58 +01:00
|
|
|
}
|
|
|
|
case Browser.FIREFOX: {
|
2021-02-04 19:15:23 +01:00
|
|
|
return await FirefoxDriver.build(webDriverOptions);
|
2019-12-11 20:14:58 +01:00
|
|
|
}
|
|
|
|
default: {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error(`Unrecognized browser: ${browser}`);
|
2019-12-11 20:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
buildWebDriver,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|