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)

2 Response to "Load actions dynamically in QTP 10 using LoadAndRunAction"

  1. Mark says:
    March 15, 2011 at 10:59 PM

    LoadAndRunAction statement is used with conditional statements. This means that actions inside your conditional statements will be loaded to your test ONLY IF your conditional statements were evaluated as TRUE. On the other hand, if your conditional statements were evaluated as FALSE, the action will not be loaded compared to your example above (no conditional statements were used).

    LoadAndRunAction must never be used the same way you showed in your example above, which ultimately defeats the purpose of "dynamically" loading Actions to your test.

  2. Reju George says:
    March 16, 2011 at 5:44 AM

    I would not completely agree on "LoadAndRunAction statement is used with conditional statements.". There are several instances where you dont need to be conditional but that depends on a couple of factors. However the example shown above was just to show the performance impact of this statement so that someone can easily decide how it can cause an impact and then make proper decisions. However this statement is a good feature and does help in certain places.

    Thanks,
    George, Reju

Post a Comment

Visitors

Website Counter