Skip to content

Commit

Permalink
fix(driverProviders): Handle promise rejection when starting selenium (
Browse files Browse the repository at this point in the history
…angular#3989)

Fixes angular#3986. Also error if jvmArgs isn't an array.
  • Loading branch information
heathkit authored and igniteram committed Feb 21, 2017
1 parent d65bdfc commit 2ad2cbe
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/driverProviders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as path from 'path';
import * as q from 'q';

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

import {DriverProvider} from './driverProvider';
Expand Down Expand Up @@ -95,13 +95,15 @@ export class Local extends DriverProvider {
* ready to test.
*/
setupDriverEnv(): q.Promise<any> {
let deferred = q.defer();

this.addDefaultBinaryLocs_();
logger.info('Starting selenium standalone server...');

let serverConf = this.config_.localSeleniumStandaloneOpts || {};

if (!Array.isArray(serverConf.jvmArgs)) {
throw new ConfigError(logger, 'jvmArgs should be an array.');
}

// If args or port is not set use seleniumArgs and seleniumPort
// for backward compatibility
if (serverConf.args === undefined) {
Expand All @@ -121,14 +123,20 @@ export class Local extends DriverProvider {

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

let deferred = q.defer();
// start local server, grab hosted address, and resolve promise
this.server_.start(this.config_.seleniumServerStartTimeout).then((url: string) => {
logger.info('Selenium standalone server started at ' + url);
this.server_.address().then((address: string) => {
this.config_.seleniumAddress = address;
deferred.resolve();
});
});
this.server_.start(this.config_.seleniumServerStartTimeout)
.then((url: string) => {
logger.info('Selenium standalone server started at ' + url);
return this.server_.address();
})
.then((address: string) => {
this.config_.seleniumAddress = address;
deferred.resolve();
})
.catch((err: string) => {
deferred.reject(err);
});

return deferred.promise;
}
Expand All @@ -143,13 +151,9 @@ export class Local extends DriverProvider {
* is down.
*/
teardownEnv(): q.Promise<any> {
let deferred = q.defer();
super.teardownEnv().then(() => {
return super.teardownEnv().then(() => {
logger.info('Shutting down selenium standalone server.');
this.server_.stop().then(() => {
deferred.resolve();
});
return this.server_.stop();
});
return deferred.promise;
}
}

0 comments on commit 2ad2cbe

Please sign in to comment.