About QTP Actions and their Properties
Actions facilitate the division of a test into logical sections. This helps improve readability and assures modularity.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
QTP Actions come in three varieties:
- Reusable Actions: These can be invoked numerous times within the same test or across different tests.
- Non-Reusable Actions: These cannot be used by any other actions.
- External Actions: When a different action calls a reusable action, it morphs into an external action that exists within the called action.
=> Click Here To Check Out The QTP Training Tutorials Series
How to Implement Actions in QTP Tests?
#1) By default, every new action is reusable.
#2) Each action possesses its own “Action” datasheet or local sheet.
#3) To insert a call to a pre-existing action in another test, select the menu option: “Insert -> Call to a pre-existing action -> (Choose test/action)”
#4) The statement or action call that’s inserted in the current test would look like this:
RunAction "Action2[Testname]", oneiteration
#5) The action would be invoked as many times as stated in the called properties of the parent action.
Example:
Action2 is a reusable action in Test2. It’s invoked for every iteration in the data table of Test2.
Action1 is the action that invokes Action2 in Test1.
Action1 runs only once.
Then, regardless of how many times it was called in Test2, Action2 will run only once.
#6) A reusable action can be converted into a non-reusable one and vice versa.
#7) If an action that was previously reusable is designated as non-reusable, the test that invokes the action will fail and a warning message will pop up.
#8) The previous article provided a discussion on how parameters could be passed “To” and “From” actions. You can decide this using one of the following methods:
- Select the action from the keyword view, right-click, and then choose Action Properties.
- While in the expert view of the action, select Edit -> Action Properties from the menu.
#9) A dialog box showing tabs for General (name, description, reusable or not), Parameters (input or output), Associated Repositories (you can associate another action’s OR), and Used by will pop up.
#10) The standard syntax for passing parameters to an action looks like this:
RunAction "Action Name". Oneiteration, input parameters, output parameters
Here are various ways to extract the output value of an action for your test:
a) The output value (value returned by an action that has been called) can be saved in a variable.
RunAction "Action1", OneIteration, inputValues, x, where x is the variable
b) The output value can be kept in an environment variable.
To create this environment variable, opt for “File -> Settings -> Environment tab”, select “user-defined” from the “Variable Type” dropdown, click + and “Add new environment Parameter” – enter the name (env_Var) and an empty value, then click OK.
Use this to assign the output value to this variable:
RunAction "Action1", OneIteration, inputValues, Environment("env_var")
c) Output values can be saved in a column of a data table.
RunAction "Action1", OneIteration, inputValue, DataTable("A", dtGlobalSheet)
About QTP Functions and Function Libraries
While QTP offers in-built functions for testers, there might be scenarios where you want to carry out a specific operation and reuse those steps.
This can be done by creating user-defined functions, saving them in distinct files, associating them with the test, and utilizing the function name as a keyword within the test.
In essence, a function is simply a block of code that executes a certain task.
Here’s how to create a function library:
Employ the menu option “File -> New -> Function Library” or “Shift+Alt+N” or click on the “New” dropdown option on the menu and pick “Function library”.
QTP will open an editor that’s similar to a test’s keyword view. You can write your code here. Let’s construct a function that logs a user into the gmail.com webpage.
Function gmailLogin(username, password) SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set username Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure password Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click End Function
Once the code is written, save the function library with a distinct name and path on your device.
Note: The function library isn’t automatically included in any tests. It needs to be explicitly included.
Here’s how to link a Function Library with your test:
Step #1: Open or create your test.
Step #₂: If it’s not already open, activate the resources pane using the menu option “View -> Resources”.
Step #3: Right-click “Associate Function Libraries,” select “Associate Function library,” and choose the library file you established earlier.
Step #4: A confirmation message could come up before transforming the path into a relative path. Click “Yes” to ensure the test doesn’t fail if files are relocated within the same hierarchy.
Step #5: The library will be visible under the associated function libraries node.
Step #6: Save your test after linking the library.
Henceforth, if your test includes a statement like the one below, it will call up the function in the library and execute the steps within it.
gmailLogin("swatiseela", "akihad989080890")
In the above statement, constant values for username and password are being passed. If necessary, you can also transmit values from the data table.
gmailLogin(DataTable("SignInName", dtGlobalSheet), DataTable("GPassword", dtGlobalSheet))
You can store more than one function in your library files and link multiple library files with your test.
Conclusion
Summing up, Function Libraries and Actions are pivotal to make tests more reusable and modular.
The following topic will explore Object Repositories (OR) and elucidate how to develop, link, and operate with shared ORs and OR managers.
=> Visit Here for the continued QTP Training Tutorials Series
If you have any queries or comments, please feel free to post them.