Ajax – QTP Web extensibilty toolkit and ajax

ajaxqtp

I'm trying to test using QTP a web app that is using ajax4jsf to implement the ajax features.
QTP doesn't have the ability to recognize when the ajax had finished.
I've read that the web extensibility toolkit that is provided with QTP 9.5 and QTP 10 is the solution for my problem.
However, I can't understand how this can help me: I need to know the ready state of the httpRequest object and continue the test when the state is 'complete'. But I don't know how to reach the httpRequest from the web extensibility toolkit.
Any help would be appreciated.

Best Answer

Thank you for your answers.

We did manage to solve our problem using the QTP Extensibilty toolkit: A4j uses a queue of listeners that are awaken before and after ajax (Depending on the type of the listener). In our solution, we implemented a Jscript function for each ajax component (e.g webButton):
1. Initialize a globalVariable to 0
2. registers a new function as a listener of type onafterajax:

_elem.ownerDocument.parentWindow.A4J.AJAX.AddListener({
        onafterajax: function(req, event, data) {
            globalVariable = 1;
        }
    });
  1. Click the button
  2. Go into a sort of busy-waiting loop:

    while (globalVariable != 1) {   
        _util.Wait(250);
    }
    

The function we registered is called when the ajax is finished and changes the globalVariable so the while loop will exit. I know this is ugly, but it works great.

Our only problem is that QTP 10 implements the _util.wait while QTP 9.5 doesn't. Without the wait, the browser will be stuck in an infinite loop and the registered function will never be called. Any solution regarding the implementation of a non busy-waiting wait in Jscript would be most appreciated.