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

chore(quitDriver): have quitDriver return a webdriver promise directly #3992

Merged
merged 1 commit into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/driverProviders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ DriverProvider.prototype.getNewDriver

/**
* @param {webdriver.WebDriver} The driver instance to quit.
* @return {webdriver.promise.Promise<void>} A promise which resolves when the instance has quit
*/
DriverProvider.prototype.quitDriver

/**
* @return {q.promise} A promise which will resolve when the environment
* is down.
* @return {q.Promise<any>} A promise which will resolve when the environment is down.
*/
DriverProvider.prototype.teardownEnv

Expand Down
8 changes: 3 additions & 5 deletions lib/driverProviders/attachSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* it down, and setting up the driver correctly.
*/
import * as q from 'q';
import {WebDriver} from 'selenium-webdriver';
import {promise as wdpromise, WebDriver} from 'selenium-webdriver';

import {Config} from '../config';
import {Logger} from '../logger';
Expand Down Expand Up @@ -50,9 +50,7 @@ export class AttachSession extends DriverProvider {
*
* @public
*/
quitDriver(): q.Promise<WebDriver> {
let defer = q.defer<WebDriver>();
defer.resolve(null);
return defer.promise;
quitDriver(): wdpromise.Promise<void> {
return wdpromise.when(undefined);
}
}
51 changes: 31 additions & 20 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* it down, and setting up the driver correctly.
*/
import * as q from 'q';
import {Builder, Session, WebDriver} from 'selenium-webdriver';
import {Builder, promise as wdpromise, Session, WebDriver} from 'selenium-webdriver';

import {BlockingProxyRunner} from '../bpRunner';
import {Config} from '../config';
Expand Down Expand Up @@ -65,30 +65,44 @@ export abstract class DriverProvider {
* @public
* @param webdriver instance
*/
quitDriver(driver: WebDriver): q.Promise<WebDriver> {
quitDriver(driver: WebDriver): wdpromise.Promise<void> {
let driverIndex = this.drivers_.indexOf(driver);
if (driverIndex >= 0) {
this.drivers_.splice(driverIndex, 1);
}

let deferred = q.defer<WebDriver>();
if (driver.getSession() === undefined) {
deferred.resolve();
return wdpromise.when(undefined);
} else {
driver.getSession()
.then((session_: Session) => {
return driver.getSession()
.then<void>((session_: Session) => {
if (session_) {
driver.quit().then(function() {
deferred.resolve();
});
} else {
deferred.resolve();
return driver.quit();
}
})
.catch((err: Error) => {
deferred.resolve();
});
.catch<void>(function(err: Error) {});
}
}


/**
* Quits an array of drivers and returns a q promise instead of a webdriver one
*
* @param drivers {webdriver.WebDriver[]} The webdriver instances
*/
static quitDrivers(provider: DriverProvider, drivers: WebDriver[]): q.Promise<void> {
let deferred = q.defer<void>();
wdpromise
.all(drivers.map((driver: WebDriver) => {
return provider.quitDriver(driver);
}))
.then(
() => {
deferred.resolve();
},
() => {
deferred.resolve();
});
return deferred.promise;
}

Expand Down Expand Up @@ -123,12 +137,9 @@ export abstract class DriverProvider {
* Shuts down the drivers.
*
* @public
* @return {q.promise} A promise which will resolve when the environment
* is down.
* @return {q.Promise<any>} A promise which will resolve when the environment is down.
*/
teardownEnv(): q.Promise<q.Promise<WebDriver>[]> {
return q.all<any>(this.drivers_.map((driver: WebDriver) => {
return this.quitDriver(driver);
}));
teardownEnv(): q.Promise<any> {
return DriverProvider.quitDrivers(this, this.drivers_);
}
}
7 changes: 3 additions & 4 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ export class Runner extends EventEmitter {
* @return {q.Promise} A promise which resolves on finish.
* @private
*/
shutdown_(): q.Promise<any> {
return q.all(this.driverprovider_.getExistingDrivers().map((webdriver) => {
return this.driverprovider_.quitDriver(webdriver);
}));
shutdown_(): q.Promise<void> {
return DriverProvider.quitDrivers(
this.driverprovider_, this.driverprovider_.getExistingDrivers());
}

/**
Expand Down