QTP
Dhananjay Singh
Life Cycle Of AutomationAnalyze the Application Select The Tool Identify the session Design/ Record Test Scripts
Run the test scripts Finding & Reporting the defects Wednesday, May 22, 2013
Dhananjay Singh
2
Introduction to QTP -
. Developed by Mercury interactive But Now by HP . Developed for web functionality .QTP s both web applications & windows applications . QTP Developed in 2002 . Test Script developed on VB Script . QTP s Languages is .NET. J2EE, Main Frame, XML,Java ERP -> SAP, Seibel, People soft
. QTP s both Technical & Non Technical People . QTP run on only windows platform not ing UNIX, Linux etc
Wednesday, May 22, 2013
Dhananjay Singh
3
Overview of QTP -
Wednesday, May 22, 2013
1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) 19) 20) 21) 22) 23) 24) 25) 26)
Testing Process of QTP Windows Structure of QTP Add Ins of QTP Architecture of QTP Execution process in QTP Development of Automation Test Recording Modes in QTP Object Repository Object Spy Transaction Virtual Object Check Points Actions Exception Handling Object identification Ordinal Identifier Smart Identification Output Values Synchronization point QTP Run Modes Regular Expressions Descriptive Programming Environment Variables VB-Script Hoe to work with Functions Associated LibraryDhananjay Singh
4
Testing Process of QTP 1) Record & Run Settings 2) Develop Automation Testing 3) Enhance/ Customize Automation test 4) Debug Automation Test 5) Execute Automation Test 6) Analyze Test Results
7) Report defects in bug tracking tool
Wednesday, May 22, 2013
Dhananjay Singh
5
Window Structure of QTP 1) Test Pane 2) Active Screen 3) Data Table 4) Debug Viewer
Wednesday, May 22, 2013
Dhananjay Singh
6
Add Ins of QTP It gives information about the technology ed by the QTP By default three Add Ins are there in QTP 1) ActiveX 2) VB 3) Web Additional Add ins: 1) Java 2) Oracle 3) People soft 4) .NET 5) Terminal Emulator 6) SAP 7) Siebel
Wednesday, May 22, 2013
Dhananjay Singh
7
Add In Manager
Wednesday, May 22, 2013
Dhananjay Singh
8
Architecture Of QTP -
1) 2)
Execution Process in QTP Development of Automation Test 1) Recording 2) Writing 3) Function Generator
Wednesday, May 22, 2013
Dhananjay Singh
9
Recording Modes of QTP -
There are three recording modes in QTP 1)Normal Recording Mode 2) Analog Recording Mode 3) Low Level Recording Mode
Wednesday, May 22, 2013
Dhananjay Singh
10
Record a Test
Wednesday, May 22, 2013
Dhananjay Singh
11
Record & Run Settings-
Wednesday, May 22, 2013
Dhananjay Singh
12
Run a Test and Save Results-
Wednesday, May 22, 2013
Dhananjay Singh
13
View Test Results-
Wednesday, May 22, 2013
Dhananjay Singh
14
Object RepositoryObject Repository is nothing but a storage location. It contains the collection logical name and physical description of a particular object. Logical Name: For Naming Convention Physical Description : is Nothing but expected physical properties Two types of Object Repositories are available in QTP1) Per Action (.mtr) 2) Shared Object Repository (.tsr)
Wednesday, May 22, 2013
Dhananjay Singh
15
Open the Object Repository Dialog Box-
Wednesday, May 22, 2013
Dhananjay Singh
16
Object SpyObject spy is used to display or view all the physical properties and methods of an object or a window based on the requirement. Example: If window(“”). Exists Then Msgbox(“”) else Msgbox(“Fail”) End If
Wednesday, May 22, 2013
Dhananjay Singh
17
Virtual ObjectVirtual Object is used to identify the properties of similar objects in a particular Area. Example: In normal recording if we select the paint brush window, the script will look like thiswindow(“Paint”).Activate Window(“Paint”).Winobject(“colors”).Click 72,16 Window(“Paint”).Winobject(“colors”).Click 80,14 window(“Paint”).Close
If we are using Virtual object, the script will look like thiswindow(“Paint”).Activate Window(“Paint”).Winobject(“colors”).Virtual Button(“RED”) Window(“Paint”).Winobject(“colors”).Virtual Button(“BLUE”) window(“Paint”).Close
Wednesday, May 22, 2013
Dhananjay Singh
18
Check PointsCheck Point is a verification point that compares the current value of the specified property with the expected value for that property. There are 9 types of check points are available in QTP. They are1) Standard Check Point 2) Text/ Text Area Check Point 3) Bitmap Check point 4) Database Check Point 5) Table Check Point 6) Page Check Point 7) XML Check Point 8) Image Check Point 9) Accessibility Check Point
Wednesday, May 22, 2013
Dhananjay Singh
19
Checkpoint Types
Wednesday, May 22, 2013
Dhananjay Singh
20
Inserting a Checkpoint During Recording-
Wednesday, May 22, 2013
Dhananjay Singh
21
Insert a Checkpoint After Recording-
Wednesday, May 22, 2013
Dhananjay Singh
22
ActionsAction is nothing but a logical portion to entire script file based on the requirement. Each and every action should have meaningful result. Types of Actions: 1) Regular (By default) 2) Reusable 3) External How to work with Actions: 1) Call to copy of Action 2) Call to Existing Action
Wednesday, May 22, 2013
Dhananjay Singh
23
Data Driven TestTesting the same application with multiple sets of data. How to use parameterization: Ex: Before parameterization Dialog(“”).Activate Dialog(“”).WinEdit(“name”).Set ”Axis” Dialog(“”).WinEdit(“).SetSecure”axisitt” Dialog””.Close
After Parameterization Dialog(“”).Activate Dialog(“”).WinEdit(“ name”).Set DataTable(”name”, dtglobalsheet) Dialog(“”).WinEdit(“). (””, dtglobalsheet) Dialog””.Close
Wednesday, May 22, 2013
Dhananjay Singh
24
Using Data Sheet (Global, Local & Location)-
Wednesday, May 22, 2013
Dhananjay Singh
25
Setting the Parameter Value-
Wednesday, May 22, 2013
Dhananjay Singh
26
Test Results Iterations-
Wednesday, May 22, 2013
Dhananjay Singh
27
Exception HandlingIt enables Quick test to detect and handle when unexpected error occurred during execution time. Types of Exception Handling: 1) Popup Exception Handling 2) Object State Exception Handling 3) Test Run Exception Handling 4) Application Crash
Wednesday, May 22, 2013
Dhananjay Singh
28
Object Identification-
By using object identification we can map “customer defined object” to “standard Class”. Two types of properties are their in object Identification: 1) Mandatory Properties 2) Assistive properties
Wednesday, May 22, 2013
Dhananjay Singh
29
Ordinal IdentifierBy using ordinal identifier options quick test able to identify an object under ordinal identifier. Three Components are available in ordinal identifier 1) Index 2) Location 3) Creation time
Wednesday, May 22, 2013
Dhananjay Singh
30
Smart IdentificationQuick test unable to identify the object, it is change randomly. To identify such object we need to use Smart Identification. Two properties are available in Smart identification They are1) Base Filter Properties 2) Optional Filter Properties
Wednesday, May 22, 2013
Dhananjay Singh
31
Synchronization Point-
Synchronization point maintains the time coordination between testing process and your application process. There are 4 types of synchronization points: 1) Sync 2) Wait, wait(5) or wait 5 3) Wait Property 4) Exist
Wednesday, May 22, 2013
Dhananjay Singh
32
Regular ExpressionsIt enables quick test to identify test string with varying value (varying means changing) Regular Expressions can be used in the following areas: 1) Check Points
2) In parameterization 3) Data Driven test 4) Actions 5) Exception Handling….etc
Wednesday, May 22, 2013
Dhananjay Singh
33
Using a Regular Expression-
Wednesday, May 22, 2013
Dhananjay Singh
34
Some Regular ExpressionsExpression
Char
Description
Period
.
Matches any single character
Asterisk
*
Matches zero to any number of occurrences of the preceding character
Plus
+
Matches one to any number of occurrences of the preceding character
Brackets
[A-Z][a-z]
Matches a range of characters
[0-9]
Matches a range of numbers
\w
Matches any alphanumeric character including underscore
\W
Matches any non-alphanumeric character
\d
Matches any digit
\d{4}
Matches exactly four digits
Digit
Wednesday, May 22, 2013
Dhananjay Singh
35
How to work with Environmental variables-
It is a special type of variable which is use to expose the data related to environment.
Environment Variables
Built In
defined
Internal
Wednesday, May 22, 2013
Dhananjay Singh
External
36
Kinds Of Actions Non Reusable Actions Reusable Actions External By default Actions are Non Reusable
Creating the Actions How to make actions reusable Iterations Action parameters (Input & Output) Input Browser("Browser").Page("Gmail: Email from Google").WebEdit("Email").Set parameter("name") Output Parameter("TotalValue") = Browser("Mercury").Page("ListOfSales").WebTable("Orders").GetCellData(NumTableRows,"Total")
Calling the Actions
Call to New Call to Copy Call to existing Difference in Call to Copy and Call to existing Properties of called function depends on the mode they are called Editable Mode and Read Only Mode
Understanding Expert View
Understanding and Using the Expert View
The following diagram shows how the same object hierarchy is displayed in the Expert View and in the Keyword View:
Expert View and Keyword View .. Cont
The table below explains how the different parts of the same step are represented in the Keyword View and the Expert View:
Understanding Checkpoint and Output Statements
Understanding Parameter Indications
Understanding Parameter Indications…. Cont
Before Parameterization: Browser("Welcome: Mercury").Page("Find a Flight:").WebList("toPort").Select "San Francisco“
After Parameterization: Browser("Welcome: Mercury").Page("Find a Flight:").WebList("toPort").Select DataTable("Destination",dtGlobalSheet)
Generating Statements in the Expert View
The Expert View helps you to generate statements in three ways:
➤ You can use the Step Generator to add steps that use methods and functions.
➤ You can manually generate VBScript statements that use methods to perform operations.
➤ When you start to type a VBScript keyword in the Expert View, QuickTest automatically adds the relevant syntax or blocks to your script, if the Autoexpand VBScript syntax option is enabled.
For...Next Statement For counter = start to end [Step step] statement Next
engers = Browser("Mercury Tours").Page("Find Flights"). WebEdit("numengers").GetROProperty("value") total = 1 For i=1 To engers total = total * i Next MsgBox "!" & engers & "=" & total
For...Each Statement For Each item In array statement Next
MyArray = Array("one","two","three","four","five") For Each element In MyArray msgbox element Next
Do...Loop Statement
Do [{while} {until} condition] statement Loop
engers = Browser("Mercury Tours").Page("Find Flights"). WebEdit("numengers").GetROProperty("value") total = 1 i=1 Do while i <= engers total = total * i i=i+1 Loop MsgBox "!" & engers & "=" & total
If...Then...Else Statement If condition Then statement ElseIf condition2 Then statement Else statement End If
engers = Browser("Mercury Tours").Page("Find Flights"). WebEdit("numengers").GetROProperty("value") If (engers < 4) Then Browser("Mercury Tours").Close Else Browser("Mercury Tours").Page("Find Flights").Image("continue").Click 69,5 End If
Invoke Internet Explorer to run the test :
Store the value of URL in „startURL‟ Variable from dtGlobal Sheet startURL = DataTable("url", dtGlobalSheet) Invoke internet Explorer set InternetExplorer = CreateObject("InternetExplorer.Application") To check whether i.e is open and maximised InternetExplorer.Visible = true Navigate the required URL in ie InternetExplorer.Navigate startURL
Functions
[Public [Default] | Private] Function name [(arglist)] [statements]
[name = expression]
[Exit Function] [statements] [name = expression] End Function Example Function MyFunction(text) MsgBox text End Function
How to call [Call] [Return value] Functionname (arglist) My Function (“Hi to all”)
Common functions used ….
Report Event : Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter] Example The following examples use the ReportEvent method to report a failed step. Reporter.ReportEvent 1, "Custom Step", "The -defined step failed." or Reporter.ReportEvent micFail, "Custom Step", "The -defined step failed."
Get Cell Data : object.GetCellData (Row, Column)
Get Current Row : DTSheet.GetCurrentRow Example row = DataTable.GetSheet("MySheet").GetCurrentRow Reporter.ReportEvent 1, "Row Number", row
Common functions used …. Get RO Property Method ( Returns a Variable ) : object.GetROProperty (Property, [PropertyData]) Example: ActualDisabledVal = Browser("Browser").Page("Page").WebButton(“Continue").GetROProperty("disabled") Exists Method : Example: Browser("Browser").Page("Page").WebButton(“Continue").Exists Msgbox : MsgBox “ Value displayed is correct” Or MsgBox ActualDisabledVal
Common functions used ……
Trim Function : Dim MyVar MyVar = LTrim(" vbscript ") MyVar = RTrim(" vbscript ") MyVar = Trim(" vbscript ")
' MyVar contains "vbscript " ' MyVar contains “ vbscript" ' MyVar contains “vbscript"
Import / Export Function : Imports the specified Microsoft Excel file to the run-time Data Table. DataTable.Import(FileName) Example: DataTable.Import ("C:\flights.xls") Saves a copy of the run-time Data Table in the specified location DataTable.Export(FileName) Example: DataTable.Export ("C:\flights.xls")
Inserting Steps Using the Step Generator
Setting the Testing Options
To set global testing options: Tools > Options or click the Options toolbar button.
Recovery Scenario
The Recovery tab displays a list of all recovery scenarios associated with the current test or component. It also enables you to associate additional recovery scenarios with the test or component, remove scenarios from the test or component
Object Repository vs. Descriptive Programming –what to use? There really is no “best way” Use the method that gives your company the best ROI, whether that be Object Repository (OR), Descriptive Programming (DP) or a mixture of both
OR Pros and Cons PROS: GUI Front end to examine all the objects in the repository Highlight in Application feature is great tool to walk the object tree No need to modify the script when object properties changes Easy to identify objects in AUT by Object Logical names Can be created independently from scripts
OR Pros and Cons CONS: Additional layer to maintain Unnecessary objects can be created Multiple s cannot concurrently save/write to the shared OR It won‟t eliminate the need for Descriptive Programming in most of cases
DP Pros and Cons PROS: It‟s a white box Compatible with different QTP versions Code portability is high Easy to mass update
DP Pros and Cons CONS: Lower Code Readability and requires more comments, like “what object is accessed” Potentially slower to create To highlight an object in the application requires utilizing the “Highlight” method
What is Object Repository? Object Repository is a place where QTP stores learned objects QTP uses default Object Identification properties: mandatory and assistive to learn objects into OR
Object Repository
Logical Name Properties
OR: Object identification default properties
Script playback using OR QTP finds the Object in Object Repository using object Logical Name and Object Hierarchy QTP retrieves Test Object properties from OR QTP searches actual application for the Object with the same properties as the OR Test Object and performs action
Script playback using Descriptive programming QTP searches the Application Under Test (AUT) for the Object using Descriptive properties and performs action
Descriptive programming – when and why? Consider using DP in following cases: Dynamic object properties Example: Link < Name> Same objects on every page Example: Buttons – Next, Back, Cancel, OK Lots of similar objects on one page Example: table with many First & Last name text boxes
Different ways to work with objects
Different ways to work with objects Example for enger 1 First Name
ChildObjects method – using Collection Object
ChildObjects method – using Collection Object Last Name fields are populated
TO, RO and .Object .GetTOproperty/SetToProperty refers to the properties stored in OR .GetROProperty property refers to the AUT Object property (Run-time) .Object.<property/method> refers to the AUT Object NATIVE properties/methods
Better names for Object Spy radiobuttons Run-Time NATIVE Object
Run-Time QTP (Test) Object
Object Run-Time Properties from AUT (GetRoProperty)
Run-Time “Native” Object Properties/Methods from AUT (.Object)
Test Object Properties from OR Set/GetToProperty
Regular Expressions in OR Example: Server independent Page object 1. Click on Property value to access RegEx
2. Click RegEx Icon
Regular Expressions in OR
Regular Expressions in OR
RegEx icon
Object Smart Identification Smart Identification is not Artificial Intelligence SI uses loose/unreliable object recognition It‟s recommended to disable SI for each and every page/window/control using the Tools->Object Identification dialog (Recording) Another way to disable SI: File -> Settings -> Run -> Check the "Disable Smart Identification during run session" check box (Run-Time)
Smart Identification (SI) Recording Options SI Checkbox
Smart Identification (SI) Run Option
SI Checkbox
A Brief Picture of Automation Framework…… Business Classes
Repositories
Generic Classes
Driver Script
Recovery Scenarios
Static Files(ini)
Test Data
Components of Framework Generic Classes Business Classes Repositories Test Data Recovery Scenarios Files Static Info Files (ini Files) Driver Script
Generic Classes These Classes are generic to any application and not dependent on applications logic. Example : 1. Functions for Launching and Exiting AdvantEdge 2006
Definition : Class
Functions and procedures will be defined here End Class Calling from script : ExecuteFile “Library File Path” „Load library files in to QTP Set Obj=New
„Declaring Object Obj.Function/procedure „Calling function/procedure Set Obj=Nothing „Removes Object from memory
Business Classes These Classes are specific to application‟s business logic. And changed according to the business logic of application. Example : 1. A function for Calculating the P&I Formula. 2. Filling borrower‟s information. Definition : Class
Functions and procedures will be defined here End Class Calling from script : ExecuteFile “Library File Path” „Load library files in to QTP Set Obj=New
„Declaring Object Obj.Function/procedure „Calling function/procedure Set Obj=Nothing „Removes Object from memory
Repositories Multiple repositories will be prepared for better maintenance. (.tsr files) Repositories will be loaded in to driver script dynamically depending on the object‟s requirement. Refer AE2006_LoadRep(Rep_Path) in AE_2006_Utils.vbs
Repository entries must maintain the standards defined in Coding Standards document.* Object identification script* must be used before adding any object to repository. All the OR‟s should be istered and should not be altered by the others with out permission.
Test Data All the Test data should be maintained in Excel files. (.xls files) Example : Borrower Information
And dynamically loaded in to the script during the script execution. Loading Dynamically : Use AE2006_LoadTData in AE_2006_Utils.vbs
(Or) DataTable.ImportSheet “Data File path”,”Source Sheet”,”Dest Sheet”
Recovery Scenarios Application related errors and interruptions in script execution should be identified and recovery operations must be defined in recovery files.(.qrs) Example : 1. Any unwanted popup message that may appear during the script execution.
These files must be loaded and activated before executing script. Activating / Deactivating Recovery.Enabled=true „Recovery operations activated Recovery.Enabled=false „Recovery operations disabled‟
Static Files All the global and application related static data must be maintained in Static files(.ini). Example : 1. A static variable that holds AdvantEdge application path. This will be referred in all the driver scripts. If application path changes simply we modify the value in „.ini‟ file, that will be reflected across all the driver scripts. Static file architecture : [Environment] Env_Variable=value Accessing global/static info Environment.LoadFromFile “path of Env File” Environment.Value(“Env_Variable”)
Driver Script Driver Script is the main automation script from where the remaining Automation Components will be called. In Driver Script we create Objects to the Business and Generic classes to access the functions and procedures of them. Calling a Function or Procedure from a class Set Obj=New Class_Name „Creates Object to Class Ret_val=Obj.MyFunction „Accesses a Function Obj.MyProcedure „Accesses a Procedure Set Obj=Nothing „Frees up from memory
Driver Script Cont… From the driver script repositories will be loaded dynamically by using a generic function . (Refer : AE_2006_LoadRep function in AE_2006_Utils.vbs)
Testdata will be called from test data files (.xls files) and it will be loaded in to the Datasheets during the test execution (run time). Importing a Sheet -DataTable.ImportSheet “Data File path”,”Source Sheet”,”Dest
Sheet”
Driver Script Cont… Recovery scenarios will be loaded in to the test from Recovery Scenario Files(.qrs files). These scenarios help running the driver script smoothly even if any interruptions occurred during the execution. Enabling and Disabling Recovery Mechanism--
Recovery.Enabled=True „To activate the scenarios Recovery.Enabled=False „To deactivate the scenarios
Driver Script Cont… If global data need to be accessed by functions or procedures, Driver Script calls that data from Static Files (.ini files) and es is it to the appropriate functioned and procedures. Loading an Static File --Environment.LoadFromFile “.ini file Path” Environment.Value(“Variable”)
„Loading file „accessing variable
In addition with Automation Components , driver script may contain Local Defined Functions and Procedures
ing Files Code template for writing the Scripts to improve readability and debugging capabilities. Refer AE2006_CodeTemplate.Doc
Coding standards document.(Yet to prepare) Refer AE2006_CodeStandards.Doc
Library mapping file to determine the usage of Library files. Refer AE2006_Libraries.xls
Responsibility Mapping file.(.xls) to determine who is working on what. Refer AE2006_Tracibility.xls
A start up Script to set the basic automation settings in QTP, like Object Identification settings and etc. Refer AE2006_StartUp.vbs
Automation Framework Reviewed…… Business Classes
Generic Classes
Driver Script
Repositories
Recovery Scenarios
Static Files(ini)
Test Data
Comments & QueriesQueries are always welcome.
Wednesday, May 22, 2013
Dhananjay Singh
98