diff --git a/debugging/conf.js b/debugging/failure_conf.js similarity index 100% rename from debugging/conf.js rename to debugging/failure_conf.js diff --git a/debugging/timeout_conf.js b/debugging/timeout_conf.js new file mode 100644 index 000000000..17b82e1d7 --- /dev/null +++ b/debugging/timeout_conf.js @@ -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 + } +}; diff --git a/debugging/timeout_spec.js b/debugging/timeout_spec.js new file mode 100644 index 000000000..f0a9cd358 --- /dev/null +++ b/debugging/timeout_spec.js @@ -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); + }); +}); diff --git a/jasminewd/index.js b/jasminewd/index.js index 2d1ed581f..f0ddaefcf 100644 --- a/jasminewd/index.js +++ b/jasminewd/index.js @@ -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(); +})); diff --git a/jasminewd/spec/adapterSpec.js b/jasminewd/spec/adapterSpec.js index b3ce20a3a..582f8a29d 100644 --- a/jasminewd/spec/adapterSpec.js +++ b/jasminewd/spec/adapterSpec.js @@ -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); + }); }); diff --git a/lib/cli.js b/lib/cli.js index 8b7976ead..d91fd0c9f 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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) {