tags:

views:

1216

answers:

4

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.

+2  A: 

Hi Eldad,

Based on my experience of automating tests for a web-based application with AJAX calls I suggest you to consider the following.

  1. QTP's Object Recognition mechanism is looking for GUI objects with Windows Handle. So whenever possible, use GUI objects only. Testing manually you won't reach XmlHttpRequest object either but it wouldn't prevent you from functional testing. You can still synchronize on a variety of events based on the change of properties of GUI objects. For example. "loading..." image or text appeared/disappeared. Dropdown list stopped adding new items. Button becomes enabled/disabled.

  2. If this is your in-house application you can develop a more friendly support for QTP, and here you can use guides from extensibility toolkit. Additionally, as a test build option you may include a GUI object (invisible image or text element) and use it to indicate states of AJAX transactions.

  3. Finally, you can still access DOM directly to reach non-GUI objects although I don't have information on using XmlHttpRequest object this way.

Thank you, Albert Gareev

Albert Gareev
A: 

Hi Eldad,

I hope you'll find the following article handy.

Synchronization for AJAX Applications http://relevantcodes.blogspot.com/2009/06/synchronization-for-ajax-applications.html

Thank you, Albert Gareev

Albert Gareev
+2  A: 

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.

Eldad
A: 

Hi Eldad,

You problem and solution sounds like what i've been searching for.

I haven't used the web extensibility before.

Is there any chance you can attach the files you used?

Any help is much appreciated...

Cheers,

phareds