SystemUtil.Run "iexplore","www.yahoo.com"
Set b= Browser("Name:=yahoo.*").Page("Title:=Yahoo.*")
b.Link("Name:=Sign In").Click
b.WebEdit("Name:=Login").set "abc"
b.WebEdit("Name:=Passwd").set "def"
b.WebButton("Name:=Sign In").Click
b.Link("Name:=Mail").Click
b.Webtable("Name:=Check Mail").WebButton("Name:=Compose").Click
b.WebEdit("Name:=To").Click
b.WebEdit("Name:=To").Set"xyz@gmail.com"
b.WebEdit("Name:=Subj").Set"helloooo"
b.WebEdit("Name:=BODY").Set"See This Message"
Descriptive Programming(QTP Script) for Yahoo Login Page
QTP Script For Composing Mail in Yahoo
QTP Script to get DataTable ColumnCount,Adding new Column to Datatable,Getting Datatable Column Names
QTP Script to get datatable column count
Syntax:-DataTable.GetSheet("sheet name"/sheetid).getparametercount
Example:-DataTable.GetSheet(1).getparametercount
Script to add new parameter(column)to datatable
Syntax:-DataTable.GetSheet("sheet name"/sheetid).AddParameter "columnname","value"
Example:-DataTable.GetSheet(1).AddParameter "AAA","4"
QTP Script to get all parameter(column)names
For i=1 to a
b=DataTable.GetSheet(1).GetParameter(i).Name
msgbox (b)
Next
where a=parametercount(columncount)
To get rowcount of datatable
DataTable.GetRowCount
Datatable Methods
QTP Script to create Excel Sheet and to enter data into it
QTP Script to create Excel Sheet and to enter data into it(using script).
To create Excel Sheet
Set Excel=createObject("Excel.Application")
Set ExcelSheet=createObject("Excel.sheet")
ExcelSheet.Application.visible=true
'script to enter data(into excel sheet)
Excel.ActiveSheet.cells(1,1).value=1111
Excel.ActiveSheet.cells(1,2).value=2222
Excel.ActiveSheet.cells(2,1).value=3333
Excel.ActiveSheet.cells(2,2).value=4444
ExcelSheet.SaveAs "C:/XYZ.xls"
Excel Sheet is saved in C folder with following data.
A B
1111 2222
3333 4444
Data Driven Testing using Excel Sheet
Datatable Methods(2)
For first part of this post check Datatable Methods(1)
SetCurrentRow:-This method is used for setting the focus of QTP to a specified row.
Syntax:-DataTable.SetCurrentRow(RowNumber)
Example:-DataTable.SetCurrentRow(1)
SetPrevRow:-This method is used for setting the focus of QTP to the previous row of the currently focused row.
Syntax:-DataTable.SetPrevRow
Example:-DataTable.SetPrevRow
SetNextRow:-This method is used for setting the focus of QTP to the next row of the currently focused row.
Syntax:-DataTable.SetNextRow
Example:-DataTable.SetNextRow
GetSheet:-This method is used for making QTP to focus on a specified sheet.
Syntax:-DataTable.GetSheet(SheetId)
Example:-DataTable.GetSheet(1)
GetSheetCount:-This method is used to get count(number) of sheets in datatable.
Syntax:-DataTable.GetSheetCount
Example:-DataTable.GetSheetCount
GetRowCount:-This method is used for getting row count of a sheet.
Syntax:-DataTable.GetRowCount
Example:-DataTable.GetRowCount
By default it will get row count of Globalsheet.
If u want to get row count of a specified sheet then we have to use GetSheet method.
Syntax:-DataTable.GetSheet(SheetId).GetRowCount
Example:-DataTable.GetSheet(2).GetRowCount
Value:-It is used for capturing a value from a specified column,specified sheet and currently focused row.
Syntax:-DataTable.Value("column name"/column id,SheetId)
Example:-DataTable.Value("A",2) or DataTable.Value(1,2)
DataTable Methods(1)
1.AddSheet:-It is used for adding a new sheet to runtime datatable.
Syntax:-DataTable.AddSheet("Sheetname")
Example:-DataTable.AddSheet("laxmi")
2.DeleteSheet:-It is used for deleting a specified sheet from runtime datatable.
Syntax:-DataTable.DeleteSheet("Sheetname")
Example:-DataTable.DeleteSheet("laxmi")
3.Import:-It is used for importing all the sheets from Excel sheet to runtime datatable.
Syntax:-DataTable.Import"Path of Excel sheet"
Example:-DataTable.Import"d:\excel1.xls"
4.ImportSheet:-It is used for importing a specified sheet from Excel sheet to runtime datatable.
Syntax:-DataTable.ImportSheet"Path of Excel Sheet",Source sheetid,Destination sheetid
Example:-DataTable.ImportSheet"d:\excel2.xls",1,1
Here Source and Destination Sheet ids are 1(in this example)
1 is for Global Sheet.
5.Export:-It is used for exporting a complete runtime datatable(all sheets) to a specified location(path).
Syntax:-DataTable.Export"Path where excel sheet has to be created"
Example:-DataTable.Export"d:\excel3.xls"
6.ExportSheet:-It is used for exporting a specified sheet from a runtime datatable to specified location.
Syntax:-DataTable.ExportSheet"Path of Excel Sheet",Sheet id which has to be exported.
Example:-DataTable.ExportSheet"d:\excel4.xls",1
Datatable Methods(2)
QTP Script for RadioButton
QTP Script for RadioButton Control
Radiobutton allows us to select only one option
Syntax for Set method is ObjectHierarchy.Set
Window("Flight Reservation").WinRadioButton("Economy").Set
To Set other option
Window("Flight Reservation").WinRadioButton("First").Set
QTP Script for Combo box and other Controls
QTP Script for Button
QTP Script for Button control
Script to Click on OK Button
Dialog("Login").WinButton("OK").Click
Qtp Script to check whether Button is enabled or not(Disabled).
a=Dialog("Login").WinButton("OK").GetROProperty("enabled")
If a=true then
msgbox"ok button is enabled"
else
msgbox"ok button is not enabled"
End if
QTP Script for Combo box and other Controls
QTP Script for Checkbox
QTP Script for checkbox
Syntax for checking or unchecking checkbox is
ObjectHierarchy.Set"on/off"
Script for above scenario will be
Window().Checkbox("one").Set "on"
Window().Checkbox("three").Set"on"
if u want to uncheck 3rd checkbox then
Window().Checkbox("three").Set"off"
QTP Script for Combo box and other Controls
QTP Script for Textbox
Script to enter value into Textbox
Dialog("Login").WinEdit("Agent Name:").Set "laxmiii"
Script to check whether particular textbox exist or not
If Dialog("Login").WinEdit("Agent Name:").Exist Then
Msgbox "The Textbox exists"
Else
Msgbox "The Textbox does not exist"
End if
If Textbox is present we get message as Textbox exist else we get message as Textbox doesnt exist.
QTP Script for Combo box and other Controls
QTP Script for Combo Box Control
QTP Script for Combobox
In combo box items index start from 0
1.Script for selecting an item from combobox using its value
Window("Flight Reservation").WinComboBox("Fly From:").Select “Frankfurt”
2. Script for selecting an item from combobox using its index
Window("Flight Reservation").WinComboBox("Fly From:").Select 1
1 indicates second item in combobox(0 for 1st item).
3.Script to get total items count of combobox
count = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
output will be 10.
4.Script to get value of selected item
selecteditem=Window("Flight Reservation").WinComboBox("Fly From:").GetSelection
Msgbox selecteditem
Output will be Frankfurt
5.Script to get all items(one by one) from combobox
count = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox count
For i = 0 to count-1
item =Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i)
Msgbox item
Next
Output -- single item will be displayed in messagebox
Total 10 message boxes will be displayed one after other.
6.Script to get names(content) of all items(at a time) from combobox
Content = Window("Flight Reservation").WinComboBox("Fly From:").GetContent
Msgbox Content
Output will be
Denver
Frankfurt
London
Los Angeles
Paris
Portland
San Francisco
Seattle
Sydney
Zurich
All items in one messagebox.
Data Driven Testing
SQL Queries Collection
QTP Script for Connecting to Database
QTP Script for Textbox Control
QTP Script for Checkbox Control
QTP Script for Button Control
QTP Script for RadioButton Control