UNPKG

nodium

Version:

Pure nodejs selenium webdriver functional helpers

69 lines (52 loc) 2.14 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFirefoxOptions = getFirefoxOptions; exports.default = getLocalDriver; var _chrome = require('selenium-webdriver/chrome'); var _firefox = require('selenium-webdriver/firefox'); function getChromeService(binaryPath) { return new _chrome.ServiceBuilder(binaryPath); } function getChromeOptions() { return new _chrome.Options().addArguments(['--no-sandbox', 'start-maximized']); } function getChromeDriver(binaryPath) { return _chrome.Driver.createSession(getChromeOptions(), getChromeService(binaryPath).build()); } function getChromeDriverWithVerboseLogging(binaryPath, logPath) { const service = getChromeService(binaryPath).enableVerboseLogging().loggingTo(logPath || __dirname + '/../chromedriver.log').build(); return _chrome.Driver.createSession(getChromeOptions(), service); } function getFirefoxService(binaryPath) { return new _firefox.ServiceBuilder(binaryPath); } function getFirefoxOptions() { const profile = new _firefox.Profile(); profile.setPreference('devtools.jsonview.enabled', false); return new _firefox.Options().setProfile(profile); } function getFirefoxDriver(binaryPath) { return _firefox.Driver.createSession(getFirefoxOptions(), getFirefoxService(binaryPath).build()); } function getFirefoxDriverWithVerboseLogging(binaryPath, logPath) { const service = getFirefoxService(binaryPath).enableVerboseLogging().build(); return _firefox.Driver.createSession(getFirefoxOptions(), service); } function getLocalDriver(browser, { binaryPath, verbose, logPath }) { switch (browser) { case 'chrome': if (verbose) { return getChromeDriverWithVerboseLogging(binaryPath, logPath); } return getChromeDriver(binaryPath); case 'firefox': if (verbose) { return getFirefoxDriverWithVerboseLogging(binaryPath, logPath); } return getFirefoxDriver(binaryPath); default: throw new Error(`No local driver found for "${browser}"`); } }