Hi guys, I asked the following on the webdriver forum: https://groups.google.com/d/topic/webdriver/5WdDJsiyAzc/discussion Kristian mailed me the following below which I find interesting. WDYT? Since I'm not know a prototype expert could someone knowledgable tell me if this can be done? (I've found http://www.prototypejs.org/api/ajax/responders but not sure if it's enough for us). Thanks -Vincent Begin forwarded message:
From: krosenvold <[email protected]> Date: June 9, 2011 8:56:20 PM GMT+02:00 To: Vincent Massol <[email protected]> Subject: Re: Re : Re: How to know if a page has been reloaded after some ajax refresh
I have generally solved this problem by instrumenting the application javascript ever so slightly, by exploiting the following known facts:
Any immediate code executed by "onClick" handlers is guaranteed to be finished before control is returned to the client code.
Most popular frameworks allow you to add a global hook that allows you to increment a counter for every request that is started. If you add one hook that increments on start and one that increments on ajax request termination, your test can basically wait for a given javascript variable to become 0.
The nice thing about this is that if you do fancy visuals (sliding or fading stuff that you actually intend to click in your tests), you can intercept "onEffectStart" and "onEffectEnd" and increment/decrement the same counter.
And if you chain this properly, you can have a client-side added "onComplete" ajax handler that starts a sliding visual effect and the counter will be guaranteed to not reach 0 before the effect is finished.
So our page object base class has a waitForAllEffectsToFinish method that we actually surround to all calls to click. Our tests went to flaky to 100% rock solid after we did this.
Btw, you must use a counter - this won't work well enough with a boolean.
Kristian