Wednesday, October 20, 2010

Some Important Syntax that are frequently used in QTP

1. Insert Call to New Action:
Syntax: RunAction ActionName, [IterationMode, IterationRange, Parameters]

Example: RunAction "Cancel_Ticket", oneIteration

2. Retrieve Visible Text from any Object:
Syntax: Object.GetVisibleText(Top,Left,Right,Bottom)

Example: x=Dialog("Login").GetVisibleText(1,1,100,100)

Note: Dialog("Login").GetVisibleText() retrieve whole text from object

3. Retrieve Screen Co-ordinate of specified Text from any Object:
Syntax: Object.GetTextLocation "Text to Search", Left,Top,Right,Bottom

Example: Dialog ("Login").GetTextLocation "UserName", l,t,r,b

4. Retrieve a Property Value from the Object
Syntax: Object.GetToProperty("Property Name")

Example: x= Dialog("Login").GetToProperty("nativeClass")

5. Retrieve a Property Value from the Object during Run Time:
Syntax: Object.GetROProperty("Property Name")

Example: x= Dialog("Login").GetROProperty("nativeClass")

6. Change the property value during run time:
Syntax: Object.SetROProperty("Property Name", "Value")

7. Wait for specified time interval until an Object Existence become True:
Syntax: Object.Exist(Timeout)

Example: x = Dialog("Login").Exist(5)

Note: Output is TRUE or FALSE

8. Wait for specified time interval before continuing the test:
Syntax: Object.Wait(Timeout)

Example: Dialog("Login").Wait(5)

9. Pause the test until an object property achieve the Value that we specify:
Syntax:  Object.WaitProperty("Property Name", Expected Value, Timeout)

 Example: Browser ("Browser").Page("Page").WebButton("Save").WaitProperty("Disable", True, 50)

10. Get the entire item as String wherein individual items are separated by New Line Character:
Syntax:  GroupObject.GetContent()

Example: x= Window("Report").WindowListView("SystemListView32").GetContent()

Output:
List
Tree
Toolbar

11. Retrieve a item from group of Object as a String:
Syntax:  GroupObject.GetItem(Index)

Example:  x= Window("Flight Reservation").Dialog("Flight reservation").WinList("From").GetItem(0)

Output: Delhi

12. Retrieve the Number of Object available in a Group Object:
Syntax: GroupObject.GetItemsCount

Example: x= Dialog("System Properties").Dialog("Environmental Variable").WinListView("SysListView32").GetItemsCount

Output: 12

13. Retrieve the Currently Selected Item from the group as String:
Syntax: GroupObject.GetSelection()

Example: x= Dialog("System Properties").Dialog("Environmental Variable").GetSelection()

14. Select Item in a Group:
Syntax: GroupObject.Select ItemId

Note: ItemId can be Index or Name

Example: Dialog("System Properties").Dialog("Environmental Variable").WinListView(SysListView32).Select 2

15. Applying a multi selectable list or list view object:
Syntax: ListObject.ExtendSelect ItemID

Example: Dialog("System Properties").Dialog("Environmental Variable").WinListView(SysListView32).ExtendSelect 2


16. Selecting Range:
Syntax: ListObject.SelectRange FromItem, ToItem

Note: FromItem/ToItem can be Index or Name

Example: Dialog("System Properties").Dialog("Environmental Variable").WinListView(SysListView32).SelectRange 1,3

17. Deselecting of Existing Selection in the Group:
Syntax: ListObject.Deselect ItemId

Note: ItemId can be Index or Name

Example: Dialog("System Properties").Dialog("Environmental Variable").WinListView(SysListView32).Deselect 2

18. Whether particular Item is Selected or Not:
Syntax: GroupObject.Selected ItemId

Example: x= Dialog("System Properties").Dialog("Environmental Variable").WinListView(SysListView32).Selected 2

19. Click on Specified button in a Toolbar:
Syntax: ToolbarObject.Press ItemID

Example: Window("New Volume(D:)").WinToolbar("ToolbarWindow32").Press "Folder"

20. Show Dropdown:
Syntax: ToolbarObject.ShowDropDown ItemID

Example: Window("New Volume(D:)").WinToolbar("ToolbarWindow32").ShowDropDown "View"

21. Capturing Bitmap:
Syntax: Object.CaptureBitmap SavingPath, Overwrite
Note: For Overwrite True or False is used

Example: Dialog("Login").CaptureBitmap "C:\Test\login.bmp", False

22. User Defined Message in Result Window:
Syntax: Reporter.ReportEvent EventStaus, EventCategory, Message

Example: Reporter.ReportEvent micFail, "Error Message", "Invalid User ID"

23. Check Point:
Syntax: Object.Check (CheckPoint(Property))

Example: x= Object.Check (CheckPoint("OK"))

24. Import Data table:
Syntax: Datatable.Import FileName with path

Example: Datatable.Import "C:\Test.xls"

25. Import Sheet:
Syntax: Datatable.Importsheet Filename with path, SourceSheet, DestinationSheet

Example: Datatable.ImportSheet "C:\test.xls", "Sheet2", "Global"

26. Get Row Count:
Syntax: Datatable.GetRowCount

Example: x = Datatable.GetRowCount
msgbox x

27. Set Current Row:
Syntax: Datatable.SetCurrentRow ItemId
Note: ItemId can be Index or Name

Example: Datatable.SetCurrentRow 2

28. Set Next Row:
Syntax: Datatable.SetNextRow

Example: Datatable.SetNextRow

29. Export Data table:
Syntax: DataTable.Export FileName with path

Example: DataTable.Export "C:\test1.xls"

30. Retrieve the number of Sheet available in Data table during runtime:
Syntax: DataTable.GetSheetCount

Example: msgbox Datatable.GetSheetCount

31. Adding New Sheet to Runtime Table:
Syntax: DataTable.AddSheet SheetName

Example: DataTable.AddSheet "ABCD"

32. Delete Sheet from Runtime Table:
Syntax: DataTable.DeleteSheet SheetId
Note: SheetId can be Name or Index

Example: Datatable.DeleteTable "Action1"

33. Represent the reference to particular sheet to data table:
Syntax:
a. Get Number of Sheet
DataTable.GetSheetCount

b. Get Name
<Variable> = SheetRef.Name

Example: x= datatable.GetSheetCount
For i =1 to x
 Set sheetRef = DataTable.GetSheet(i)
 msgbox sheetRef.Name
Next

Output:
Global
Action1

34. Retrieve number of data column available in sheet:
Syntax:
a. Get Number of Sheet
DataTable.GetSheetCount

b. Get Parameter Count
<Variable> = SheetRef.GetParameterCount

Example: x= datatable.GetSheetCount
For i =1 to x
 Set sheetRef = DataTable.GetSheet(i)
 msgbox sheetRef.GetParameterCount i
Next

35. Adding New Data Column to Runtime data table:
Syntax: SheetRef.AddParameter, ColumnName, InitialValue

Example: Set sheetRef = DataTable.GetSheet (1)
 sheetRef.AddParameter "COL5", "Temp"

36. Delete a data column from sheet:
Syntax: SheetRef.DeleteParameter, ColumnName, InitialValue

Example: Set sheetRef = DataTable.GetSheet (1)
 sheetRef.DeleteParameter "Remarks"

No comments: