How to Use LoadAndRunAction in UFT

In my previous article Actions in UFT with Examples, we have seen how to call a required action in a Test using RunAction method. Having said that, RunAction method has a limitation and it can not be called inside a user-defined function.

In this article, I will show you another way to load action in UFT be it an action or a test, or a function. We do have a built-in method LoadAndRunAction in UFT to load and run a required action whenever required. LoadAndRunAction in UFT is used to load the desired action at runtime within an action of a Test as well as in a Function.

LoadAndRunAction method can be used inside a user-defined function as well as inside an action.

LoadAndRunAction in UFT

We can use the LoadAndRunAction function when we do not want to call too many actions in the actual test, or when we are not sure which action is going to be called. For example, you may use conditional statements that call external actions, and you do not want to load actions each time you open the test, since these actions may not be necessary during the run session.

LoadAndRunAction method is mostly used in the automation framework wherein individual scripts are invoked through the driver script.

Syntax
LoadAndRunAction(TestPath, ActionName, [Iteration], [Parameters])

Argument Type Description
TestPath Variant The path of the test containing the action. You can specify an absolute file system path, an ALM path, or a relative path.
ActionName Variant The name of the action.
Iteration Variant Optional.

— oneIteration or 0 (Default)—Runs the action only once, using the row in the action’s data sheet that corresponds to the global data sheet iteration counter.

If the action’s data sheet contains fewer rows than the global sheet, the last row of the action’s data sheet will be used for each subsequent iteration.

— allIterations or 1—Runs iterations on all rows.

— iteration row range (for example, “1-7”)—Indicates the rows for which action iterations will be performed

Parameters Variant Optional.
Accepts both Input and Output parameters. Input parameters are listed before output parameters.

LoadAndRunAction in UFT Example

Suppose you have already created a Flight Booking action inside a Test and you want to Load and Run this Action after doing log-in to the application inside another Test. The following is an example of using LoadAndRunAction inside of the actions of a Test.

LoadAndRunAction Having Input-Output Parameters

Suppose you want to Load and Run an action that has two input parameters and one output parameter. The following would be the syntax of LoadAndRunAction of an action having input and output parameters.

Important Points Regarding LoadAndRunAction

When we use the LoadAndRunAction statement at any step, the action is loaded only when the particular step runs (and not when the test opens). Hence, the action is not listed in the following (except during the run session):
  • The Solution Explorer pane in UFT.
  • The Canvas in UFT.
  • The Errors pane in UFT.
At the end of a run session, all of the actions that were dynamically loaded are unloaded. In the Run Results window, you can view the steps that ran during the run session.
 
Calling an external action from a function library using the RunAction statement results in a run-time error. So you can use the LoadAndRunAction statement rather than RunAction statement.
 

Conclusion

In this article, we have learned how to use the LoadAndRunAction statement in UFT. This statement can be used inside a Driver script of automation framework to call the required scripts inside a loop to execute the entire regression or smoke test suite.

Recommended Posts

 

Leave a Reply