问题
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