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.
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.
LoadAndRunAction(TestPath, ActionName, [Iteration], [Parameters])
|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.|
— 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
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.
Systemutil.Run "C:\Program Files (x86)\Internet Explorer\iexplore.exe","http://www.newtours.demoaut.com/"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "username"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").Set "password"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click
'Calling the Action1 of BookMyFlight 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
- The Solution Explorer pane in UFT.
- The Canvas in UFT.
- The Errors pane in UFT.
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.
- Action Input And Output Parameters In UFT
- How to Use Environment Variables in UFT
- 5 Tips for Using External Environment Variables in UFT
- How to Use Recovery Scenario in UFT with Example
- Read, Write and Update Excel File In UFT
- Read Excel Using ADODB Connection in UFT | VBA
- Reading and Updating MS Access Database Using ADODB in UFT
- How to Use Insight Object in UFT
- Descriptive Programming in UFT with Examples