@progress/kendo-e2e
Version:
Kendo UI end-to-end test utilities.
145 lines • 6.53 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DriverManager = void 0;
const selenium_webdriver_1 = require("selenium-webdriver");
const chrome_1 = require("selenium-webdriver/chrome");
const edge_1 = require("selenium-webdriver/edge");
const firefox_1 = require("selenium-webdriver/firefox");
const safari_1 = require("selenium-webdriver/safari");
const browserstack_settings_1 = require("../settings/browserstack-settings");
const settings_1 = require("../settings/settings");
class DriverManager {
constructor() {
this.DEFAULT_CHROMIUM_OPTIONS = [
`--window-size=${settings_1.Settings.browserWidth},${settings_1.Settings.browserHeight}`,
'--force-device-scale-factor=1',
'--log-level=1',
'--disable-extensions',
'--disable-notifications',
'--disable-search-engine-choice-screen',
'--ignore-certificate-errors'
];
}
getDriver(options = {}) {
switch (settings_1.Settings.browserName) {
case selenium_webdriver_1.Browser.CHROME: {
// Pass mobileOptions as second parameter, not as the options instance.
return this.getChromeDriver(options);
}
case selenium_webdriver_1.Browser.EDGE: {
return this.getEdgeDriver();
}
case selenium_webdriver_1.Browser.FIREFOX: {
return this.getFirefoxDriver();
}
case selenium_webdriver_1.Browser.SAFARI: {
return this.getSafariDriver();
}
default: {
return this.getBrowserStackDriver();
}
}
}
getChromeOptions(args = this.DEFAULT_CHROMIUM_OPTIONS, options = {}) {
const chromeOptions = new chrome_1.Options();
args.forEach(argument => {
chromeOptions.addArguments(argument);
});
if (settings_1.Settings.headless) {
chromeOptions.addArguments('--headless=new');
}
// We must disable the Chrome sandbox when running Chrome inside Docker.
// Chrome's sandbox needs more permissions than Docker allows by default.
// See:
// - https://github.com/GoogleChrome/puppeteer/issues/560
// - https://github.com/microsoft/playwright/issues/1977#issuecomment-619397496
if (process.env["CI_CONTAINER"]) {
chromeOptions.addArguments('--no-sandbox');
chromeOptions.addArguments('--disable-setuid-sandbox');
}
if (options.mobileEmulation) {
chromeOptions.setMobileEmulation(options.mobileEmulation);
}
if (options.enableBidi) {
chromeOptions.enableBidi();
}
return chromeOptions;
}
getChromeDriver(options) {
let chromeOptions;
if (options instanceof chrome_1.Options) {
chromeOptions = options;
}
else {
chromeOptions = this.getChromeOptions(this.DEFAULT_CHROMIUM_OPTIONS, options);
}
return new selenium_webdriver_1.Builder().forBrowser(selenium_webdriver_1.Browser.CHROME).setChromeOptions(chromeOptions).build();
}
getEdgeOptions(args = this.DEFAULT_CHROMIUM_OPTIONS) {
const options = new edge_1.Options();
args.forEach(argument => {
options.addArguments(argument);
});
if (settings_1.Settings.headless) {
options.addArguments('--headless');
}
return options;
}
getEdgeDriver(options = this.getEdgeOptions()) {
return new selenium_webdriver_1.Builder().forBrowser(selenium_webdriver_1.Browser.EDGE).setEdgeOptions(options).build();
}
getFirefoxOptions() {
const options = new firefox_1.Options();
options.addArguments(`--width=${settings_1.Settings.browserWidth}`);
options.addArguments(`--height=${settings_1.Settings.browserHeight}`);
options.setLoggingPrefs(selenium_webdriver_1.logging.Level.SEVERE);
if (settings_1.Settings.headless) {
options.addArguments('--headless');
}
return options;
}
getFirefoxDriver(options = this.getFirefoxOptions()) {
const prefs = new selenium_webdriver_1.logging.Preferences();
prefs.setLevel(selenium_webdriver_1.logging.Type.BROWSER, selenium_webdriver_1.logging.Level.ALL);
const service = new firefox_1.ServiceBuilder().setStdio("inherit");
return new selenium_webdriver_1.Builder()
.forBrowser(selenium_webdriver_1.Browser.FIREFOX)
.setLoggingPrefs(prefs)
.setFirefoxOptions(options)
.setFirefoxService(service)
.build();
}
getSafariOptions() {
const options = new safari_1.Options();
return options;
}
getSafariDriver(options = this.getSafariOptions()) {
const driver = new selenium_webdriver_1.Builder().forBrowser(selenium_webdriver_1.Browser.SAFARI).setSafariOptions(options).build();
const size = { width: settings_1.Settings.browserWidth, height: settings_1.Settings.browserHeight, x: 0, y: 0 };
driver.manage().window().setRect(size);
return driver;
}
getBrowserStackDriver() {
if (browserstack_settings_1.BSSettings.accessKey === undefined || browserstack_settings_1.BSSettings.userName === undefined) {
throw Error("Please set BS_USER_NAME and BS_ACCESS_KEY variables.");
}
const url = "http://hub-cloud.browserstack.com/wd/hub";
const capabilities = {
'bstack:options': {
"osVersion": browserstack_settings_1.BSSettings.osVersion,
"deviceName": browserstack_settings_1.BSSettings.deviceName,
"realMobile": browserstack_settings_1.BSSettings.realMobile,
"local": browserstack_settings_1.BSSettings.local,
"userName": browserstack_settings_1.BSSettings.userName,
"accessKey": browserstack_settings_1.BSSettings.accessKey
},
"browserName": browserstack_settings_1.BSSettings.browserName,
"name": browserstack_settings_1.BSSettings.buildName,
"build": browserstack_settings_1.BSSettings.buildNumber,
"nativeWebTap": "true"
};
return new selenium_webdriver_1.Builder().usingServer(url).withCapabilities(capabilities).build();
}
}
exports.DriverManager = DriverManager;
//# sourceMappingURL=driver-manager.js.map
;