Sunday, January 27, 2008

Function Library Example 4

QTP Function Library - Example 4

Below is an example that creates a new copy method for winedit object which copies the data from the text field to clipboard and then shows that data (which is copied to the clipboard) in a message box. In a new library file type:

Sub Copy (edit)
Edit.Click
Edit.SetSelection 0, Len(Edit.GetROProperty("text"))
Edit.Type micCtrlDwn + "c" + micCtrlUp
End Sub
RegisterUserFunc "WinEdit", "Copy","Copy"

Open a new test and type:

Dialog("text:=Login").winedit("attached text:=Agent Name:").Copy
Set objhtml=Createobject("htmlfile")
a=objhtml.parentwindow.clipboarddata.getdata("text")
msgbox a
unRegisterUserFunc "WinEdit", "Copy"


Associate the library with the test as we did earlier. Make sure 'Login' window is open (Start-> All Programs -> QuickTest Professional -> Sample Applications ->Flight). In this login window type "sachin" in the Agent Name text field and run the test.

For RegisterUserFunc and UnRegisterUserFunc please see the QTP user guide.


Also See:

QTP Function Library
QTP Function Library - Example 1
QTP Function Library - Example 2
QTP Function Library - Example 3
ExecuteFile