Search code examples
angularjsjasminetimeoutprotractorappium

Can the time out issue be the consequence of browser.sleep() and browser.waitForAngular?


In protractor scripts i'm always having problem of time out, even if i put a big time out jasmine interval, allscripttimeout... And in some places i'm obliged to wait until element are present like in home page until the url is totally loaded.

Can the time out issue be the consequence of

  • browser.sleep(time_ms);
  • browser.waitForAngular();

If so, how can i fix this problem ?

Here the problem in details

Thanks,


Solution

  • Yes they could be -- browser.sleep() would only timeout if you had it sleep longer than your Jasmine timeout interval (default is 30 seconds).

    browser.waitForAngular() is automatically applied to every webDriver action by Protractor so you shouldn't need to call it. If this time's out then your app is still synchronizing something.

    Both of these would result in A Jasmine spec timed out. Resetting the WebDriver Control Flow. following by Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. if it takes too long.

    I'm not positive how you would fix it - you've had a lot of questions about timeouts (for good reason), but at this point I think you need to use browser.ignoreSynchronization = true; and treat your app as non-Angular if you're having this many timeout issues. Something is preventing synchronization from finishing.

    There are several helper methods that you can create and execute seamlessly on non-Angular apps by extending Protractor's functions to avoid explicit browser.sleep()'s . For example, the below code pauses test execution until isPresent returns true (or until a failure by exceeding the timeout I specified)

    Util.prototype.waitForElementPresent = function (el, time) {
        var timeout = time || 0,
    
        return browser.wait(function() {
            return el.isPresent();
        }, timeout)
    };