protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Strange behaviour when a jasmine spec timeouts

Open lynchblue opened this issue 11 years ago • 1 comments

I've been experiencing protractor strange behaviours when one spec timeouts. Specially when we have a beforeEach.

I have realized that:

  1. After one 'it' timeouts, the following beforeEach will be ignored.
  2. There is a sort of cascade effect that makes following specs also to timeout.

Code Example

protractor.conf.js

const DEFAULT_TIMEOUT_INTERVAL = 1000; 

exports.config = {
    seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.47.1.jar',
    seleniumPort: 4455,

    suites: {
        'basic': 'spec.js'
    },

    capabilities: {
        'browserName': 'firefox'
    },

    framework: 'jasmine2',

    jasmineNodeOpts: {
        defaultTimeoutInterval: DEFAULT_TIMEOUT_INTERVAL,

    },

    onPrepare: function () {

    }

};

We set the timeout (defaultTimeoutInterval) to one second.

spec.js

describe('Testing domino effect (strange behavior) when Timeout', function () {

    beforeEach(function () {
        console.log('before spec finished!\n');
    });

    afterEach(function () {
        console.log('after spec finished!\n');
    });

    it('Test 1', function () {
        expect(1).toBe(1);
    });

    it('Test 2', function () {
        browser.get('http://www.protractortest.org/#/');
        browser.sleep(2000);
        expect(1).toBe(1);

    });

    it('Test 3', function () {
        expect(1).toBe(1);
    });

    it('Test 4', function () {
        expect(1).toBe(1);
    });

});

And we force the spec Test 2 to timeout by adding a 2 seconds sleep.

Given these tests the only test that should fail would be Test 2. However Test2, Test3 and Test4 will fail. The output after running the tests is the following:

Console Output

Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.4.105:4455/wd/hub
Started
before spec finished!

after spec finished!

.before spec finished!

after spec finished!

A Jasmine spec timed out. Resetting the WebDriver Control Flow.
Fafter spec finished!

A Jasmine spec timed out. Resetting the WebDriver Control Flow.
Fafter spec finished!

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

Failures:
1) Testing domino effect in Timeout strange behavior Test 2
  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.

2) Testing domino effect in Timeout strange behavior Test 3
  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.

3) Testing domino effect in Timeout strange behavior Test 4
  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.

4 specs, 3 failures
Finished in 3.029 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] firefox #1 failed 3 test(s)
[launcher] overall: 3 failed spec(s)
[launcher] Process exited with error code 1

Protractor version: 2.5.1 Jasmine version: 2.3.2

I have a created a Gist so it is easier to reproduce the behaviour:

https://gist.github.com/lynchblue/1dd1f5d53a781ac1bce4

lynchblue avatar Nov 04 '15 08:11 lynchblue

This is a duplicate of https://github.com/angular/protractor/issues/1797

Thanks for the gist and the detailed report, it should make investigating easier.

juliemr avatar Nov 10 '15 19:11 juliemr