Qtp Command Examples
Essay by 24 • November 28, 2010 • 1,278 Words (6 Pages) • 2,414 Views
QTP Command Examples
1. Activate: Activates the current Dialog Box.
Syntax: object.Activate [BUTTON]
Example:
Sub Activate_Example()
'The following example uses the Activate method to activate the
'Internet Options dialog box.
Browser("Mercury Tours").Dialog("Internet Options").Activate
End Sub
2. CaptureBitmap: Saves the screen capture of the object as a .png or .bmp image using the specified file name.
Syntax: object.CaptureBitmap FullFileName, [OverrideExisting]
Example:
Sub CaptureBitmap_Example1()
'The following example uses the CaptureBitmap method to capture a
'screen shot of the Internet Options dialog box. The file is
'automatically saved to a different folder (the test run results
'folder) in each run.
Browser("Mercury Tours").Dialog("Internet Options").CaptureBitmap "internet_options.bmp"
End Sub
3. ChildObjects: Returns the collection of child objects contained within the object.
Syntax: object.ChildObjects (pDescription)
Example:
'The following example uses the ChildObjects method to retrieve a
'set of child objects matching the description listed in the function
'call and uses the method to display a message indicating how many
'objects are found with the specified description: none, one (unique),
'or several (not unique).
Public Function CheckObjectDesription(parent, descr)
Dim oDesc
' Create description object
Set oDesc = Description.Create()
arProps = Split(descr, ",")
For i = 0 To UBound(arProps)
arProp = Split(arProps(i), ":=")
If UBound(arProp) = 1 Then
PropName = Trim(arProp(0))
PropValue = arProp(1)
oDesc(PropName).Value = PropValue
End If
Next
' Get all child objects with the given description
Set children = parent.ChildObjects(oDesc)
If children.Count = 1 Then
CheckObjectDesription = "Object Unique"
ElseIf children.Count = 0 Then
CheckObjectDesription = "Object Not Found"
Else
CheckObjectDesription = "Object Not Unique"
End If
End Function
4. Click: Clicks on a object.
Syntax: object.Click [X], [Y], [BUTTON]
Example:
Sub Click_Example()
'The following example uses the Click method to click a right mouse
'button at coordinates 47, 131 on the Internet Options dialog box.
Browser("Mercury Tours").Dialog("Internet Options").Click 47, 131, 1
End Sub
5. Close: Closes the Dialog Box.
Syntax: object.Close
Example:
Sub Close_Example()
'The following example uses the Close method to close the Internet
'Options dialog box.
Browser("Mercury Tours").Dialog("Internet Options").Close
End Sub
6. DblClick: Double clicks on a object.
Syntax: object.DblClick X, Y, [BUTTON]
Example:
Sub DblClick_Example()
'The following example uses the DblClick method to double-click a right
'mouse button at coordinates 73, 120 on the SysListView32 object.
Window("Exploring").WinListView("SysListView32").DblClick 73, 120, 1
End Sub
7. Drag: Performs the 'drag' part of a drag and drop operation.
Syntax: object.Drag X, Y, [BUTTON]
Example:
Sub Drag_Example1()
'The following example uses the Drag and Drop methods to drag the object from
'coordinates 10, 20 within the Test window and drop the object at
'coordinates 30, 40 within the same window.
Window("Test").Drag 10, 20
Window("Test").Drop 30, 40
End Sub
8. Drop: Performs the 'drop' part of a drag and drop operation.
Syntax: object.Drop X, Y, [BUTTON]
Example:
Sub Drop_Example1()
...
...