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

Commit

Permalink
feat(runner/hosted): add support for promises for seleniumAddress and…
Browse files Browse the repository at this point in the history
… capabilities

Change driverProviders/hosted to resolve promise values
in configuration to allow async jobs in setup. Specifically,
seleniumAddress, capabilities, and multiCapabilities may be promises. Primarily,
this would be for a network call to acquire a selenium host
or to start a proxy server.
  • Loading branch information
samlecuyer authored and juliemr committed Aug 4, 2014
1 parent 6de2e32 commit 316961c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
15 changes: 12 additions & 3 deletions lib/driverProviders/hosted.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var util = require('util'),
webdriver = require('selenium-webdriver'),
q = require('q');


var HostedDriverProvider = function(config) {
this.config_ = config;
this.driver_ = null;
Expand All @@ -21,8 +20,18 @@ var HostedDriverProvider = function(config) {
* ready to test.
*/
HostedDriverProvider.prototype.setupEnv = function() {
util.puts('Using the selenium server at ' + this.config_.seleniumAddress);
return q.fcall(function() {});
var config = this.config_,
seleniumAddress = config.seleniumAddress;

if (q.isPromiseAlike(seleniumAddress)) {
return q.when(seleniumAddress).then(function(resolvedAddress) {
config.seleniumAddress = resolvedAddress;
util.puts('Using the selenium server at ' + config.seleniumAddress);
});
} else {
util.puts('Using the selenium server at ' + this.config_.seleniumAddress);
return q.fcall(function() {});
}
};

/**
Expand Down
11 changes: 8 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,17 @@ Runner.prototype.run = function() {

// 1) Setup environment
return this.driverprovider_.setupEnv().then(function() {
driver = self.driverprovider_.getDriver();
return q.fcall(function() {});
return q.all(
[self.config_.capabilities, self.config_.multiCapabilities]).
spread(function(capabilites, multiCapabilities) {
self.config_.capabilities = capabilites;
self.config_.multiCapabilities = multiCapabilities;
}).then(function() {
driver = self.driverprovider_.getDriver();
});

// 2) Execute test cases
}).then(function() {

var deferred = q.defer();
driver.manage().timeouts().setScriptTimeout(self.config_.allScriptsTimeout);
self.setupGlobals_.bind(self)(driver);
Expand Down
15 changes: 14 additions & 1 deletion spec/driverprovider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ testDriverProvider(require('../lib/driverProviders/chrome')(chromeConfig)).
});

var hostedConfig = {
sauceAddress: 'http://localhost:4444/wd/hub',
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName: 'firefox'
}
Expand All @@ -64,6 +64,19 @@ testDriverProvider(require('../lib/driverProviders/hosted')(hostedConfig)).
console.log('hosted.dp failed with ' + err);
});

var hostedPromisedConfig = {
seleniumAddress: q.when('http://localhost:4444/wd/hub'),
capabilities: {
browserName: 'firefox'
}
};
testDriverProvider(require('../lib/driverProviders/hosted')(hostedPromisedConfig)).
then(function() {
console.log('hosted.dp with promises working!');
}, function(err) {
console.log('hosted.dp with promises failed with ' + err);
});

var localConfig = {
seleniumArgs: [],
capabilities: {
Expand Down
25 changes: 24 additions & 1 deletion spec/unit/runner_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,34 @@ describe('the Protractor runner', function() {
});
});

it('should wait for promise capabilities to resolve', function(done) {
var config = {
mockSelenium: true,
specs: ['*.js'],
framework: 'debugprint',
capabilities: q.when({
'browserName': 'customfortest'
})
};
var exitCode;
Runner.prototype.exit_ = function(exit) {
exitCode = exit;
};
var runner = new Runner(config);

runner.run().then(function() {
expect(runner.getConfig().capabilities.browserName).
toEqual('customfortest');
expect(exitCode).toEqual(0);
done();
});
});

it('should fail with no specs', function() {
var config = {
mockSelenium: true,
specs: [],
framework: 'simpleprint'
framework: 'debugprint'
};
var exitCode;
Runner.prototype.exit_ = function(exit) {
Expand Down

0 comments on commit 316961c

Please sign in to comment.