-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.2.0: upgrade selenium-webdriver to v3.0.1, use babel-preset-env an…
…d require nodejs >= 6.9
- Loading branch information
1 parent
bb44e31
commit 9ddeeae
Showing
5 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": { | ||
"node": "6.9" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
], | ||
"ignore": [ | ||
"*.spec.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,74 @@ | ||
import chrome from 'selenium-webdriver/chrome'; | ||
import firefox from 'selenium-webdriver/firefox'; | ||
import { | ||
ServiceBuilder as ChromeServiceBuilder, | ||
Driver as ChromeDriver, | ||
Options as ChromeOptions, | ||
} from 'selenium-webdriver/chrome'; | ||
import { | ||
ServiceBuilder as FirefoxServiceBuilder, | ||
Driver as FirefoxDriver, | ||
Options as FirefoxOptions, | ||
} from 'selenium-webdriver/firefox'; | ||
|
||
function getChromeService(binaryPath) { | ||
const chromeBinary = binaryPath || __dirname + '/../node_modules/webdriver-manager/selenium/chromedriver'; | ||
|
||
return (new chrome.ServiceBuilder(chromeBinary)).build(); | ||
return new ChromeServiceBuilder(chromeBinary); | ||
} | ||
|
||
function getChromeOptions() { | ||
return new chrome.Options().addArguments(['--no-sandbox']); | ||
return new ChromeOptions().addArguments(['--no-sandbox']); | ||
} | ||
|
||
function getChromeDriver(binaryPath) { | ||
return new chrome.Driver(getChromeOptions(), getChromeService(binaryPath)); | ||
return ChromeDriver.createSession(getChromeOptions(), getChromeService(binaryPath).build()); | ||
} | ||
|
||
function getChromeDriverWithVerboseLogging(filePath) { | ||
const service = getChromeService() | ||
function getChromeDriverWithVerboseLogging(binaryPath, logPath) { | ||
const service = getChromeService(binaryPath) | ||
.enableVerboseLogging() | ||
.loggingTo(filePath || __dirname + '/../chromedriver.log') | ||
.loggingTo(logPath || __dirname + '/../chromedriver.log') | ||
.build(); | ||
|
||
return new chrome.Driver(getChromeOptions(), service); | ||
return ChromeDriver.createSession(getChromeOptions(), service); | ||
} | ||
|
||
function getFirefoxDriver() { | ||
return new firefox.Driver(); | ||
function getFirefoxService(binaryPath) { | ||
const firefoxBinary = binaryPath || __dirname + '/../node_modules/webdriver-manager/selenium/geckodriver'; | ||
|
||
return new FirefoxServiceBuilder(firefoxBinary); | ||
} | ||
|
||
function getFirefoxOptions() { | ||
return new FirefoxOptions(); | ||
} | ||
|
||
export default function getLocalDriver(browser, options = {}) { | ||
function getFirefoxDriver(binaryPath) { | ||
return FirefoxDriver.createSession(getFirefoxOptions(), getFirefoxService(binaryPath).build()); | ||
} | ||
|
||
function getFirefoxDriverWithVerboseLogging(binaryPath, logPath) { | ||
const service = getFirefoxService(binaryPath) | ||
.enableVerboseLogging() | ||
.build(); | ||
|
||
return FirefoxDriver.createSession(getFirefoxOptions(), service); | ||
} | ||
|
||
export default function getLocalDriver(browser, { binaryPath, verbose, logPath }) { | ||
let driver; | ||
switch (browser) { | ||
case 'chrome': | ||
if (options.verbose) { | ||
return getChromeDriverWithVerboseLogging(options.logPath) | ||
if (verbose) { | ||
return getChromeDriverWithVerboseLogging(binaryPath, logPath); | ||
} | ||
return getChromeDriver(options.binaryPath); | ||
|
||
return getChromeDriver(binaryPath); | ||
case "firefox": | ||
return getFirefoxDriver(); | ||
if (verbose) { | ||
return getFirefoxDriverWithVerboseLogging(binaryPath, logPath); | ||
} | ||
|
||
return getFirefoxDriver(binaryPath); | ||
default: throw new Error(`No local driver found for "${browser}"`); | ||
} | ||
} |