question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically set allScriptsTimeout from an it block

See original GitHub issue

Feature request: Dynamically set allScriptsTimeout from an it block.

Motivation: Suppose uploading a large file to a website takes 3-5min. If I have allScriptsTimeout set to 30s, Protractor will timeout automatically (due to the POST request taking longer than 30s). I prefer to keep allScriptsTimeout relatively small (e.g., 30s) for all the other tests, and it would not be appropriate to increase the global timeout.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
wswebcreationcommented, Sep 22, 2017

@mwsessom

Sorry, I had the wrong script. If your run this you will see it works. Mind the comment in the first it-block at the end

config

exports.config = {
    capabilities: {
        'browserName': 'chrome'
    },
    framework: 'jasmine',
    specs: ['example_spec.js'],
    allScriptsTimeout: 9000
};

example test

describe('Wait a long time', () => {
    it('wait 60000 for a async response', () => {
        let start;

        // Override the default / set allScriptsTimeout
        browser.driver.manage().timeouts().setScriptTimeout(60000);
        browser.get('http://www.angularjs.org').then(() =>{
            start = new Date().getTime();
        });
        browser.executeAsyncScript('window.setTimeout(arguments[arguments.length - 1], 50000);')
            .then(() => {
                console.log('Elapsed time: ' + (new Date().getTime() - start) + ' ms');
            });

        expect(true).toBe(true);
        // Add the 70000 to the it block, or in your protractor conf (jasmineNodeOpts.defaultTimeoutInterval)
        // to not face the jasmine.DEFAULT_TIMEOUT_INTERVAL that is defaulted to 30 seconds if you don't set it
    }, 70000);

    it('wait 10 seconds for an async response, but fail', () => {
        let start;

        // Override the default / set allScriptsTimeout
        browser.driver.manage().timeouts().setScriptTimeout(10000);
        browser.get('http://www.angularjs.org').then(() =>{
            start = new Date().getTime();
        });
        browser.executeAsyncScript('window.setTimeout(arguments[arguments.length - 1], 60000);')
            .then(() => {
                console.log('Elapsed time: ' + (new Date().getTime() - start) + ' ms');
            });

        expect(true).toBe(true);
    });
});

output

✘  ~/contributions/protractor   examples ●  npm run test.example

> protractor@5.1.2 test.example /Users/wswebcreation/contributions/protractor
> node ./bin/protractor example/conf.js

[05:51:44] I/launcher - Running 1 instances of WebDriver
[05:51:44] I/hosted - Using the selenium server at http://localhost:4444/wd/hub/
Started
Elapsed time: 50265 ms
.FA Jasmine spec timed out. Resetting the WebDriver Control Flow.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.


Failures:
1) Wait a long time wait 10 seconds for an async response, but fail
  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:386:14)
        at tryOnTimeout (timers.js:250:5)
        at Timer.listOnTimeout (timers.js:214:5)
  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:386:14)
        at tryOnTimeout (timers.js:250:5)
        at Timer.listOnTimeout (timers.js:214:5)

2 specs, 1 failure
Finished in 112.808 seconds

[05:53:39] I/launcher - 0 instance(s) of WebDriver still running
[05:53:39] I/launcher - chrome #01 failed 1 test(s)
[05:53:39] I/launcher - overall: 1 failed spec(s)
[05:53:39] E/launcher - Process exited with error code 1

I’m going to close the issue now based on the above testcase. You are able to influence it from the it-block. It’s still open for discussion

3reactions
mwsessomcommented, Mar 27, 2017

jasmine.DEFAULT_TIMEOUT_INTERVAL is different than allScriptsTimeout.

jasmine.DEFAULT_TIMEOUT_INTERVAL is specific to Jasmine. allScriptsTimeout is specific to Protractor.

jasmine.DEFAULT_TIMEOUT_INTERVAL refers to the total time to run a single test. allScriptsTimeout refers to the time to wait for a single async request.

You can view the documentation here http://www.protractortest.org/#/timeouts

Read more comments on GitHub >

github_iconTop Results From Across the Web

set timeouts dynamically - javascript - Stack Overflow
It seems that you've multiple elements with the same class, you can just use their index to create a dynamic array of timers....
Read more >
Timeouts - Protractor - end-to-end testing for AngularJS
Looks like: an error in your test results - Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. Default timeout:...
Read more >
Getting Started for Selenium E2E Testing using Protractor
To setup the Protractor with ChromeDriver, set the directConnect property to true in configuration as in the following code block.
Read more >
Is it possible to use AngularJS in a Dynamic block...
Hi everyone, I got a question for the Community about Angular in ServiceNow. I got it that you can create UI Pages or...
Read more >
Protractor Tutorial: Handling Timeouts With Selenium
overriding default value of allScriptsTimeout parameter for ... The test specification i.e. the 'it block' of the Protractor testing case ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found