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

Commit 8ff4787

Browse files
committed
fix(runner): exit with proper code when tests fail
When errors with messages matching /timeout/ were created, Protractor clears the control flow so that the remainder of the tasks scheduled for that spec don't bleed over into the next spec. This was messing up the promises used in the runner, since they are also webdriver promises. Long term, the runner should _not_ use webdriver promises. For now, fix by having the runner resolve promises directly rather than through chaining, and add a TODO to use promises which aren't connected to WebDriver's control flow in the runner. Closes #214.
1 parent ebc528f commit 8ff4787

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lib/runner.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ var cleanUp = function(runner) {
9999
* the value of the selenium address that will be used.
100100
*/
101101
var setUpSelenium = function() {
102-
var promise = webdriver.promise.defer();
102+
// TODO: This should not be tied to the webdriver promise loop, it should use
103+
// another promise system instead.
104+
var deferred = webdriver.promise.defer();
103105

104106
if (config.sauceUser && config.sauceKey) {
105107
sauceAccount = new SauceLabs({
@@ -110,7 +112,7 @@ var setUpSelenium = function() {
110112

111113
if (config.seleniumAddress) {
112114
util.puts('Using the selenium server at ' + config.seleniumAddress);
113-
promise.fulfill(config.seleniumAddress);
115+
deferred.fulfill(config.seleniumAddress);
114116
} else if (sauceAccount) {
115117
config.capabilities.username = config.sauceUser;
116118
config.capabilities.accessKey = config.sauceKey;
@@ -121,7 +123,7 @@ var setUpSelenium = function() {
121123
config.sauceKey + '@ondemand.saucelabs.com:80/wd/hub';
122124

123125
util.puts('Using SauceLabs selenium server at ' + config.seleniumAddress);
124-
promise.fulfill(config.seleniumAddress);
126+
deferred.fulfill(config.seleniumAddress);
125127
} else if (config.seleniumServerJar) {
126128
util.puts('Starting selenium standalone server...');
127129
if (config.chromeDriver) {
@@ -143,14 +145,14 @@ var setUpSelenium = function() {
143145

144146
util.puts('Selenium standalone server started at ' + url);
145147
config.seleniumAddress = server.address();
146-
promise.fulfill(config.seleniumAddress);
148+
deferred.fulfill(config.seleniumAddress);
147149
});
148150
} else {
149151
throw new Error('You must specify either a seleniumAddress, ' +
150152
'seleniumServerJar, or saucelabs account.');
151153
}
152154

153-
return promise;
155+
return deferred.promise;
154156
}
155157

156158
/**
@@ -181,7 +183,9 @@ var runJasmineTests = function() {
181183
}
182184

183185
minijn.addSpecs(resolvedSpecs);
184-
var runPromise = webdriver.promise.defer();
186+
// TODO: This should not be tied to the webdriver promise loop, it should use
187+
// another promise system instead.
188+
var runDeferred = webdriver.promise.defer();
185189
driver = new webdriver.Builder().
186190
usingServer(config.seleniumAddress).
187191
withCapabilities(config.capabilities).build();
@@ -227,25 +231,29 @@ var runJasmineTests = function() {
227231
originalOnComplete(runner, log);
228232
}
229233
driver.quit().then(function() {
230-
runPromise.fulfill(runner);
234+
runDeferred.fulfill(runner);
231235
});
232236
};
233237

234238
minijn.executeSpecs(options);
235239
});
236240
});
237241

238-
return runPromise;
242+
return runDeferred.promise;
239243
};
240244

241245

242246
/**
243247
* Run Protractor once.
244248
*/
245249
var runOnce = function() {
246-
setUpSelenium().
247-
then(runJasmineTests).
248-
then(cleanUp);
250+
setUpSelenium().then(function() {
251+
// cleanUp must be registered directly onto runJasmineTests, not onto
252+
// the chained promise, so that cleanUp is still called in case of a
253+
// timeout error. Timeout errors need to clear the control flow, which
254+
// would mess up chaining promises.
255+
runJasmineTests().then(cleanUp);
256+
});
249257
};
250258

251259
exports.addConfig = addConfig;

0 commit comments

Comments
 (0)