Sunday 23 September 2012

QTP Methods / Operations




 QTP Methods / Operations
1) Activate Method

It activates dialog boxes/Windows

Syntax: Object hierarchy. Activate
 Ex:
Dialog(“Login”).Activate
Window(“Flight Reservation”).Activate

2) Click Method
It clicks on an object (Buttons)
Syntax: Object hierarchy. Click
Ex:
Dialog(“Login”).Winbutton(“ok”).click

3) Close Method
It closes the window,Dialog box, Browser window etc.
Syntax: Object hierarchy. Close
Ex:
Window(“Flight Reservation”).Close
Browser(“Browser”).Close

4) Dblclick 
It Double clicks the object.

5) Set Method
It can be used in three ways.
a. For setting the value of an edit box
Syntax: Object Hierarchy. SET “Value”
Ex: Dialog (“Login”).WinEdit(“Agent Name”).Set “asdf”

b. Selecting a Radio Button
Syntax: Object Hierarchy. Set
Ex: Window("Flight Reservation").WinRadioButton("Business").Set

c. Selecting/Deselecting check boxes
Syntax:object Hierarchy.Set “ON/off”
Ex: Window ("Flight Reservation"). Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

6) Select Method:
It is used for selecting an item from a combo box or list box.
Syntax: Object hierarchy.select “item”
Ex:
Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12572

7) GetVisibletext: It returns Text from the specified area.
Syntax: Variable =object hierarchy.getvisibletext
Ex:
x=Window("Flight Reservation").WinComboBox("Fly From:").GetVisibleText
msgbox x

8) GetRoproperty:
It returns current object property value. It can be used for getting any object’s, any property value.
Syntax: Variable = object hierarchy.getroproperty (“property name”)
Ex: x=Window("Flight Reservation").WinEdit("Tickets:").GetROProperty ("width")
msgbox x

9) Navigate Method:
It opens a specified URL in the Browser.
Syntax: object hierarchy.navigate “URL”
Ex: Browser("Yahoo!").Navigate http://www.google.co.in/

10) Getitemscount: It returns number of items in a combobox.
Syntax: Variable=object hierarchy.getitemscount
Ex: x=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox x

11) Getcontent: It returns all items from a combobox.
Syntax: variable=object hierarchy.GetContent
Ex: x=Window("Flight Reservation").WinComboBox("Fly From:").GetContent
msgbox x

12) Exist property: It checks whether the object is available or not.
Syntax: Object hierarchy.exist(time in seconds)
Ex: Window("Flight Reservation").Exist(5)
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 "gcreddy"

(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="gcreddy"

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="gcreddy"

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="gcreddy"


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:\gcreddy.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:\gcreddy.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:\anji.xls”, 2
Data Driven Testing for Login Operation using Data Table methods


Datatable.AddSheet "Login"
Datatable.ImportSheet "C:\Documents and Settings\gcr\Desktop\gcreddy.xls",1,3
Rows_count=Datatable.GetSheet(3).GetRowCount

For i= 1 to Rows_count
    Datatable.SetCurrentRow(i)
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set Datatable("Agent",3)
Dialog("Login").WinEdit("Password:").Set Datatable("Pwd",3)
Dialog("Login").WinButton("OK").Click

If window("Flight Reservation").exist(10) Then
    Login="Login Operation Successful"
    Datatable("Result",3)=Login
    Reporter.ReportEvent micPass,"res","Passed"
    else
Reporter.ReportEvent micFail,"res","Failed"
Login="Login Operation Failed"
Datatable("Result",3)=Login

Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
End If

If Window("Flight Reservation").Exist(3)Then
    Window("Flight Reservation").Close
    End if
Next
Synchronization
It is a process of matching the speeds of both QTP and AUT in order to get proper execution and results.


Where Synchronization is required:

During test execution QTP gives instructions one by one with same speed, but AUT takes less time for some operations execution and more time for some operations execution, that time we may not get proper execution and results. In order to get proper results in between QTP & AUT synchronization is required.

There are several methods available in QTP for synchronization.

1. Inserting Wait statements.
2. Inserting Synchronization points.
3. Increasing Tool default synchronization time.
4. Sync Method (Only for WEB)
5. Exist Property

Inserting Wait Statements:
We can insert wait statements in our test in order to make QTP to wait until AUT completes current operation.
Syntax: Wait(time in seconds)

Note: If we insert wait statements QTP waits up to maximum time even though operation is completed.

Inserting Synchronization points:

Place cursor in desired location>keep tool under recording mode>Insert menu>Synchronization point >show the object >click ok>select property name & Value(True)>enter time in Milli seconds>click ok>Stop recording.

Note: if we insert Synchronization points, it does not wait up to maximum time, after completion of the current operations, it goes to next step immediately.

Syntax: object hierarchy.waitproperty “property name”,value,time in milli seconds.

Increasing Tool default synchronization time:

Navigation: File>settings>run tab>increase object synchronization time out>apply>ok
Note: If we increase QTP tool default time that can be applied for all statements in the test, but QTP does not wait up to maximum time unnecessarily, After completion of one statement execution it goes to next statement immediately.

Sync Method: (only for WEB)
Waits for the browser to complete current navigation.

Syntax: Object Hirearchy.Sync
Ex: Browser("Yahoo! Toolbar").Page("Yahoo! Toolbar").Sync

Selecting an appropriate Method:

1. Suppose in our test one or more statements only are taking more time for execution then selecting “Inserting synchronization method” is better.

2. Suppose in our test more statements are taking more time for execution then selecting “increasing tool time out” .

3. Above two are local features but wait statement is Vbscript feature, even though some drawbacks are there in using wait statement, it is better to use wait statement in functions.

Advantages of Wait Statement:
1)  It is a VBScript statement, we can use this globally

2) It is recommended, whenever we want to observe the Test Execution process
3) No object reference required to insert wait statements

4) It is useful to make QTP capture values and screen shots during test execution

1 comment:

  1. Can the Set method be used with variables for edit boxes?

    ReplyDelete