Skip to content

Commit

Permalink
deps(webdriver-manager): use replacement (angular#5088)
Browse files Browse the repository at this point in the history
- Current workaround to use webdriver-manager-replacement until we
publish a beta release of webdriver-manager

closes angular#5087
  • Loading branch information
cnishina committed Dec 19, 2018
1 parent 053f0dc commit 424060a
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 419 deletions.
2 changes: 1 addition & 1 deletion bin/webdriver-manager
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('webdriver-manager');
require('webdriver-manager-replacement');
5 changes: 2 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ jobs:
name: Selenium Start
background: true
command: |
./node_modules/webdriver-manager/bin/webdriver-manager update
./node_modules/.bin/webdriver-manager-replacement update --gecko false
./node_modules/.bin/webdriver-manager-replacement start --gecko false
./node_modules/.bin/webdriver-manager update
./node_modules/.bin/webdriver-manager start
- run:
name: TestApp Start
Expand Down
40 changes: 11 additions & 29 deletions lib/driverProviders/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
* it down, and setting up the driver correctly.
*/
import * as fs from 'fs';
import * as path from 'path';
import {Capabilities, WebDriver} from 'selenium-webdriver';
import {ServiceBuilder as ChromeServiceBuilder} from 'selenium-webdriver/chrome';
import {Driver as DriverForChrome, ServiceBuilder as ChromeServiceBuilder} from 'selenium-webdriver/chrome';
import {Driver as DriverForFirefox, ServiceBuilder as FirefoxServiceBuilder} from 'selenium-webdriver/firefox';
import {ChromeDriver, GeckoDriver} from 'webdriver-manager-replacement';

import {Config} from '../config';
import {BrowserError} from '../exitCodes';
import {Logger} from '../logger';

import {DriverProvider} from './driverProvider';

const SeleniumConfig = require('webdriver-manager/built/lib/config').Config;

let logger = new Logger('direct');
export class Direct extends DriverProvider {
constructor(config: Config) {
Expand Down Expand Up @@ -60,14 +59,10 @@ export class Direct extends DriverProvider {
chromeDriverFile = this.config_.chromeDriver;
} else {
try {
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
chromeDriverFile = updateConfig.chrome.last;
chromeDriverFile = new ChromeDriver().getBinaryPath();
} catch (e) {
throw new BrowserError(
logger,
'Could not find update-config.json. ' +
'Run \'webdriver-manager update\' to download binaries.');
logger, 'Run \'webdriver-manager update\' to download binaries.');
}
}

Expand All @@ -79,27 +74,19 @@ export class Direct extends DriverProvider {
}

let chromeService = new ChromeServiceBuilder(chromeDriverFile).build();
// driver = ChromeDriver.createSession(new Capabilities(this.config_.capabilities),
// chromeService);
// TODO(ralphj): fix typings
driver =
require('selenium-webdriver/chrome')
.Driver.createSession(new Capabilities(this.config_.capabilities), chromeService);
driver = DriverForChrome.createSession(
new Capabilities(this.config_.capabilities), chromeService);
break;
case 'firefox':
let geckoDriverFile: string;
if (this.config_.geckoDriver) {
geckoDriverFile = this.config_.geckoDriver;
} else {
try {
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
geckoDriverFile = updateConfig.gecko.last;
geckoDriverFile = new GeckoDriver().getBinaryPath();
} catch (e) {
throw new BrowserError(
logger,
'Could not find update-config.json. ' +
'Run \'webdriver-manager update\' to download binaries.');
logger, 'Run \'webdriver-manager update\' to download binaries.');
}
}

Expand All @@ -110,14 +97,9 @@ export class Direct extends DriverProvider {
'. Run \'webdriver-manager update\' to download binaries.');
}

// TODO (mgiambalvo): Turn this into an import when the selenium typings are updated.
const FirefoxServiceBuilder = require('selenium-webdriver/firefox').ServiceBuilder;

let firefoxService = new FirefoxServiceBuilder(geckoDriverFile).build();
// TODO(mgiambalvo): Fix typings.
driver =
require('selenium-webdriver/firefox')
.Driver.createSession(new Capabilities(this.config_.capabilities), firefoxService);
driver = DriverForFirefox.createSession(
new Capabilities(this.config_.capabilities), firefoxService);
break;
default:
throw new BrowserError(
Expand Down
35 changes: 9 additions & 26 deletions lib/driverProviders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
* so that we only start the local selenium once per entire launch.
*/
import * as fs from 'fs';
import * as path from 'path';
import {SeleniumServer} from 'selenium-webdriver/remote';
import {ChromeDriver, GeckoDriver, SeleniumServer as WdmSeleniumServer} from 'webdriver-manager-replacement';

import {Config} from '../config';
import {BrowserError, ConfigError} from '../exitCodes';
import {Logger} from '../logger';

import {DriverProvider} from './driverProvider';

const SeleniumConfig = require('webdriver-manager/built/lib/config').Config;
const remote = require('selenium-webdriver/remote');

let logger = new Logger('local');

export class Local extends DriverProvider {
Expand All @@ -37,14 +35,9 @@ export class Local extends DriverProvider {
'Attempting to find the SeleniumServerJar in the default ' +
'location used by webdriver-manager');
try {
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
this.config_.seleniumServerJar = updateConfig.standalone.last;
this.config_.seleniumServerJar = new WdmSeleniumServer().getBinaryPath();
} catch (err) {
throw new BrowserError(
logger,
'No update-config.json found.' +
' Run \'webdriver-manager update\' to download binaries.');
throw new BrowserError(logger, 'Run \'webdriver-manager update\' to download binaries.');
}
}
if (!fs.existsSync(this.config_.seleniumServerJar)) {
Expand All @@ -60,14 +53,9 @@ export class Local extends DriverProvider {
'location used by webdriver-manager');

try {
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
this.config_.chromeDriver = updateConfig.chrome.last;
this.config_.chromeDriver = new ChromeDriver().getBinaryPath();
} catch (err) {
throw new BrowserError(
logger,
'No update-config.json found. ' +
'Run \'webdriver-manager update\' to download binaries.');
throw new BrowserError(logger, 'Run \'webdriver-manager update\' to download binaries.');
}
}

Expand All @@ -91,14 +79,9 @@ export class Local extends DriverProvider {
'location used by webdriver-manager');

try {
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
this.config_.geckoDriver = updateConfig.gecko.last;
this.config_.geckoDriver = new GeckoDriver().getBinaryPath();
} catch (err) {
throw new BrowserError(
logger,
'No update-config.json found. ' +
'Run \'webdriver-manager update\' to download binaries.');
throw new BrowserError(logger, 'Run \'webdriver-manager update\' to download binaries.');
}
}

Expand Down Expand Up @@ -152,7 +135,7 @@ export class Local extends DriverProvider {
serverConf.jvmArgs.push('-Dwebdriver.gecko.driver=' + this.config_.geckoDriver);
}

this.server_ = new remote.SeleniumServer(this.config_.seleniumServerJar, serverConf);
this.server_ = new SeleniumServer(this.config_.seleniumServerJar, serverConf);

// start local server, grab hosted address, and resolve promise
const url = await this.server_.start(this.config_.seleniumServerStartTimeout);
Expand Down
Loading

0 comments on commit 424060a

Please sign in to comment.