How to implement intervals / polls in angular2 to work with a protractor?

I have an angular2 application that I want to test with a protractor.

In this application, I have a page with a graph that is regularly updated with auto-generated data.

Apparently, one protractor feature is waiting for scripts and http calls to complete before the test code is executed. However, if there is a constant polling script that never ends, the protractor will wait forever and time out after a certain time.

In angular1, this can be solved by performing a survey with $interval , which does not reach the protractor. Unfortunately, angular2 doesn't have $interval , and the correct way to do the polling seems to be Observable.interval , so it looks like my code:

 Observable.interval(500) .map(x => this.getRandomData()) .subscribe(data => this.updateGraph(data)); 

When testing the page on which this code works, the protractor will be disabled. He expects the page to finish loading, and thinks that this script will come out someday (when it actually works forever).

  • Is there an interval mechanism in angular2 that protractor recognizes so that it does not wait for polling to complete before running user interface tests?

  • If not, how can I say that the protractor did not wait for this interval to complete before executing the larger test code?

EDIT: To clarify, a timeout problem already existed in the transporter with angular1, but can be fixed with $interval , see

This does not work in angular2 because there is no $interval .

+5
source share
2 answers

After some research, I found two possible solutions:

  • browser.ignoreSynchronization = true instructs the protractor to stop waiting for http calls and interval scripts. However, this is likely to make recording e2e tests much more difficult, because now you need to manually wait for the elements and pages to load before testing them.
  • protranslator-xhr-only plugin basically does the same thing as ignoreSynchronization , but only for interval scripts. The protractor will still wait for the completion of the $http calls.

Neither one is the perfect solution, but better than nothing.

+2
source

https://github.com/angular/protractor/issues/3349#issuecomment-232253059

solved this problem with juliemr:

 this.ngZone.runOutsideAngular(() => { this.timer = Observable.interval(1000) } 

execute a timeout outside the zone, then the protractor will not wait for it.

0
source

Source: https://habr.com/ru/post/1246242/


All Articles