admin管理员组文章数量:1405628
I have an angular2 app I want to test with protractor.
In this app I have a page with a graph that is being updated in regular intervals with autogenerated data.
Apparently one feature of protractor is waiting for scripts and http calls to finish before executing test code. However, if there is a constantly polling script that never finishes, protractor will wait forever and time out after a certain time.
In angular1 this could be solved by implementing the polling with $interval
, which protractor does not wait for. Unfortunately in angular2 there is no $interval
and the correct way to implement polling seems to be Observable.interval
, so this is what my code looks like:
Observable.interval(500)
.map(x => this.getRandomData())
.subscribe(data => this.updateGraph(data));
When testing a page where this code is running, protractor will time out. It waits for the page to finish loading and thinks this script will exit sometime (when in fact it runs forever).
Is there an interval mechanism in angular2 that protractor recognizes, so that it doesn't wait for the polling to finish before running the UI tests?
If not, how can I tell protractor not to wait for this interval to finish before executing more test code?
EDIT: To clarify, the timeout problem already existed in protractor with angular1, but could be fixed by using $interval
, see:
- Timed out waiting for Protractor to synchronize with the page after 50001ms
- How to implement intervals in protractor/selenium
This doesn't work in angular2 because there is no $interval
.
I have an angular2 app I want to test with protractor.
In this app I have a page with a graph that is being updated in regular intervals with autogenerated data.
Apparently one feature of protractor is waiting for scripts and http calls to finish before executing test code. However, if there is a constantly polling script that never finishes, protractor will wait forever and time out after a certain time.
In angular1 this could be solved by implementing the polling with $interval
, which protractor does not wait for. Unfortunately in angular2 there is no $interval
and the correct way to implement polling seems to be Observable.interval
, so this is what my code looks like:
Observable.interval(500)
.map(x => this.getRandomData())
.subscribe(data => this.updateGraph(data));
When testing a page where this code is running, protractor will time out. It waits for the page to finish loading and thinks this script will exit sometime (when in fact it runs forever).
Is there an interval mechanism in angular2 that protractor recognizes, so that it doesn't wait for the polling to finish before running the UI tests?
If not, how can I tell protractor not to wait for this interval to finish before executing more test code?
EDIT: To clarify, the timeout problem already existed in protractor with angular1, but could be fixed by using $interval
, see:
- Timed out waiting for Protractor to synchronize with the page after 50001ms
- How to implement intervals in protractor/selenium
This doesn't work in angular2 because there is no $interval
.
- @close-voter: What part don't you understand? I will be happy to explain the problem further. – magnattic Commented Apr 1, 2016 at 16:00
- I copy/post your article to protractor issue: github./angular/protractor/issues/3349 . and did you get any better solution now? – Huan Commented Jul 11, 2016 at 3:20
2 Answers
Reset to default 4After some investigation, I found two possible solutions:
browser.ignoreSynchronization = true
instructs protractor to stop waiting for http calls and interval scripts. However, this will likely make writing e2e tests much harder, because now you have to manually wait for elements and pages to load before testing them.- The protractor-xhr-only plugin basically does the same thing as
ignoreSynchronization
, but only for interval scripts. Protractor will still wait for$http
calls to finish.
Neither of both are a perfect solution, but better than nothing.
https://github./angular/protractor/issues/3349#issuement-232253059
resolved this problem with help from juliemr:
this.ngZone.runOutsideAngular(() => {
this.timer = Observable.interval(1000)
}
run timeout out of zone, then protractor will not wait for it.
本文标签: javascriptHow to implement intervalspolling in angular2 to work with protractorStack Overflow
版权声明:本文标题:javascript - How to implement intervalspolling in angular2 to work with protractor? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744911991a2631974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论