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

Commit

Permalink
feat(protractor/runner): allow multiple browser in test
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Nov 20, 2014
1 parent 47f12ba commit c45aa59
Show file tree
Hide file tree
Showing 19 changed files with 340 additions and 113 deletions.
1 change: 1 addition & 0 deletions lib/configParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var ConfigParser = function() {
this.config_= {
specs: [],
multiCapabilities: [],
numDrivers: 1,
rootElement: 'body',
allScriptsTimeout: 11000,
getPageTimeout: 10000,
Expand Down
6 changes: 3 additions & 3 deletions lib/driverProviders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Each file exports a function which takes in the configuration as a parameter and
DriverProvider.prototype.setupEnv

/**
* @return {webdriver.WebDriver} The setup driver instance.
* @return {Array<webdriver.WebDriver>} The setup driver instances.
*/
DriverProvider.prototype.getDriver
DriverProvider.prototype.getDrivers

/**
* @return {q.promise} A promise which will resolve when the environment
Expand All @@ -37,6 +37,6 @@ DriverProvider.prototype.updateJob
Requirements
------------

- `setupEnv` and `getDriver` will be called before the test framework is loaded, so any pre-work which might cause timeouts on the first test should be done there.
- `setupEnv` and `getDrivers` will be called before the test framework is loaded, so any pre-work which might cause timeouts on the first test should be done there.

- `teardownEnv` should call the driver's `quit` method.
49 changes: 34 additions & 15 deletions lib/driverProviders/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var webdriver = require('selenium-webdriver'),

var DirectDriverProvider = function(config) {
this.config_ = config;
this.driver_ = null;
this.drivers_ = null;
};

/**
Expand All @@ -39,29 +39,31 @@ DirectDriverProvider.prototype.setupEnv = function() {

/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the driver.
* Shuts down the drivers.
*
* @public
* @return {q.promise} A promise which will resolve when the environment
* is down.
*/
DirectDriverProvider.prototype.teardownEnv = function() {
var deferred = q.defer();
this.driver_.quit().then(function() {
deferred.resolve();
var deferredArray = this.drivers_.map(function(driver) {
var deferred = q.defer();
driver.quit().then(function() {
deferred.resolve();
});
return deferred.promise;
});
return deferred.promise;
return q.all(deferredArray);
};

/**
* Retrieve the webdriver for the runner.
* @public
* Create a new driver.
*
* @private
* @return webdriver instance
*/
DirectDriverProvider.prototype.getDriver = function() {
if (this.driver_) {
return this.driver_;
}
DirectDriverProvider.prototype.newDriver_ = function() {
var driver;
switch (this.config_.capabilities.browserName) {
case 'chrome':
var chromeDriverFile = this.config_.chromeDriver ||
Expand All @@ -78,20 +80,37 @@ DirectDriverProvider.prototype.getDriver = function() {
}

var service = new chrome.ServiceBuilder(chromeDriverFile).build();
this.driver_ = chrome.createDriver(
driver = chrome.createDriver(
new webdriver.Capabilities(this.config_.capabilities), service);
break;
case 'firefox':
if (this.config_.firefoxPath) {
this.config_.capabilities.firefox_binary = this.config_.firefoxPath;
}
this.driver_ = new firefox.Driver(this.config_.capabilities);
driver = new firefox.Driver(this.config_.capabilities);
break;
default:
throw new Error('browserName ' + this.config_.capabilities.browserName +
'is not supported with directConnect.');
}
return this.driver_;
return driver;
};

/**
* Retrieve the array of webdrivers for the runner.
* The count is specified in config.numDrivers
* @public
* @return Array<webdriver.WebDriver>
*/
DirectDriverProvider.prototype.getDrivers = function() {
if (this.drivers_) {
return this.drivers_;
}
this.drivers_ = [];
for (var i = 0; i < this.config_.numDrivers; ++i) {
this.drivers_.push(this.newDriver_());
}
return this.drivers_;
};

// new instance w/ each include
Expand Down
38 changes: 23 additions & 15 deletions lib/driverProviders/hosted.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var util = require('util'),

var HostedDriverProvider = function(config) {
this.config_ = config;
this.driver_ = null;
this.drivers_ = null;
};

/**
Expand All @@ -36,33 +36,41 @@ HostedDriverProvider.prototype.setupEnv = function() {

/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the driver.
* Shuts down the drivers.
*
* @public
* @return {q.promise} A promise which will resolve when the environment
* is down.
*/
HostedDriverProvider.prototype.teardownEnv = function() {
var deferred = q.defer();
this.driver_.quit().then(function() {
deferred.resolve();
var deferredArray = this.drivers_.map(function(driver) {
var deferred = q.defer();
driver.quit().then(function() {
deferred.resolve();
});
return deferred.promise;
});
return deferred.promise;
return q.all(deferredArray);
};

/**
* Return the webdriver for the runner.
* Retrieve the array of webdrivers for the runner.
* The count is specified in config.numDrivers
* @public
* @return webdriver instance
* @return Array<webdriver.WebDriver>
*/
HostedDriverProvider.prototype.getDriver = function() {
if (!this.driver_) {
this.driver_ = new webdriver.Builder().
usingServer(this.config_.seleniumAddress).
withCapabilities(this.config_.capabilities).
build();
HostedDriverProvider.prototype.getDrivers = function() {
if (!this.drivers_) {
this.drivers_ = [];
for (var i = 0; i < this.config_.numDrivers; ++i) {
var newDriver = new webdriver.Builder().
usingServer(this.config_.seleniumAddress).
withCapabilities(this.config_.capabilities).
build();
this.drivers_.push(newDriver);
}
}
return this.driver_;
return this.drivers_;
};

// new instance w/ each include
Expand Down
40 changes: 26 additions & 14 deletions lib/driverProviders/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var util = require('util'),

var LocalDriverProvider = function(config) {
this.config_ = config;
this.driver_ = null;
this.drivers_ = null;
this.server_ = null;
};

Expand Down Expand Up @@ -88,39 +88,51 @@ LocalDriverProvider.prototype.setupEnv = function() {

/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the driver.
* Shuts down the drivers and server.
*
* @public
* @return {q.promise} A promise which will resolve when the environment
* is down.
*/
LocalDriverProvider.prototype.teardownEnv = function() {
var deferred = q.defer();
var self = this;

util.puts('Shutting down selenium standalone server.');
self.driver_.quit().then(function() {
return self.server_.stop().then(function() {
var deferredArray = this.drivers_.map(function(driver) {
var deferred = q.defer();
driver.quit().then(function() {
deferred.resolve();
});
return deferred.promise;
});

var deferred = q.defer();
q.all(deferredArray).then(function() {
self.server_.stop().then(function() {
deferred.resolve();
});
});
return deferred.promise;
};

/**
* Retrieve the webdriver for the runner.
* Retrieve the array of webdrivers for the runner.
* The count is specified in config.numDrivers
* @public
* @return webdriver instance
* @return Array<webdriver.WebDriver>
*/
LocalDriverProvider.prototype.getDriver = function() {
if (!this.driver_) {
this.driver_ = new webdriver.Builder().
usingServer(this.config_.seleniumAddress).
withCapabilities(this.config_.capabilities).
build();
LocalDriverProvider.prototype.getDrivers = function() {
if (!this.drivers_) {
this.drivers_ = [];
for (var i = 0; i < this.config_.numDrivers; ++i) {
var newDriver = new webdriver.Builder().
usingServer(this.config_.seleniumAddress).
withCapabilities(this.config_.capabilities).
build();
this.drivers_.push(newDriver);
}
}
return this.driver_;
return this.drivers_;
};

// new instance w/ each include
Expand Down
31 changes: 19 additions & 12 deletions lib/driverProviders/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var webdriver = require('selenium-webdriver'),
* @constructor
*/
var MockExecutor = function() {
this.driver_ = null;
this.drivers_ = null;
};

/**
Expand Down Expand Up @@ -44,23 +44,30 @@ MockDriverProvider.prototype.setupEnv = function() {
* @return {q.promise} A promise which will resolve immediately.
*/
MockDriverProvider.prototype.teardownEnv = function() {
var deferred = q.defer();
this.driver_.quit().then(function() {
deferred.resolve();
var deferredArray = this.drivers_.map(function(driver) {
var deferred = q.defer();
driver.quit().then(function() {
deferred.resolve();
});
return deferred.promise;
});
return deferred.promise;
return q.all(deferredArray);
};

/**
* Retrieve the webdriver for the runner.
* Retrieve the array of webdrivers for the runner.
* The count is specified in config.numDrivers
* @public
* @return webdriver instance
* @return Array<webdriver.WebDriver>
*/
MockDriverProvider.prototype.getDriver = function() {
var mockSession = new webdriver.Session('test_session_id', {});

this.driver_ = new webdriver.WebDriver(mockSession, new MockExecutor());
return this.driver_;
MockDriverProvider.prototype.getDrivers = function() {
this.drivers_ = [];
for (var i = 0; i < this.config_.numDrivers; ++i) {
var mockSession = new webdriver.Session('test_session_id', {});
this.drivers_.push(new webdriver.WebDriver(mockSession, new MockExecutor()));
}

return this.drivers_;
};

// new instance w/ each include
Expand Down
Loading

0 comments on commit c45aa59

Please sign in to comment.