Skip to content

Commit

Permalink
v0.2.0: upgrade selenium-webdriver to v3.0.1, use babel-preset-env an…
Browse files Browse the repository at this point in the history
…d require nodejs >= 6.9
  • Loading branch information
jeromemacias committed Dec 19, 2016
1 parent bb44e31 commit 9ddeeae
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 35 deletions.
18 changes: 18 additions & 0 deletions .babelrc
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"
]
}
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ install:
@echo "Installing Node dependencies"
@npm install

build-dev:
./node_modules/.bin/babel --watch -d lib/ src/

build:
./node_modules/.bin/babel --presets es2015,stage-2 -d lib/ src/
./node_modules/.bin/babel -d lib/ src/
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodium",
"version": "0.1.5",
"version": "0.2.0",
"description": "Pure nodejs selenium webdriver functional helpers",
"homepage": "https://github.com/jeromemacias/nodium",
"repository": {
Expand All @@ -21,26 +21,26 @@
"url": "https://github.com/jeromemacias/nodium/issues"
},
"engines": {
"node": "~4.0"
"node": "~6.9"
},
"engine-strict": true,
"main": "lib/driver/index.js",
"dependencies": {
"selenium-webdriver": "~2.53.2"
"selenium-webdriver": "~3.0.1"
},
"devDependencies": {
"babel-cli": "~6.9.0",
"babel-eslint": "~6.0.4",
"babel-preset-es2015": "~6.9.0",
"babel-preset-stage-2": "~6.5.0",
"eslint": "~2.11.1"
"babel-cli": "~6.18.0",
"babel-eslint": "~7.1.1",
"babel-preset-env": "~1.1.4",
"babel-plugin-transform-object-rest-spread": "~6.16.0",
"eslint": "~3.12.2"
},
"peerDependencies": {
"chai": "~3.5",
"chai-as-promised": "~5.3",
"chai-as-promised": "^5.*",
"pm2": "*",
"request": "2.*",
"json-server": "0.8.*",
"json-server": "0.*",
"body-parser": "1.*"
}
}
16 changes: 8 additions & 8 deletions src/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ if (process.env.BROWSERSTACK) {
} else {
switch (browser.name.toLowerCase()) {
case 'chrome':
browser.version = '49';
browser.version = '54';
break;
case 'firefox':
browser.version = '45';
browser.version = '49';
break;
default:
throw new Error(`Cannot set default version for browser ${browser.name}`);
Expand Down Expand Up @@ -57,13 +57,13 @@ if (process.env.BROWSERSTACK) {
if (process.env.VERBOSE_MODE) {
options.verbose = true;
}
if ('firefox' !== browser.toLowerCase()) {
const binaryPath = process.env.SELENIUM_BROWSER_BINARY_PATH;
if (!binaryPath) {
throw new Error(`You must provide a browser binary path using "SELENIUM_BROWSER_BINARY_PATH" env var.`);
}
options.binaryPath = binaryPath;

const binaryPath = process.env.SELENIUM_BROWSER_BINARY_PATH;
if (!binaryPath) {
throw new Error(`You must provide a browser binary path using "SELENIUM_BROWSER_BINARY_PATH" env var.`);
}
options.binaryPath = binaryPath;

driver = getLocalDriver(browser.toLowerCase(), options);
console.log(`Use ${browser.toLowerCase()} browser`);
}
Expand Down
64 changes: 48 additions & 16 deletions src/driver/local.js
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}"`);
}
}

0 comments on commit 9ddeeae

Please sign in to comment.