Mar 15, 2012

QTP V-10.0- Parameterization

Parameterization  


Passing parameters, through this  we can pass multiple values.

We use parametrization 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 Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.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 Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.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.

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.

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 Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","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 Settings\pooja\My Documents\trigun.mdb"
rs.open "select * from login",con
do until rs.eof=true
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","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","gcreddy"
inputdata.Add "Password","mercury"

SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set inputdata("Agent")
Dialog("Login").WinEdit("Password:").Set inputdata("Password")
Dialog("Login").WinButton("OK").Click

QTP V-10.0-Object Repository

Object Repository:
It is a storage place of QTP where objects information can be stored and it also acts as interface between the Test script and the AUT in order to identify the objects during execution.

Object:
Object is something, which has structure and properties.

Software objects:
We call Windows, Web Pages, Buttons, Edit boxes, Check boxes etc.. as software objects.

Types of Object in QTP:
There are four types of object available in QTP.

1. Run time objects
2. Test objects
3. Utility objects
4. Automation objects/User defined objects.

Run time objects: The objects present in the AUT. Ex: Buttons, Links, etc…

Test Objects: References of Run time objects. Ex: WinEdit, WinButton, WebButton, Link, etc…

Note:
Test objects names vary from one environment to another.

Utility objects

They are QTP reserved objects used for Testing and Result reporting.

Ex:
1. SystemUtil for launching/closing the application.
2. Reporter for defining results.
3. Services for inserting transaction points
4. Environment for using environment variables

Automation objects/User defined objects

User can create objects; those can be used for performing specific operations. Ex: Creating objects in filesystemobject class, adodb.connection class, dictionary object class, Excel. Application class etc.

There are two types of repository available in QTP.

1. Local repository (.MTR extension)
2. Shared repository(.TSR extension)

Local Repository:
QTP creates a Local Repository for every Action automatically during Recording. That cannot be shared among tests.

User can add some more objects to Local repository

User can perform rename, delete operations on local repository. As it is QTP internal file user no need to save modifications.

Shared Repository:
User (Test Engineer) creates the Shared Repository by adding objects. That can be shared among number of tests.

Using this method user can perform modifications on objects easily.

Operations on Object Repository

Adding objects
a. Local Repository:

Navigation: open Local Repository (Resource Menu > Object Repository)

objects>Add objects to Local> Show the Object>Click Ok

(No need to save separately, it saves automatically)

B. Shared Repository:

Navigation: Resource menu>object repository manager>object>Add objects>show the window/object>click ok

o Selected object only
o Default object types
o All objects types
o Selected object types

(If we select first option it stores Selected objects only, if we select second option it stores all default objects, if we select third option it stores All objects including static objects, if we select fourth option, we have to select object classes then it stores that class objects, we can select more than one class also.)

Renaming Objects

a. Local Repository:

Resources > object repository >select object and right click >choose rename option >modify the name>release the mouse.>close repository

b. Shared Repository:

Resources >object repository manager>file>open>browse path of the repository file >file>enable editing>select object &Right click>choose rename option>modify the name > release mouse>save the file & close repository manager.

Deleting Objects

a. Local Repository:

Resources > object repository >select object and right click >choose delete option >confirm deletion>. >close repository

b. Shared Repository:

Resources >object repository manager>file>open>browse path of the repository file >file>enable editing>select object &Right click>choose delete option>confirm the deletion >save the file & close repository manager.

Associating Object Repositories to an Action/Test

Resources>Associate repositories>click add icon (+)>browse path of the repository>Associate with an action>click ok

Merging Repositories

Resources > object repository manager>tools>object repository merge tool >browse path of the first repository> browse path of the second repository>click ok>click close>save the merged repository>close the repository manager.

Note: After merging also, source repository files will be available, if we do not want source files we can delete.

Defining New Test Objects

Navigation: Object>Define new test object >Select Environment>Select Class of the object>Enter name of the object>Click Add>click close>Select object >select property name>enter value (like this select one by one properties and enter values)>save

Note: This feature can be used for preparing tests before the AUT is ready.

Spying Objects

For getting objects information, (Test objects names, property & Values) QTP is providing a feature called Object Spy, using this we can get objects information.

Navigation>Tools>object spy>take hand icon & Show the object>get information (Object Spy shows the specific objects all available properties with their values)

Note: As Object spy is an important feature, it can be available in 3 Areas.(1. In tools Menu 2. In local repository 3. In Repository manager)

View Options

Locate in Repository

This feature can be used for identifying objects from application to repository.

Navigation: View>Locate in repository >show the object>click Ok>it locates specified object in the repository.

Highlight in Application

This feature can be used for identifying objects from repository to application.

Navigation: Select object in the repository >view>highlight in application>it highlights specified objects in the application.

Exporting Repository to an XML file

We can export our repository file to an xml file.

Navigation: File >export Test objects to XML Enter the file name and Save with xml extension.

Importing Repository from XML file.

We can import XML file to our repository.

Navigation: File>import from XML >browse path of the XML file >it loads objects.

Note: The purpose of this feature is Editing objects information outside of the QTP

Navigation: Resource menu>object repository (Short cut key Ctrl+R)