Timeouts

Because WebDriver tests are asynchronous and involve many components, there are several reasons why a timeout could occur in a Protractor test.

Timeouts from Protractor

Waiting for Page to Load

When navigating to a new page using browser.get, Protractor waits for the page to be loaded and the new URL to appear before continuing.

  • Looks like: an error in your test results - Error: Timed out waiting for page to load after 10000ms
  • Default timeout: 10 seconds
  • How to change: To change globally, add getPageTimeout: timeout_in_millis to your Protractor configuration file. For an individual call to get, pass an additional parameter: browser.get(address, timeout_in_millis)

Waiting for Angular

Before performing any action, Protractor waits until there are no pending asynchronous tasks in your Angular application. This means that all timeouts and http requests are finished.

  • Looks like: an error in your test results - Timed out waiting for asynchronous Angular tasks to finish after 11 seconds.
  • Default timeout: 11 seconds
  • How to change: Add allScriptsTimeout: timeout_in_millis to your Protractor configuration file.

You may also need to fix this problem with a change to your application.

AngularJS If your AngularJS application continuously polls $timeout or $http, Protractor will wait indefinitely and time out. You should use the $interval for anything that polls continuously (introduced in Angular 1.2rc3).

Angular For Angular apps, Protractor will wait until the Angular Zone stabilizes. This means long running async operations will block your test from continuing. To work around this, run these tasks outside the Angular zone.

For example:


this.ngZone.runOutsideAngular(() => {
  setTimeout(() => {
    // Changes here will not propagate into your view.
    this.ngZone.run(() => {
      // Run inside the ngZone to trigger change detection.
    });
  }, REALLY_LONG_DELAY);
});			


As an alternative to either of these options, you could disable waiting for Angular, see below.

Waiting for Angular on Page Load

Protractor waits for the angular variable to be present when loading a new page.

  • Looks like: an error in your test results - Angular could not be found on the page: retries looking for angular exceeded
  • Default timeout: 10 seconds
  • How to change: To change globally, add getPageTimeout: timeout_in_millis to your Protractor configuration file. For an individual call to get, pass an additional parameter: browser.get(address, timeout_in_millis)

How to disable waiting for Angular

If you need to navigate to a page which does not use Angular, you can turn off waiting for Angular by setting browser.waitForAngularEnabled(false)


browser.waitForAngularEnabled(false);
browser.get('/non-angular-login-page.html');

element(by.id('username')).sendKeys('Jane');
element(by.id('password')).sendKeys('1234');
element(by.id('clickme')).click();

browser.waitForAngularEnabled(true);
browser.get('/page-containing-angular.html');			

Timeouts from WebDriver

Asynchronous Script Timeout

Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.

  • Looks like: an error in your test results - ScriptTimeoutError: asynchronous script timeout: result was not received in 11 seconds
  • Default timeout: 11 seconds
  • How to change: Add allScriptsTimeout: timeout_in_millis to your Protractor configuration file.

Logging in Protractor using Winston

Timeouts from Jasmine

Spec Timeout :

If a spec (an 'it' block) takes longer than the Jasmine timeout for any reason, it will fail.

  • Looks like: a failure in your test results - timeout: timed out after 30000 msec waiting for spec to complete
  • Default timeout: 30 seconds
  • How to change: To change for all specs, add jasmineNodeOpts: {defaultTimeoutInterval: timeout_in_millis} to your Protractor configuration file. To change for one individual spec, pass a third parameter to it: it(description, testFn, timeout_in_millis).

Protractor Interview Questions

 
Join My Facebook Group
Join Group
 

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech