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

Commit

Permalink
Adding debugging tests showing different types of timeouts, and fixing
Browse files Browse the repository at this point in the history
a bug where scheduled tasks from a previous it block would run into
the next in case of a timeout.
  • Loading branch information
juliemr committed Aug 24, 2013
1 parent 7a59479 commit 08ef244
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 10 deletions.
File renamed without changes.
26 changes: 26 additions & 0 deletions debugging/timeout_conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Examples of tests to show how timeouts works with Protractor. Tests
// should be run against the testapp.

exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',

// Spec patterns are relative to the current working directly when
// protractor is called.
specs: [
'debugging/timeout_spec.js',
],

capabilities: {
'browserName': 'chrome'
},

baseUrl: 'http://localhost:8000',

// ----- Options to be passed to minijasminenode.
jasmineNodeOpts: {
onComplete: null,
isVerbose: false,
showColors: true,
includeStackTrace: true
}
};
40 changes: 40 additions & 0 deletions debugging/timeout_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
describe('timeout possibilities', function() {
ptor = protractor.getInstance();
jasmine.getEnv().defaultTimeoutInterval = 33;


it('shoud pass - first test should not timeout', function() {
expect(true).toEqual(true);
});

it('should timeout due to webdriver script timeout', function() {
ptor.driver.manage().timeouts().setScriptTimeout(55);

ptor.get('app/index.html#/form');

ptor.driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
setTimeout(callback, 500);
});

expect(ptor.findElement(protractor.By.binding('greeting')).getText()).
toEqual('Hiya');
}, 5000); // The 5000 here sets the Jasmine spec timeout.

it('should fail normally', function() {
expect(false).toEqual(true);
});

it('should pass - tests in the middle should be unaffected', function() {
expect(true).toEqual(true);
});

it('should timeout due to Jasmine spec timeout', function() {
ptor.driver.sleep(1000);
expect(true).toBe(true);
});

it('should pass - previous timeouts should not affect this', function() {
expect(true).toEqual(true);
});
});
40 changes: 40 additions & 0 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,43 @@ global.expect = function(actual) {
return originalExpect(actual);
}
};

/**
* A Jasmine reporter which does nothing but execute the input function
* on a timeout failure.
*/
var OnTimeoutReporter = function(fn) {
this.callback = fn;
};

OnTimeoutReporter.prototype.reportRunnerStarting = function() {};
OnTimeoutReporter.prototype.reportRunnerResults = function() {};
OnTimeoutReporter.prototype.reportSuiteResults = function() {};
OnTimeoutReporter.prototype.reportSpecStarting = function() {};
OnTimeoutReporter.prototype.reportSpecResults = function(spec) {
if (!spec.results().passed()) {
var result = spec.results();
var failureItem = null;

var items_length = result.getItems().length;
for (var i = 0; i < items_length; i++) {
if (result.getItems()[i].passed_ === false) {
failureItem = result.getItems()[i];

if (failureItem.toString().match(/timeout/)) {
this.callback();
}
}
}
}
};
OnTimeoutReporter.prototype.log = function() {};

// On timeout, the flow should be reset. This will prevent webdriver tasks
// from overflowing into the next test and causing it to fail or timeout
// as well. This is done in the reporter instead of an afterEach block
// to ensure that it runs after any afterEach() blocks with webdriver tasks
// get to complete first.
jasmine.getEnv().addReporter(new OnTimeoutReporter(function() {
flow.reset();
}));
6 changes: 5 additions & 1 deletion jasminewd/spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ describe('webdriverJS Jasmine adapter', function() {
// }, 200);

// it('should timeout after 300ms', function() {
// fakeDriver.sleep(999);
// fakeDriver.sleep(9999);
// expect(fakeDriver.getValueB()).toEqual('b');
// }, 300);

it('should pass after the timed out tests', function() {
expect(true).toEqual(true);
});
});
18 changes: 9 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ var startJasmineTests = function() {
driver.manage().timeouts().setScriptTimeout(100000);
driver.getSession().then(function(session) {
id = session.id;
});

protractor.setInstance(protractor.wrapDriver(driver, config.baseUrl));
protractor.setInstance(protractor.wrapDriver(driver, config.baseUrl));

// Export protractor to the global namespace to be used in tests.
global.protractor = protractor;
// Export protractor to the global namespace to be used in tests.
global.protractor = protractor;

// Set up the Jasmine WebDriver Adapter
require('../jasminewd');
// Set up the Jasmine WebDriver Adapter
require('../jasminewd');

var options = config.jasmineNodeOpts;
options.onComplete = cleanUp;
var options = config.jasmineNodeOpts;
options.onComplete = cleanUp;

minijn.executeSpecs(options);
minijn.executeSpecs(options);
});
}

if (!args.length) {
Expand Down

0 comments on commit 08ef244

Please sign in to comment.