Selenium - Wait for network traffic

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2010-11-05T22:20:25Z Indexed on 2012/06/20 21:16 UTC
Read the original article Hit count: 160

Filed under:
|
|

We're using Selenium with the Java API and some Javascript user extensions. We use a lot of AJAX calls in our app. A lot of our tests fail randomly because sometimes the AJAX calls finish slower than other times so the page isn't fully loaded. We fix that by waiting for specific elements or Thread.sleep. I was trying to find a way to instead just wait for the network traffic to finish. So that we could do this:

selenium.click("some JS button");
selenium.waitForNetwork();
assertTrue(something);

That way we can get rid of the thread sleep and have tests pass faster when the server responds faster and not have so many tests fail due to timing issues.

I haven't been able to find a way to do this searching Google. Does anyone have any ideas how we can accomplish this? (Preferably either through Javascript or the Java API but all suggestions are welcome).

Note: the other variations of "waitFor" are not what I'm looking for. We're already using those in clicks and other things. I'm looking for something that waits for the NETWORK TRAFFIC. Thanks for all the feedback, I'll be trying out a couple of the suggestions, but I'm still open to other ideas.

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about networking