Integration Tests Richfaces 4 AJAX and e.g. Selenium (Requirement)
jbosscommunity13 Jul 24, 2012 6:27 AMHello Richfaces Community,
I have a requirement and in case there is already an implemented solution, a question.
"How can I hook into tha a4j cycle on the client side (browser) in a generic way to know if there is an active ajax call pending?"
We do a lot of browser integration testing with Selenium. Those who know selenium know that when you run the scripts in a certain speed you do get problems with ajax Calls,
because you can not always detect them for sure. (Waiting for an element present is also not always a solution, because after certain ajax calls no change might happen too!)
So I studied the internet for solutions, some seem to be very promising.
Hidden Field Solution
Like:
<h:inputHidden id="ajaxRequestStatus" value="AJAX_REQUEST_INACTIVE"/>
on every ajax component a jsFunctionCall to change the value in the hidden field
[...]
<a4j:ajax event="change" onbeforesubmit="setHiddenAjaxFieldActive()" oncomplete="setHiddenAjaxFieldInactive()" ...
[...]
like this, in Selenium you can now use the command "waitForCondition" which loops as long as a javaScriptFunction becomes true (e.g. the hidden field has the value "AJAX_REQUEST_INACTIVE") or of course when it reaches the given timeout.
That solution works 100%, but it requires that all (every single) ajax component need to implement this 2 methods....
In Selenium many User try to get over the browserbot to find out if there is an active ajax Call
selenium.browserbot.getCurrentWindow().jQuery.active == 0
This doenst work very reliable unfortunately!
------------------------------------------------------------------------------------------------------
So my question:
Is there a solution for this requirement?
The Richfaces Ajax-Status Component e.g. is a Component that is already aware of when the cycle is over... so the information must be known
by an the clientside Object. The ajax Queue Object ist also not usabel for it, because it doens hold the information if one element left the queue is already worked off...
it would be nice to have access something like in this Fashion:
RichFaces.getNumberOfActiveAjaxCalls()
I tried to find out in runtime if any of the accesible methods in the RichFaces Js Object could be helpful but I couldn't locate any.
Is this a candidate for future releases, to make the number of acrtive ajax calls accesible through the RichFaces Object?
Could it Integrate with JSF 2 Ajax calls?
It would be a very helpful benefit for testability of web applications.
For any hints, suggestions and comments, very apreciated!