0

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?

plus-
  • 45,453
  • 15
  • 60
  • 73

1 Answers1

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.

Ludwig Magnusson
  • 13,964
  • 10
  • 38
  • 53
  • wow that's unexpected, I had to add those sleep in the past to have e2e tests pass. I'll double check. And yes I'm using solely angular. Thanks – plus- Oct 29 '13 at 20:54
  • so it appears I was using direct `document.location.href` change which is not handled by karma. For the rest it works out of the box. – plus- Dec 02 '13 at 13:20