Monday, 30 July 2012

Data Table Methods in QTP

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

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

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

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:\rk.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:\rk.xls”, 2

**********************

Data Driven Testing for Login Operation using Data Table methods

Datatable.AddSheet "Login"
Datatable.ImportSheet "C:\Documents and Settings\gcr\Desktop\rk.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

Object Identification Process


Overview:

Generally for every object 20-25 properties information available, qtp recognizes object using 2 0r 3 important properties.

Qtp has default object identification configuration for every environment, if we feel that config is not sufficient for recognizing objects in our application, we can configure some more

Object Identification Types


a)    Normal identification

1)   Mandatory properties
2)   Assistive properties

b)    Smart identification

1)    base filter properties
2)    optional filter properties

c)    Ordinal identifier  

1)    location
2)    index
3)    creation time(only for Browser)

QTP learns information in the following in case of normal identification:

First of all the qtp learns all the mandatory properties at a time and thinks whether these properties sufficient to identify the object uniquely. if it feels sufficient then it stops learning otherwise,
It learns first assistive property and once again stops and thinks, like this qtp learns one by one. At the end of assistive properties list also if it feels not satisfied and it finally goes to Ordinal Identifier.

QTP learns information in the following in case of Smart Identification:

Smart identification is an optional feature, if we feel normal identification is not sufficient for any object, and then we configure Smart Identification for that object, in order to avoid Ordinal Identifier.

After normal identification if qtp feels not satisfied then it goes to smart identification. in smart identification 2 types of properties available, first qtp learns all base filter properties at a time and thinks whether these properties are sufficient for identifying the object uniquely. If it feels sufficient, then it stops learning otherwise it goes Optional Filter Properties and learns one by one. Still it feels not satisfied finally it goes to Ordinal Identifier.

Ordinal identifiers:

There are 3 types of ordinal identifiers available

1) Location: is based on object location in the AUT ,location starts from zero.  

2) index: it is based on sequence of the programs, index starts from zero  

3) Creation time: it is based on loading time of the web objects. qtp generates 0,1,2 like numbers.

Tool Settings Globalization:

As QTP is a I-tier(Stand-alone) application,making Tool settings globally is not possible.

For making tool settings global, QTP is providing a special feature called "Generate Script".

STEPS:

1) Settings available in 3 areas.
  
    a) File->Settings
    b) Tools->Options
    c) Tools->Object Identification

2) Perform required settings and generate Scripts

3) Share Script files to team members and ask them to execute those scripts.

NOTE: After executing these scripts all team members can get same settings.


Object Repository in QTP

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)

Types of Recording in QTP

a) Test Recording Process

It is a Process of Recording user operations on AUT (Application Under Test). During Recording QTP Creates steps in Keyword view, and generates them in a script in the Expert view. Simultaneously it adds Objects information into Object Repository.

b) Running /Execution Process
During Running QTP reads statements one by one and gets Object Information from the Object Repository, based on that Information performs operations on AUT.

c) Recording Modes
QTP has 3 Recording Modes to generate Tests / Test Scripts

i)  Normal Recording 

It records User Mouse and Keyboard operations on AUT with respect to objects, but unable to record continuous mouse operations like Digital Signatures, graphs, paints etc.

During recording QTP generates VbScript statements in Test Pane, Simultaneously it stores objects information into object repository. 

Navigation: Automation>Record

                          Or

           Select Record option on automation toolbar

                          Or

             Use short cut key (F3) 

Steps for preparing a Test (through Recording): 

1.Put AUT in base state

2.Select Record Option

3.It shows Record and Run Settings, Select type of Environment (Windows or Web)

4.Select Record Option  

(It shows two Options :

1.Record and Run Test on any open window based applications

2.Record and Run only on) 

If we select first option it records on any opened application on Desktop.

If we select Second option, it asks for the path of the AUT, After Providing the path it records only on that particular application.) 

5.Click OK

6.Perform actions on AUT

7.Stop recording.

8.Save the Test  

ii) Analog Recording: 

It records the exact mouse and keyboard operations. We can use this mode for recording continuous mouse operations. It is not useful for recording normal operations why because it does not generate steps for each operation, generates total user actions in a Track File. The Track file is not editable. 

Navigation:  

1.Keep tool under recording mode

2.Automation >Analog Recording

OR

Use Short cut Key (Shift + ALT+F3) 

Steps for preparing a Test (through Analog Recording): 

1.Launch AUT (or we can launch AUT through QTP)

2.Select Record option

3.Automation>Analog Recording

4.Analog Recording Settings Dialog box opens 

(In this Dialog box two options available. 

1.Record relative to the screen

2.Record relative to the following window) 

(If we select first option QTP records User operations with respect to Desktop co-ordinates.

If we select Second option, we have to show the window (AUT), after showing the Window it records with respect to that window co-ordinates.) 

5.Select any one option in the dialog box and click Start Analog record.

6.It records User actions

7.Stop Recording

iii) Low Level Recording 

It records some operations on Non-supported environments apart from Normal operations.  

This mode records at the object level and records all run time objects as window or winobject Test objects. 

Use Low Level Recording for recording in an environment not recognized by QTP. 

Navigation:

1.Keep tool under recording mode

2.Automation >Low Level Recording 

Steps for preparing a Test (through Low Level Recording): 

1)Launch AUT (or we can launch AUT through QTP)

2)Select Record option

3)Automation> Low Level Recording

4)Perform options on AUT

5)Stop Recording

6)Save the Test 

d) Disadvantages of Recording
• It occupies a lot of memory space(due to duplicate objects), So QTP    performance will be reduced 

• No Centralized Maintenance mechanism , So Modifications are very difficult 

• User may not have command on the Recorded script, So locating errors is difficult 

•  Recorded scripts are QTP internal files, they may corrupt.


e) Advantages of Recording/ Where Applicable
• It is used for Analyzing the AUT in the initial stage to find out weather the QTP tool is Recognizing all of our Application Objects or not

• It is easy to create Tests / Test Scripts 

•It is used for frequently changing UI (User Interface) 

• It takes less time to create Tests