QTP-Parameterization
Parameterization
Passing parameters, through this we can pass multiple values.
We use parameterization in Data Driven Testing.
Data Driven Testing: Testing the Same operation with multiple sets of test data.
Types of Parameterization: We can parameterize tests in several ways in QTP
1. Through Loop Statements
2. Dynamic Test Data Submission
3. Through Data Table
4. Fetching Test Data directly from External files (Flat files & Spreadsheets)
5. Fetching Test Data directly from Databases (MSAcess, Oracle etc).
6. Getting Test Data from front end objects.
1. Through Loop Statements: We can use loop statements for passing sequential numbers & Logical Numbers.
Note: We can’t generate Strings.
For orderno=1 to 10 step 1 ‘ for one increment step keyword is not mandatory
Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set orderno
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click
Next
2.Dynamic Test Data Submission: Through Loop Statements we can give strings also but every time user has to enter data.
For x=1 to 3
Agent =inputbox(“enter an Agent Name”)
Password=inputbox(“enter a password”)
invokeapplication “C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set Agent
Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
Dialog(“Login”).WinEdit(“Password:”).SetSecure password
Dialog(“Login”).WinButton(“OK”).Click
Window(“Flight Reservation”).Close
Next
3. Through Data Table: QTP adds one data table (Spreadsheet) for every test, we can use Data Table for Data Driven Testing.
It has 3 types of usage .
a. Entering test data directly into data table and use
b. Importing test data from external Flat files
c. Importing test data from external Spread sheets
d. Importing test data from Data bases.
a. Entering test data directly into data table and use.
Steps:
i) Generate the basic test>open data table(View>Data Table)
ii) Click on column header>enter the name of the field (like this we can create number of columns) > Enter Data>connect the data to test
(variable=datatable(“column name”, Sheet id)
Example: agent=datatable(“agent”,1)
Pass parameters.)
iii) Run the test.
Example:
Agent = Datatable(“Agent”,1)
pwd=Datatable (“Password”,1)
Invokeapplication “C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set Agent
Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
Dialog(“Login”).WinEdit(“Password:”).SetSecure pwd
Dialog(“Login”).WinButton(“OK”).Click
Window(“Flight Reservation”).Close
b. Importing test data from external files:
Open Data Table (view>Data table)>place mouse pointer on data table and right click>file>import from file>Click ok>Browsw path of the file(it imports data from the flat file)
Connecting Test Data to QTP Test as above and run the test.
c. Importing test data from external Spread sheets:
Open Data Table (view>Data table)>place mouse pointer on data table and right click>file>import from file>Click ok>Browse path of the excel sheet (it imports data from the excel sheet)
Connecting Test Data to QTP Test as above and run the test.
d. Importing test data from Data bases:
Through Data table we can import Test Data from Data bases, but first we have to create /get the DSN(Data source Name)& we have to use SQL Commands.
Through Data table we can import Test Data from Data bases, but first we have to create /get the DSN(Data source Name)& we have to use SQL Commands.
i). Creating a Test Database: open MS Access (or we can use any other database).
ii) Start programs>MS Office>MS Access>file >new>Select blank Database>enter name of the database>Save with mdb extension.
iii)
Creating Tables: Select Create table in design view>Enter field name(Agent)and Select data type(text) Like this we can create number of fields>save&enter table name.
iv)
Entering Data into Tables: Select table>enter the data.
v)
Creating DSN & importing data
Navigation:
view>data table>Place mouse pointer on Data table>sheet>import>from database(Database query wizard opens)>choose ‘specify SQL statements manually>click next >click create>click new>select driver type>click next >browse path to store> enter DSN Name>Click Save>click next>click finish>select>browse the database& select>click ok>click ok>select DSN>click ok>enter SQL statement (select *from login)>click finish.
view>data table>Place mouse pointer on Data table>sheet>import>from database(Database query wizard opens)>choose ‘specify SQL statements manually>click next >click create>click new>select driver type>click next >browse path to store> enter DSN Name>Click Save>click next>click finish>select>browse the database& select>click ok>click ok>select DSN>click ok>enter SQL statement (select *from login)>click finish.
Note: DSN Creation is one time activity, by using the DSN we can get data for number of tests.
4. Fetching Test Data directly from Flat files
Dim fso, myfile
Set fso=createobject(“scripting.filesystemobject”)
Set myfile=fso.opentextfile(“d:trigun.txt”,1)
myfile.skipline
While myfile.atendofline <> true
x=myfile.readline
S=split(x,”@”)
SystemUtil.Run “C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightappflight4a.exe”,””,”C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightapp”,”open”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set s(0)
Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
Dialog(“Login”).WinEdit(“Password:”).SetSecure S(1)
Dialog(“Login”).WinEdit(“Password:”).Type micReturn
Window(“Flight Reservation”).Close
Wend
Fetching Test Data directly from Excel Sheets
Fetching Test Data directly from Databases
Option explicit
Dim con,rs
Set con=createobject(“adodb.connection”)
Set rs=createobject(“adodb.recordset”)
con.provider=(“microsoft.jet.oledb.4.0″)
con.open “C:Documents and SettingspoojaMy Documentstrigun.mdb”
rs.open “select * from login”,con
do until rs.eof=true
SystemUtil.Run “C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightappflight4a.exe”,””,”C:Program FilesMercury InteractiveQuickTest Professionalsamplesflightapp”,”open”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set rs.fields (“agent”)
Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
Dialog(“Login”).WinEdit(“Password:”).SetSecure rs.fields(“password”)
Dialog(“Login”).WinEdit(“Password:”).Type micReturn
Window(“Flight Reservation”).Close
rs.movenext
loop
————————————–
————————————–
Using Dictionary Object for Parameterization
Set inputdata=CreateObject(“Scripting.Dictionary”)
inputdata.Add “Agent”,”Naseer”
inputdata.Add “Password”,”mercury”
inputdata.Add “Password”,”mercury”
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set inputdata(“Agent”)
Dialog(“Login”).WinEdit(“Password:”).Set inputdata(“Password”)
Dialog(“Login”).WinButton(“OK”).Click
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set inputdata(“Agent”)
Dialog(“Login”).WinEdit(“Password:”).Set inputdata(“Password”)
Dialog(“Login”).WinButton(“OK”).Click
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.