Quality Testing

Quality is delighting customers

How to create and where we call user defined functions in QTP? Give an example.

Views: 4656

Reply to This

Replies to This Discussion

User defined functions are encapsulation of segments of code which is used several times in the script.They can be
either within the QTP script or can be maintained in external .VBS or .TXT files.

Creating User defined Functions:
Open QTP and Application --> type function header along with Unique function name and arguments --> Record
repatable operations in application as function body --> follow above navigation to create more then one functions --
> Save that functions in a file using 3rd party s/w with Extension .vbs( Copy the script, genarated in QTP and paste
in Notepad, MS.Word etc.) --> now goto Resource menu in QTP --> object Repository --> file menu --> Export Local
Objects --> Enter file name with Extension .tsr --> click Save.

Calling User defined Functions:
In QTP --> type Useer defined function name along with argument values --> file menu --> settings --> Resources
tab --> click + icon -->browse the path of the file --> click apply --> click OK --> Resources menu in QTP -->
Associate Repositories --> Click + icon --> browse the path of references file --> select current action --> click OK.

Example:( Creating User defined Function )
Public function login(x,y)
Dialog ("Login").winedit("User name").set x
Dialog ("Login").winedit("Password").setsecure
crypt.encrypt (y)
dialog ("Login").winbutton("OK").Click
End Function
User defined function is nothing but we write our own functions to perform set of action which contains a login to execute some steps on the application without making use of inbuilt qtp functions or which contain full logical code by us.

For. Eg:
If you need to do some arithmetical operation and just return the value to some object (textbox) or some thing else. Then write a funcion on ur own and pass the value to do the operation and that's it.

Similary if u want to do some event handling like check, click, select object, do some decission making etc. based on
return value u can make use of functions effectively.

We can write user define functions in QTP Editor or in notepad also. when we write functions in notepad we have to save file with .vbs extention. and close notepad then we can use that file in qtp resources. in resources we give notepad file path. than we can use funtion directly by functions name....

please correct me if I'm wrong..

creation of userdefined functions involves two steps
01. write the script for particular functionality that we may think is reusable
02. save that with unique nae to easily identify in future retrival purpose, save it.

to perform above two steps the approach we fallow:

use Qtp testpane or any text editor to wite the script..
if it is a txteditor save it with .vbs extension
if it is qtp test pane saave it using export option in local system memory

Once creation completed use that by adding in resources...

queries are invited...


TTWT Magazine





© 2021   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service