Some of the methods in QTP
|
|
Working with API functions in QTP
- Extern object – It enables us to declare calls to external procedures from an external dynamic-link library (DLL).
- Declare Method - Declares references to external procedures in a dynamic-link library (DLL).
Once we use the Declare method for a method, we can use the Extern object to call the declared methodSyntax
Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])Argument
Type
Description
RetType
String
Data type of the value returned by the method.
MethodName
String
Any valid procedure name.
LibName
String
Name of the DLL or code resource that contains the declared procedure.
Alias
String
Name of the procedure in the DLL or code resource.
ArgType
String
A list of data types representing the data types of the arguments that are passed to the procedure when it is called.
Example
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
if hwnd = 0 then
MsgBox "Notepad window not found"
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "qat")
RegisterUserFunc utility in QTP - Enables us to add new methods to test objects or change the behavior of an existing test object method during a run session
- When we use this statement, QuickTest uses our user-defined function as a method of a specified test object class for the remainder of a run session, or until we unregister the method.
Syntax
RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefaultArgument
Type
Description
TOClass
String
The test object class for which you want to register the method.
MethodName
String
The method you want to register.
FunctionName
String
The name of your user-defined function. The function can be located in your action or in any library file associated with your test or component.
SetAsDefault
Boolean
Indicates whether the registered function is used as the default method for the test object.
Example
The following example uses the RegisterUserFunc method to create a new Copy method for the WinEdit test object that copies all the text in an edit box to the Windows Clipboard.
Sub Copy (edit)
Edit.Click 3, 3
Edit.SetSelection 0, Len(Edit.GetROProperty("text"))
Edit.Type micCtrlDwn + "c" + micCtrlUp
End SubRegisterUserFunc "WinEdit", "Copy", "Copy"
' Now you can call the new method
Dialog("Login").WinEdit("Agent Name:").Copy