Load actions dynamically in QTP 10 using LoadAndRunAction


So here we have a new feature in QTP 10. We can load actions dynamically at run time in QTP 10 instead of associating all the actions in the main test script. This is accomplished with the statement LoadAndRunAction, a new feature introduced in QTP 10.
But first of all, lets back up a little. Until version 9.5, you only had one option if you wanted to call external actions in a main action. Of course, you would have to use the RunAction statement but you also had to include the action in your script


Now QTP 10 provides the feature where you can avoid the insertion step by simply calling LoadAndRunAction and provide the test name and action name as mandatory arguments. You can optionally also pass the iteration and parameters arguments.

Looks good ... Ya sure.... but wait !!! There is a cost associated to this - the cost of performance !!! Yes... here is an example. I wrote 5 actions and called them Test1 through Test5. These actions had just one statement like Print "In ". So each action had Print "In Test1", Print "In Test2" etc...

Next, I created two main scripts. The first main script had all the 5 actions already loaded.


The second main action made use of the LoadAndRunAction statement and so did not have the actions loaded already.


Ok... so we are all ready now. I ran both these scripts multiple times just to get an average performance. So here is the result...
The script which already had the actions loaded took an average time of 0.6 seconds for the complete execution and each action took on an average 0.12 seconds to complete the individual execution.
The script which made use of the LoadAndRunAction statement took an average time of 1.2 seconds for the complete execution and each action took an average 0.24 seconds to complete the individual execution.
Understand that this is a very small script and we see that the script using LoadAndRunAction took double the time to execute when compared to the actions that were already loaded. Also the QTP documentation also clearly mentions this "Run performance can be affected because the action is loaded and run during the run session (and not when the test is opened)."
So my suggestion is use this statement only if you are absolutely sure that you do need it and you are not affecting the performance of your test.

Nonetheless, its always good to have new utilities.. you never know when you would need them !!!
I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (2)

QTP 10, Vista and IE8

If your question is whether QTP 10 supports IE8 on Vista, the answer is "Yes". At least, thats what HP QuickTest Professional 10.00 Patch QTPWEB_00037 Readme File says. The documentation also says
"This patch provides official support for testing Web applications in Internet Explorer 8.
It includes support for working with Internet Explorer 8 on all operating systems that QuickTest Professional supports."
QTP 10 supports Vista, so this also means that IE 8 on Vista is supported. However not everything looks rosy here because when I try to spy on IE8 in Vista....this is what I see..




QTP recognizes the browser as a Window object instead of Browser. Now this is not always the case. In some cases (for which I have no explanation) it does recognize IE8 as a Browser object. So I would be reluctant in stating that QTP 10 supports IE8 on Vista "completely" !!!!!

All that said and done, let me get into the reason why I wanted to write this article. I had got stuck with a problem where I wanted to activate a browser. I am sure you would also have known by this time that you activate a browser by getting the handle of the browser and then do a Window("hwnd:=" & hwnd).Activate. Well, lets try it here...but before that we have a sort of chicken and egg problem here... if we are unable to recognize the browser then how do we get its handle !!! One way is to use the object spy on the browser and get the handle... the other way is by knowing that the regexpwndtitle property of such a window would be "Windows Internet Explorer" and nativeclass property would be "IEFrame" and another way would be to use Description objects. Lets use the properties here ..

wHandle = Window("regexpwndtitle:=Windows Internet Explorer", "nativeclass:=IEFrame").GetROProperty("hwnd")
Window("hwnd:=" & wHandle).Activate
There you go ... it worked !!!
Just make sure that if your browser is in "Full Screen" mode, the Activate method would not work so make use of the "Click" method instead of Activate.
I hope this saved you time "googling" further for this problem and you got a resolution.

Update: Oh boy !!! Why didn't I know this earlier ?? Just figured out why IE8 was not being recognized as a browser in Vista. I usually work on Vista as a standard user and have my UAC (User Access Control) set to "ON". This is because it gives an added security and gives you more control over unauthorized access on your system. For some reason, I had to uncheck the UAC option. Of course, you can do this only as a user with administrative privileges. And Voila .... QTP started to recognize IE 8 as a browser with absolutely no problems. Now is this problem only on IE8. Not really !! I downgraded my IE8 to IE7 but still it was being recognized as a Window. So all this while, UAC was the culprit. OK...so things are resolved, but I would want to test on Vista with the UAC set to ON !! H-m-m... will investigate further and let you know if there is any solution.

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (5)

Visitors

Website Counter