Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

fix(driverProviders): Handle promise rejection when starting selenium #3989

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}