Karma e2e testing: how to know when the DOM is ready?

五迷三道 提交于 2020-01-06 07:17:07

问题


I'm writing some e2e tests and up until now I have been using the sleep(x) function to wait for ajax calls.

This is not very efficient as I must estimate the value to wait for testing and if I set too big a value then my tests are taking much more time then needed.

Is there a way to sleep for an ajax call duration? or at least when redirecting to a different page a way to sleep for the time the DOM is loaded?


回答1:


If you do e2e testing with angular scenario runner and karma you do not need to worry about this. The framework handels all this for you. If you have a button that will cause your application to send an AJAX request and on response change something in the DOM, you can simply write your test like this:

element('#mybutton').click();
expect('...'); //Test that checks that the DOM has changed as excpected.

As long as you use angular full out, this will work.



来源:https://stackoverflow.com/questions/19633549/karma-e2e-testing-how-to-know-when-the-dom-is-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!