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

Commit 316961c

Browse files
samlecuyerjuliemr
authored andcommitted
feat(runner/hosted): add support for promises for seleniumAddress and 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.
1 parent 6de2e32 commit 316961c

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

lib/driverProviders/hosted.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var util = require('util'),
88
webdriver = require('selenium-webdriver'),
99
q = require('q');
1010

11-
1211
var HostedDriverProvider = function(config) {
1312
this.config_ = config;
1413
this.driver_ = null;
@@ -21,8 +20,18 @@ var HostedDriverProvider = function(config) {
2120
* ready to test.
2221
*/
2322
HostedDriverProvider.prototype.setupEnv = function() {
24-
util.puts('Using the selenium server at ' + this.config_.seleniumAddress);
25-
return q.fcall(function() {});
23+
var config = this.config_,
24+
seleniumAddress = config.seleniumAddress;
25+
26+
if (q.isPromiseAlike(seleniumAddress)) {
27+
return q.when(seleniumAddress).then(function(resolvedAddress) {
28+
config.seleniumAddress = resolvedAddress;
29+
util.puts('Using the selenium server at ' + config.seleniumAddress);
30+
});
31+
} else {
32+
util.puts('Using the selenium server at ' + this.config_.seleniumAddress);
33+
return q.fcall(function() {});
34+
}
2635
};
2736

2837
/**

lib/runner.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,17 @@ Runner.prototype.run = function() {
232232

233233
// 1) Setup environment
234234
return this.driverprovider_.setupEnv().then(function() {
235-
driver = self.driverprovider_.getDriver();
236-
return q.fcall(function() {});
235+
return q.all(
236+
[self.config_.capabilities, self.config_.multiCapabilities]).
237+
spread(function(capabilites, multiCapabilities) {
238+
self.config_.capabilities = capabilites;
239+
self.config_.multiCapabilities = multiCapabilities;
240+
}).then(function() {
241+
driver = self.driverprovider_.getDriver();
242+
});
237243

238244
// 2) Execute test cases
239245
}).then(function() {
240-
241246
var deferred = q.defer();
242247
driver.manage().timeouts().setScriptTimeout(self.config_.allScriptsTimeout);
243248
self.setupGlobals_.bind(self)(driver);

spec/driverprovider_test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ testDriverProvider(require('../lib/driverProviders/chrome')(chromeConfig)).
5252
});
5353

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

67+
var hostedPromisedConfig = {
68+
seleniumAddress: q.when('http://localhost:4444/wd/hub'),
69+
capabilities: {
70+
browserName: 'firefox'
71+
}
72+
};
73+
testDriverProvider(require('../lib/driverProviders/hosted')(hostedPromisedConfig)).
74+
then(function() {
75+
console.log('hosted.dp with promises working!');
76+
}, function(err) {
77+
console.log('hosted.dp with promises failed with ' + err);
78+
});
79+
6780
var localConfig = {
6881
seleniumArgs: [],
6982
capabilities: {

spec/unit/runner_test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,34 @@ describe('the Protractor runner', function() {
3030
});
3131
});
3232

33+
it('should wait for promise capabilities to resolve', function(done) {
34+
var config = {
35+
mockSelenium: true,
36+
specs: ['*.js'],
37+
framework: 'debugprint',
38+
capabilities: q.when({
39+
'browserName': 'customfortest'
40+
})
41+
};
42+
var exitCode;
43+
Runner.prototype.exit_ = function(exit) {
44+
exitCode = exit;
45+
};
46+
var runner = new Runner(config);
47+
48+
runner.run().then(function() {
49+
expect(runner.getConfig().capabilities.browserName).
50+
toEqual('customfortest');
51+
expect(exitCode).toEqual(0);
52+
done();
53+
});
54+
});
55+
3356
it('should fail with no specs', function() {
3457
var config = {
3558
mockSelenium: true,
3659
specs: [],
37-
framework: 'simpleprint'
60+
framework: 'debugprint'
3861
};
3962
var exitCode;
4063
Runner.prototype.exit_ = function(exit) {

0 commit comments

Comments
 (0)