17

I would like to end-to-end test our angular 2 application using Protractor, but I'm stuck with the message:

"Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds."

My conf file.

exports.config = {
  directConnect: true,
  specs: ['spec.js'],

  // For angular2 tests
  useAllAngular2AppRoots: true,
}

Chrome is opened, and the website is also opened, then nothing happens till the the timeout.

When disabling the synchronisation (using browser.ignoreSynchronization = true; ), it's OK. But I'm loosing the "automatic waiting" feature, one of the main advantages of using Protractor.

The application is fully based on angular 2. So why this does not work?

Our developers told me that we are not polling (one of the possible cause according Protractor documentation). By the way, we are using websocket architecture. I don't know if there's a link.

Actually, I don't know how to troubleshoot this issue at all.

Could someone help, please?

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Tibeben
  • 181
  • 1
  • 5

3 Answers3

6

Your guess is right. This error would occur when their are any outstanding tasks running in your angular2 application.

Yes, the most common reason is when application continuously polls $timeout or $http, Protractor will wait indefinitely and time out. But this can also occur in scenarios where App takes more than 11 seconds

Please refer here for more information on different timeouts

the default timeout value is 11 seconds. You can change this by adjusting the below value in config.js and try and see if you are still seeing the issue

  /**
   * The timeout in milliseconds for each script run on the browser. This
   * should be longer than the maximum time your application needs to
   * stabilize between tasks.
   */
  allScriptsTimeout?: number;
AdityaReddy
  • 3,625
  • 12
  • 25
5

Temporarily enabling browser.ignoreSynchronization fixes it, as reported in an answer here.

browser.ignoreSynchronization = true;

(code that throws the error)

browser.ignoreSynchronization = false;
emery
  • 8,603
  • 10
  • 44
  • 51
  • thanks for sharing. My problem arise after oauth work flow is integrated. It has puzzled me for a couple of days. After applying your fix, my BDD tests started to work as usual. – chfw May 29 '18 at 11:13
  • Note that this is deprecated in favour of `waitForAngularEnabled` – Pieter De Bie Aug 01 '18 at 11:54
2

Modify the test case and put browser.waitForAngularEnabled(false); after the first click, should work.

However, recommended method can be overriding the default timeout in your conf.js file as allScriptsTimeout: 110000

Saikat
  • 14,222
  • 20
  • 104
  • 125