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

Commit 08ef244

Browse files
committed
Adding debugging tests showing different types of timeouts, and fixing
a bug where scheduled tasks from a previous it block would run into the next in case of a timeout.
1 parent 7a59479 commit 08ef244

File tree

6 files changed

+120
-10
lines changed

6 files changed

+120
-10
lines changed
File renamed without changes.

debugging/timeout_conf.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Examples of tests to show how timeouts works with Protractor. Tests
2+
// should be run against the testapp.
3+
4+
exports.config = {
5+
seleniumAddress: 'http://localhost:4444/wd/hub',
6+
7+
// Spec patterns are relative to the current working directly when
8+
// protractor is called.
9+
specs: [
10+
'debugging/timeout_spec.js',
11+
],
12+
13+
capabilities: {
14+
'browserName': 'chrome'
15+
},
16+
17+
baseUrl: 'http://localhost:8000',
18+
19+
// ----- Options to be passed to minijasminenode.
20+
jasmineNodeOpts: {
21+
onComplete: null,
22+
isVerbose: false,
23+
showColors: true,
24+
includeStackTrace: true
25+
}
26+
};

debugging/timeout_spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
describe('timeout possibilities', function() {
2+
ptor = protractor.getInstance();
3+
jasmine.getEnv().defaultTimeoutInterval = 33;
4+
5+
6+
it('shoud pass - first test should not timeout', function() {
7+
expect(true).toEqual(true);
8+
});
9+
10+
it('should timeout due to webdriver script timeout', function() {
11+
ptor.driver.manage().timeouts().setScriptTimeout(55);
12+
13+
ptor.get('app/index.html#/form');
14+
15+
ptor.driver.executeAsyncScript(function() {
16+
var callback = arguments[arguments.length - 1];
17+
setTimeout(callback, 500);
18+
});
19+
20+
expect(ptor.findElement(protractor.By.binding('greeting')).getText()).
21+
toEqual('Hiya');
22+
}, 5000); // The 5000 here sets the Jasmine spec timeout.
23+
24+
it('should fail normally', function() {
25+
expect(false).toEqual(true);
26+
});
27+
28+
it('should pass - tests in the middle should be unaffected', function() {
29+
expect(true).toEqual(true);
30+
});
31+
32+
it('should timeout due to Jasmine spec timeout', function() {
33+
ptor.driver.sleep(1000);
34+
expect(true).toBe(true);
35+
});
36+
37+
it('should pass - previous timeouts should not affect this', function() {
38+
expect(true).toEqual(true);
39+
});
40+
});

jasminewd/index.js

+40
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,43 @@ global.expect = function(actual) {
106106
return originalExpect(actual);
107107
}
108108
};
109+
110+
/**
111+
* A Jasmine reporter which does nothing but execute the input function
112+
* on a timeout failure.
113+
*/
114+
var OnTimeoutReporter = function(fn) {
115+
this.callback = fn;
116+
};
117+
118+
OnTimeoutReporter.prototype.reportRunnerStarting = function() {};
119+
OnTimeoutReporter.prototype.reportRunnerResults = function() {};
120+
OnTimeoutReporter.prototype.reportSuiteResults = function() {};
121+
OnTimeoutReporter.prototype.reportSpecStarting = function() {};
122+
OnTimeoutReporter.prototype.reportSpecResults = function(spec) {
123+
if (!spec.results().passed()) {
124+
var result = spec.results();
125+
var failureItem = null;
126+
127+
var items_length = result.getItems().length;
128+
for (var i = 0; i < items_length; i++) {
129+
if (result.getItems()[i].passed_ === false) {
130+
failureItem = result.getItems()[i];
131+
132+
if (failureItem.toString().match(/timeout/)) {
133+
this.callback();
134+
}
135+
}
136+
}
137+
}
138+
};
139+
OnTimeoutReporter.prototype.log = function() {};
140+
141+
// On timeout, the flow should be reset. This will prevent webdriver tasks
142+
// from overflowing into the next test and causing it to fail or timeout
143+
// as well. This is done in the reporter instead of an afterEach block
144+
// to ensure that it runs after any afterEach() blocks with webdriver tasks
145+
// get to complete first.
146+
jasmine.getEnv().addReporter(new OnTimeoutReporter(function() {
147+
flow.reset();
148+
}));

jasminewd/spec/adapterSpec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ describe('webdriverJS Jasmine adapter', function() {
104104
// }, 200);
105105

106106
// it('should timeout after 300ms', function() {
107-
// fakeDriver.sleep(999);
107+
// fakeDriver.sleep(9999);
108108
// expect(fakeDriver.getValueB()).toEqual('b');
109109
// }, 300);
110+
111+
it('should pass after the timed out tests', function() {
112+
expect(true).toEqual(true);
113+
});
110114
});

lib/cli.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ var startJasmineTests = function() {
127127
driver.manage().timeouts().setScriptTimeout(100000);
128128
driver.getSession().then(function(session) {
129129
id = session.id;
130-
});
131130

132-
protractor.setInstance(protractor.wrapDriver(driver, config.baseUrl));
131+
protractor.setInstance(protractor.wrapDriver(driver, config.baseUrl));
133132

134-
// Export protractor to the global namespace to be used in tests.
135-
global.protractor = protractor;
133+
// Export protractor to the global namespace to be used in tests.
134+
global.protractor = protractor;
136135

137-
// Set up the Jasmine WebDriver Adapter
138-
require('../jasminewd');
136+
// Set up the Jasmine WebDriver Adapter
137+
require('../jasminewd');
139138

140-
var options = config.jasmineNodeOpts;
141-
options.onComplete = cleanUp;
139+
var options = config.jasmineNodeOpts;
140+
options.onComplete = cleanUp;
142141

143-
minijn.executeSpecs(options);
142+
minijn.executeSpecs(options);
143+
});
144144
}
145145

146146
if (!args.length) {

0 commit comments

Comments
 (0)