QTP T utorial #21 – How to Ma ke QTP Tests Modular and Reusable Using Actions and Function LibrariesPosted In |Automation Testing,QTP TutorialsQTP Actions and Action Properties: Actions divide a test into logical units. This aids in highly readable tests and make sure that modularity is achieved. There are 3 types of QTP actions: 1.Reusable–only these can be called multiple times within the same or different tests 2.Non-reusable –These cannot be called by any other actions 3.External actions–a reusable action when called from another action becomes an external action in the called action. How to useQTPActions in tests?1) By default all new actions are reusable 2)Every action has its own “Action” datasheet or a local sheet 3)Call to an existing action in another test can be inserted by using the menu option: “ Insert- >Call to an existing action-> (Choose test/action)”4) The statement or action call inserted in the current test will be as follows: 1 RunAction “Action2[Testname]”, oneiteration
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
7/28/2019 Tutorial #21 - Actions and Function Libraries
Let’s create a function library now: Use the menu option “File->New->Function Library” or “Shift+Alt+N” or click on the
“New” drop down option in the menu and choose “Function library”
QTP will open up an editor, very similar to the keyword view of a test. Here you can writeyour code. I am going to include statements that will login a user into gmail.com page.
1
2
3
4
5
6
7
Function gmailLogin(uname, pwd) 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 uname Browser("Gmail: Email from Google").Page("Gmail: Email from
Google").WebEdit("Passwd").SetSecure pwd Browser("Gmail: Email from Google").Page("Gmail: Email from
Google").WebButton("Sign in").Click End Function
Once you are done writing the code, “Save” the function library by choosing the required
name and location on your computer.
Note – A function library does not get auto included in any of your tests. You are going to
have to do it explicitly.
The following are the steps to associate a function library into your test:
Step #1) Open your test or create a new test
Step #2) Depending on the settings you have on your IDE you might have the resources pane
already available to you. If not choose the menu option “View->Resources” and this displaysthe pane.
Step #3) Right click on the “Associate Function libraries”, click the “Associate Function
library” option and choose the library file you created earlier.