QTP Web extensibilty toolkit and ajax

回眸只為那壹抹淺笑 提交于 2019-12-22 07:59:57

问题


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.


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/1199534/qtp-web-extensibilty-toolkit-and-ajax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!