3. Parameterization
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.
4. Parameterization
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
5. Parameterization
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
6. Parameterization
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.
7. Parameterization
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.
9. Parameterization
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.
10. Parameterization
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.
11. Parameterization
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.
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
12. Parameterization
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.
Note: DSN Creation is one time activity, by using the DSN
we can get data for number of
tests.
13. Parameterization
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,"@")
15. Parameterization
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
17. Parameterization
Using Dictionary Object for Parameterization
Set inputdata=CreateObject("Scripting.Dictionary")
inputdata.Add "Agent","gcreddy"
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
18. Step Generator
The Step Generator enables to add steps
easily, by selecting from a range of context-
sensitive options and entering the required
values.
User familiar with VBScript, can add and
update statements and enhance the tests with
programming.
After the test or an Action is recorded, its
power and flexibility can be increased by
adding recordable and non- recordable
VBScript statements as required for tasks like
Checkpoints, Datatables etc.
19. Step Generator
These additional steps can be added either
manually or using Insert>Step >Step
Generator.
In the Step Generator dialog box steps can be
defined that use:
-Test object methods and properties.
-Utility object methods and properties.
-Calls to library functions, VBScript functions,
and internal script functions.
21. Adding conditional
statements
Conditional statements enable you to control the flow of
your Test or component. You use the IF … THEN and
ELSE statement to incorporate decision-making in your
tests. The IF … THEN statement evaluates whether a
condition is true. If the condition is true, the statements
following IF … THEN are executed. If condition is not true,
the statements
following the ELSE are executed.
If [condition] Then
[statement]
Else
[else statement]
End If
22. Adding conditional
statements
if...then...elseif statement
if fee="Cash" then
msgbox "pay cash!"
elseif fee="Visa" then
msgbox "pay with visa."
elseif fee="American Express" then
msgbox "pay with American Express."
else
msgbox "Unknown method of Payment."
end If
23. Custom checkPoints
QTP checkpoints are very limiting when it
comes to maintenance and transport of
the same across scripts. It is always best
to avoid QTP checkpoints whenever
possible and create your own checkpoint.
For doing the custom check points, we
use Reporter.ReportEvent method
24. Custom checkPoints
Syntax is: Reporter.ReportEvent EventStatus,
ReportStepName, Details
There are 5 EventStatus.
micPass – used to display passed events.
micFail – used to display Failed events.
micDone – No event status
micWarning – used to display Warning events.
micInfo – used to display any information events.
26. Custom checkPoints
Custom CheckPoints and the Exist Method
This is an extremely important concept, and it
should serve as the base to all
CheckPoints. It checks whether an object
exists on the page or not, and before we
can start verifying an object’s properties,
it’s important that we check if it is even
available to us to perform our
verifications. Also, if the object is found in
the applicantion, the Exist method returns
true, else, it returns false.
Syntax:Object.Exist(Timeout)
27. Custom checkPoints
In this syntax, Timeout is the amount of time
you would like QTP to wait for the object
before it returns a boolean output.
Case where an object is found.
To check if the Text box exists, we can
formulate the following code that will wait
for a max of 5 seconds before the WebEdit
appears on the page:
MsgBox Browser("title:=.*Relevant
Codes.*").Page("micclass:=Page")
.WebEdit("name:=txtExistTest").Exist(5)
28. Custom checkPoints
Case where an object is not found.
MsgBox Browser("title:=.*Relevant
Codes.*").Page("micclass:=Page")
.WebEdit("name:=txtNotFound").
Exist(5) 'False
29. Custom checkPoints
Custom CheckPoints and the
GetROProperty Method.
GetROProperty is short for Get-
Runtime-Object-Property. In other
words, this method can be used to
retrieve the value that the object has,
at present.
Note that, in some dynamic applications,
runtime object properties can change
on various factors.
30. Custom checkPoints
Also, with Descriptive Programming (DP),
regardless of what property you retrieve, it
will always be a runtime property.
If
Browser("title:=.*Relevant.*").WebEdit("name:=t
xtMaxLen").GetROProperty("max
length")=10 Then
Reporter.ReportEvent micPass, "WebEdit
MaxLength Text", "Test Passed."
Else
Reporter.ReportEvent micFail, "WebEdit
MaxLength Text", "Test Failed."
End If
31. Custom checkPoints
When you open your Test Results after the above
statement executes, you will notice that, the test failed.
It will always fail because the maxLength for our
WebEdit is not 10, but 9. When you you use Object spy
to retrieve the max length property,you will notice that
it is indeed not 10, but its 9. However, in the real-world,
we may not always know the properties these objects
will have at runtime, and most of the times you will
come to find of errors after your regression suites
complete their execution.
32. Custom checkPoints
Let’s create another CheckPoint, and verify if the Link has the correct
color:
With Browser("title:=.*Relevant Codes.*").Link("text:=Relevant Codes:
Test Color")
If .Exist(5) Then
If .GetROProperty("color") = "#0000ff" Then
Reporter.ReportEvent micPass, "RelevantCodes Link", "Correct color."
Else
Reporter.ReportEvent micFail, "RelevantCodes Link", "Incorrect color."
End If
Else
Reporter.ReportEvent micFail, "RelevantCodes Link", "Link was not
found."
End If
End With
33. QTP Continued
Day4:
Report and Comment
Splitting Action
Virtual object
34. QTP Continued
Day5:
Recovery scenario
Optional steps
Framework Approach
Working with Dynamic Objects