Search code examples
javascriptunit-testingjasmineprotractortimeout

How to enforce the default timeout interval in Jasmine?


I am trying to set a timeout for my automation script using protactor and jasmine. I have set the default jasmine timeout to 5 seconds. jasmineNodeOpts: { defaultTimeoutInterval: 5000, } When I try to test the 5 second timeout, the script runs for 20 seconds in total, even after the spec has timed out. So basically it keeps executing until it times out 4 times.

This is my terminal -

A Jasmine spec timed out. Resetting the WebDriver Control Flow.

A Jasmine spec timed out. Resetting the WebDriver Control Flow.

A Jasmine spec timed out. Resetting the WebDriver Control Flow.

A Jasmine spec timed out. Resetting the WebDriver Control Flow.

Failures: 1) Timeout issue debugger Set timeout and see if it exceeds

Message: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Stack: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10)

Message: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Stack: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10)

Message: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Stack: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10)

Message: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. Stack: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10)

This is how I am testing it -

describe('Timeout issue debugger', () => {
  afterEach(done => {
    helper.reportTestRails().then(function() {
      done();
    });
  });

  afterEach(() => {
    helper.updateResults();
  });

  it('Set timeout and see if it exceeds and works properly', async () => {
    browser.sleep(30000);
  });
)};

I will appreciate any suggestions or solutions.


Solution

  • I would suggest to not mix protractor control flow and async/await together. This cases horrible bugs like yours. Also Control flow is deprecated and already removed from v6.x

    I suggest: 1) Set SELENIUM_PROMISE_MANAGER: false in your protactor config file 2) Use await everywhere: Prepend all async commands with await:

    describe('Timeout issue debugger', function () {
      afterEach(async function () {
        await helper.reportTestRails();
        await helper.updateResults();
      });
    
      it('Set timeout and see if it exceeds and works properly', async function () {
        await browser.sleep(10000);
      });
    )};
    

    http://www.protractortest.org/#/async-await