Object Properties and Methods used in QTP

Object Properties and Methods used in QTP

Following are the Main Properties and Methods are used in QTP

Activate :

The Activate method is used to activate the dialog boxes/Windows.

Syntax: (Object hierarchy).Activate

Example:

Window("Login").Activate
Dialogue("Login").Activate

Click :

The Click method is used to click on an object, usually buttons.

Syntax: (Object hierarchy).Click

Example:

Window("Login").WebButton("Ok").click

Close :

The Close method is used ot close a window,Dialog box, Browser etc.

Syntax: (Object hierarchy). Close

Example:

Window("Flight Reservation").Close
Browser("Browser").Close

Dblclick (Double Click):

The Dblclick method is used to doubleclick on an object.

Syntax: (Object hierarchy).Dblclick (Co-ordinates)

Example:

Window("Exploring").WinListView("SysListView32").DblClick 73, 120, 1

Set :

The Set method is used in 3 different contexts:

  1. Setting the value of an edit box:

    Syntax: (Object Hierarchy).SET “Value”

    Example:

2.       Dialog ("Login").WinEdit("Agent Name").Set "Agent1"
  1. Selecting a Radio Button:

    Syntax: (Object Hierarchy).Set

    Example:

4.       Window("Flight Reservation").WinRadioButton("Business").Set
  1. Selecting/Deselecting Check boxes:

    Syntax: (Object Hierarchy).Set “ON/off”

    Example:

6.       Window ("Flight Reservation"). Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

Select:

The Select method is used for selecting an item from a combo box or a list box.

Syntax: (Object hierarchy).select “item”

Example:

Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12572

GetVisibletext:

The GetVisibletext method is used to return the Text from a specified area.

Syntax: Variable = (Object hierarchy).getvisibletext

Example:

x=Window("Flight Reservation").WinComboBox("Fly From:").GetVisibleText
msgbox "The Visible Text was :" & x

GetROproperty:

GetROproperty method returns the current runtime object property value. It can be used for getting any run-time object’s, (any) property value.

Syntax: (Object hierarchy).getroproperty (“property name”)

Example:

x=Window("Flight Reservation").WinEdit("Tickets:").GetROProperty ("width")
msgbox x

Click here to know more about GetROproperty.

Navigate:

The Navigate method opens a specified URL in the Browser.

Syntax: (Object hierarchy).navigate “URL”

Example:

Browser("Yahoo!").Navigate "http://www.google.co.in/"

GetItemsCount:

GetItemsCount method returns the number of items in a combobox.

Syntax: (Object hierarchy).GetItemsCount
Example:

x=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox x

GetContent:

GetContent method returns all the items from a combobox.

Syntax: (Object hierarchy).GetContent

Example:

x=Window("Flight Reservation").WinComboBox("Fly From:").GetContent
msgbox x

Exist:

The Exist method checks whether the object is available or not.

Syntax: Object hierarchy.exist(time in seconds)

Example:

If Window("Flight Reservation").Exist Then
   MsgBox "The Window Exists"
Else
   MsgBox "The Window does not Exist"
End If

 

 

GetROProperty (Get Run Time Object Property) in Detail

During Run Time a property of an object in the application is generating a value. We use GetROProperty method to fetch this property value and print it to the user.

To put it as a definition “GetROProperty is a method which returns the specified property value of an object during run time”

We want to print the order number to the user we will fetch the text value of the order number field. Look at the image below:

We use the Text property for the Order No Field. We will use the GetRoProperty method to get the text value and assign it to a variable which is an implicit declaration.

To the above script we will add a wait time of 8 second since the order has to be placed and the order number has to be generated. For this we will use the Wait function which waits for the seconds we mention.

 

 

The lines to be added are

Wait 8

Ord_Num = Window(“Flight Reservation”).WinEdit(“Order No”).GetRoProperty(“text”)

Msgbox “The Order Number is: ” &Ord_Num

 

Run the script and see how the order number is printed.

 

We will write a script using the GetROProperty to fetch the Order Number in the Flight Reservation Application and print it to the user.

 

Window(“Flight Reservation”).Activate

Window(“Flight Reservation”).WinButton(“New”).Click

Window(“Flight Reservation”).WinObject(“Date of Flight:”).Type “121212”

Window(“Flight Reservation”).WinComboBox(“Fly From:”).Select “Frankfurt”

Window(“Flight Reservation”).WinComboBox(“Fly To:”).Select “Los Angeles”

Window(“Flight Reservation”).WinButton(“FLIGHT”).Click

Window(“Flight Reservation”).Dialog(“Flights Table”).WinButton(“OK”).Click

Window(“Flight Reservation”).WinEdit(“Name:”).Set “TestUser”

Window(“Flight Reservation”).WinButton(“Insert Order”).Click

Wait 8

Ord_Num = Window(“Flight Reservation”).WinEdit(“Order No”).GetRoProperty(“text”)

Msgbox “The Order Number is: ” &Ord_Num

 

 

QTP Data Table Methods

 

 

(1) Add Sheet:

We can use this method to “add” one new sheet to the run time data table.

Syntax: DataTable.AddSheet “sheet name”

Ex: DataTable.AddSheet “msk”

 

(2) Delete Sheet:

 

We can use this method to “delete” one specified sheet from the Run Time Data table.

 

Syntax: datatable.DeleteSheet (Sheet_ID)

Ex: datatable.DeleteSheet (3)

 

(3) GetSheetCount

We can use this method to count number of sheets in the run time data table.

Syntax:

datatable.GetSheetCount

msgbox datatable.GetSheetCount

 

(4) GetRowCount

We can use this method to count number of rows in the 1st sheet

(longest column) of the Run time data table.

 

Syntax: datatable.GetRowCount

Ex: msgbox datatable.GetRowCount

 

(5) GetSheet

We can use this method to return a specified sheet from the Run Time data table.

Syntax: datatable.GetSheet(SheetID)

Ex: msgbox datatable. GetSheet(1).GetRowCount

(6) Value

We can use this method to set or get value of cell in the specified parameter and the current row of the Rum time data table.

To set data

Syntax: datatable.Value(Parameter_Name, Sheet_Name) = Value / variable Or

datatable(Parameter_Name, Sheet_Name) = Value / variable

To get data

Syntax: Variable = datatable.Value(Parameter_Name, Sheet_Name) Or

Variable = datatable(Parameter_Name, Sheet_Name)

Ex:

Option explicit Dim a, b, c

 

a=datatable.Value (1,1) b=datatable.Value (2,1) c=cint(a)+cint(b) datatable.Value (3,1) = c

Note: Default property of Datatable is value

(7) SetCurrentRow

 

We can use this method to take a specified row as current row in the Run Time Datatable (By default it is 1st Row of 1st Sheet)

Syntax: datatable.SetCurrentRow(Row_Number)

g=”msk”

datatable.SetCurrentRow (3) datatable.Value (1,1) = g

(8) SetNextRow

We can use this method to take the row after the current Row as New Current Row in the Run time data table.

Syntax: datatable.SetNextRow

Ex: g=”msk”

datatable.SetCurrentRow (3) datatable.SetNextRow datatable.Value (1,1) = g

 

(9) SetPrevRow

 

We can use this method to take the row before the current Row as New Current Row in the Run time data table.

Syntax: datatable.SetPrevRow

Ex: g=”msk”

datatable.SetCurrentRow (3) datatable.SetPrevRow datatable.Value (1,1) = s

 

(10) Import

We can use this method to import Microsoft Excel File to the Runtime Data Table (Including all sheets)

Syntax: datatable.Import “Path of File”

Ex: datatable.Import “F:Inputdata.xls”

 

11) ImportSheet

We can use this method to import a specified sheet of Microsoft Excel Sheet to the Runtime Data table.

Syntax: datatable.ImportSheet “Path of File”, “Source Sheet”, “Destination Sheet”

Ex: datatable.ImportSheet “E:msk.xls”,3,1

 

 

(12) Export

We can use this method to export a copy of Run Time Data table to another location (Including all sheets)

Syntax: datatable.Export “Path of File”

Ex: datatable.Export “F:msk.xls”

 

13) ExportSheet

We can use this method to export a copy specified sheet of Run Time Data table to the existing or new Excel File.

Syntax: datatable.ExportSheet “Path of File”, “Sheet Name / Source Sheet”

Ex: datatable.ExportSheet “F:msk.xls”, 2

 

Comments