QTP_CourseMaterial (1).docx
description
Transcript of QTP_CourseMaterial (1).docx
TS Technologies
Quick Test Professional Course
FOR
Test Automation Aspires
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 1
Introduction to Test Automation
Functional Testing / Regression Testing
When to automate
When Application is stable
As early as possible
Multiple Environments
What to automate
Regression scenarios
Positive scenarios
Complex scenarios
Software Development Life Cycle
Requirement Gathering
Analysis and design
Coding
Testing
Release
Maintenance
Launching QTP
To launch QTP, In Start Menu, Choose Programs > Quick Test Professional Folder > Quick Test Professional
The first time you start QTP, the Add-in Manager dialog box opens. It displays list of all installed add-in along with license expiry date.
QTP will remember the add-ins you load so that the next time you open QTP the add-ins you selected in the previous session are selected by default.
If you do not want this dialog box to open the next time you start QTP clear the Show on startup check box. Click OK.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 2
Recording Modes
QTP supports 3 types of recording modes
1. Context Sensitive or Normal Mode
2. Analog
3. Low Level
Context Sensitive Recording mode
•Normal recording mode is also called Context Sensitive Mode
•It is the default mode of recording which takes full advantage of Quick Test Professional's test object model.
•It recognizes objects in application regardless of their location on the screen.
•It records the objects in your application and the operation performed on them
Example of Context Sensitive Recording
Dialog("Login").WinEdit("Agent Name:").Set "ashish”
Parent, Child Object, operation and data
Dialog("Login").WinEdit("Agent Name:").Type micTab
Analog Recording Mode
QTP’s Analog recording is captured as Tracks and stored in the directory of your test
It is useful for recording operations that cannot be recorded at the level of an object. E.g., A signature produced by dragging the mouse In Analog mode you can record
1) Record Relative to screen &
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 3
2) Relative to window
When analog operation are confined to just one window, use relative to window when your analog operation involve multiple screens like dragging and dropping an object from one window to other use the screen option
This mode records exact mouse and Key Board operations you perform in relation to the screen /Application Window. This mode is useful for the operation which you can record at Object Level, such as drawing a picture, recording signature.
This file is stored with your action in which these Analog Steps are created. The Step recorded in Analog mode cannot be edited within QTP.
In analog recording mode, Quick Test Professional records and tracks every movementof the mouse as you drag the mouse around a screen or window
Low Level Recording Mode
This mode enables you to record on any object in your application, irrespective of QTP recognizes the specific object or the specific operation.
This mode records at the object level and records all run-time objects as either Window or WinObject test objects.
It is used when the exact coordinates of the object are important for your tests. A good example would be hash maps where clicking different sections of a picture takes you to different links
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 4
Used when recording tests in an environment (or on an object) not recognized by QTP
Low level mode records the x,y coordinates of any clicks
Summary Recording modes
Analog recording and low-level recording require more disk space than normal recording mode.
For Analog mode, screen positions during the record and run time needs to be identical otherwise script fails
Use analog recording or low-level recording only when normal recording mode does not accurately record your operation.
At times QTP automatically switches to low level mode while recording objects or environments not supported by QTP
Recording Advantages and Disadvantages
Advantages
No expert / experience are required for recording. Automatic test object creation when recording. Help to learn the objects and create the scripts. Can add checkpoints easily
Disadvantages
Data is bind with the scripts Less flexible for reuse Need to add the comments our own
QTP IDE
The Start Pagedescribes the new features in this releaseincluding links to more information about these features.
It also provides links to Process Guidance, a tool that offers best practices for working with QTP.
You can open a document from the list of Recently Used Files, or you can click the buttons in the Welcome! area to open new or existing documents. If you do not want QTP to display the
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 5
Start Page when you next open QTP,select the "Don’t show the Start Page window on startup" check box.
When you select this option, the Start Page is also automatically hidden for the current QTP session as soon as you open another QTP document. To display the Start Page again, select View > Start.
Title Bar Displays the name of the active document. If changes have been made since it was last saved, an asterisk (*) is displayed next to the document name in the title bar.
Menu Bar displays menus of QTP commands.
Toolbars contains buttons to assist you in managing your document
Document Tabs Enables you to navigate open documents
Keyword View Displays test steps in a graphical representation
Expert View Displays test steps as a VB Script line.
Active Screen Provides a snapshot of your application as it appeared when you performed a certain step during the recording session.
Data Table Assists you to parameterize your test.
Test Flow Displays the hierarchy of actions and action calls in the current test, and shows the order in which they are run.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 6
Test object, Run Time Object
A test object is an object that QuickTest creates in the test to correspond to (represent) the actual object in the application.
QuickTest uses the stored information about the object during the run session to identify and check the object.
A run-time object is the real (actual) object in the application or Web site on which methods are performed during the run session.
Object Model
An object model is a structural representation of software objects (classes) that comprise the implementation of a system or application. An object model defines a set of classes and interfaces, together with their properties, methods and events, and their relationships.
We can use QTP Automation object Model to write scripts, that automate our QTP operations.
QTP Automation object model provides objects, methods and properties that enable us to control QTP from another application.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 7
Object Identification
QTP also uses a "human" like technology for object identification
During recording QTP learns the properties of a GUI object on which operation is performed.
During Run-Time QTP compares the stored object properties with actual properties of object available on screen and uniquely identifies an object independent of its location on screen
The stored object and together with its properties is called TEST Object
During Run-Time, the actual object available on the application under test is called Run-Time Object This is Quick Tests "Test Object Model"
Smart Identification
If the usual object identification process fails, QTP triggers Smart Identification, which is more flexible mechanism for identifying objects provided it is enabled in Object Identification settings.
Smart Identification uses two categories of properties 1) Base Filter Properties & 2) Optional Filter Properties
Base Filter Properties It contains the most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object
If the usual object identification process fails, QTP triggers Smart Identification, which is more flexible mechanism for identifying objects provided it is enabled in Object Identification settings.
Smart Identification uses two categories of properties 1) Base Filter Properties & 2) Optional Filter Properties
Base Filter Properties It contains the most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object
Optional filter properties. Other properties that can help identify objectsQuick Test "forgets" the learned test object description and creates a new object candidate list containing the objects that match all of the properties defined in the Base Filter Properties list.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 8
QTP the Uses Base Filter Property to reduce the Object Candidate list
The idea is to narrow down only one object matching the some or all of the saved description properties
If smart identification is invoked during a test run,in the test results tree a warning message is generated indicating smart identification was invoked and a smart identification step is inserted.
Enable the Smart Identification
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 9
Change the Object Identification Properties
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 10
Object Repository
It is repository that allows storing the test object and its indefinable properties.In QTP there are two types of repository
1. Local repository this is also called per action repository and associate with the action only.
2. Shared repository can be shared across various actions
Object Repositories Features
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 11
Cut
Copy
Paste
Delete
Rename
Filter objects
Edit -> Find and Replace
Add objects to local
Object Spy
Define New Objects
Highlight in application
Locate in repository
Click on update application
Export local objects (Convert into shared)
Create Shared Object Repository
All repositories are local by default.
To create a Shared Object Repository, in the Object Repository Dialog Box, Click File > Export Local Objects
Repository files have an extension .tsr
Give a suitable name say “global" and save The Shared Repository File is now created
Associate Shared Object Repository
How to associate Shared Object Repository in QTP
We can associate a Shared Object Repository in three ways
1. Using Associate Repository
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 12
2. During Runtime
3. Using Action Properties
1 Using Associate Repository
• Go to Resources Menu>Associate Repository> Click on Add
• Select / Location of Repository file path > Click Open
• Associate with Action > Click on OK
2 During Runtime
• repositorycollection.Add “Repository file path”
3 Using Action Properties
• Right click on Expert View > Go to Action > Action Properties
• Select “Associated Repositories” tab > Click on Add >Select / Location of Repository file path
• Click Open> Click on OK
Copy to Local
To copy an object to the local object repository:
• In the Object Repository window, select an object from a shared object repository that you want to copy to the local object repository. Objects in a shared object repository are colored gray. You can select more than one object to copy, as long as the selected objects have the same parent objects.
• Choose Object > Copy to Local or right-click the object(s) and choose Copy to Local. The object(s) (and parent objects) are copied to the local object repository and are made editable.
Edit- Shared Object Repository
You can use the Object Repository Manager to Edit a Share Repository.
Select Resources > Object Repository Manager .Open the Object Repository we created “global"
By default repository is opened in Read-only mode. To enable editing click File > Enable Editing
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 13
Once editing is enabled you can all the operations like cut, copy, paste, rename objects etc. that you can also do in Object Repository
Using Object Repository Manager is you can compare two Object Repositories .QTP will give you a static's of what's unique and common in both the repositories
You can use the Object repository merge tool to merge two repositories into one
Difference between Local and Shared
Local Object Repository (LOR)
1. Every action has its own.
2. LOR cannot be accessed as separate file.
3. Modify objects using Object Repository Window.
Shared Object Repository (SOR)
1. All actions use same OR
2. SOR is accessible as separate file(s).
3. Modify objects using Object Repository Manager.
Global or Shared Object Repository is preferable when application is dynamic and object descriptions change frequently
Between Shared and local object repository, shared object repository is more commonly used in automation projectsBut it has maintenance and administration overheads as compared to local object repository.
Shared object repository occupies less memory than local object repository
We cannot remove a local object repository with its test script
We can remove a shared object repository with test script
The objects in the local object repository are editable.
Key functions of the ORM
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 14
Create .tsr file Open in ORM record script and save file as .tsr file
Import Form XML
Find and Replace
Compare
Merge Repository
Navigate and learn
Editing a Shared Object Repository
You can use the Object Repository Manager to Edit a Share Repository.
Select Resources > Object Repository Manager .Open the Object Repository we created “global"
By default, Repository is opened in Read-only mode. To enable editing click File > Enable Editing
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 15
Once editing is enabled you can all the operations like cut , copy , pate , rename objects etc. that you can also do in Object Repository
Using Object Repository Manager is you can compare two Object Repositories .QTP will give you a static's of what's unique and common in both the repositories
You can use the Object repository merge tool to merge two repositories into one
Keyword driven methodology
Generating Tests Manually through Expert view
Generating Steps through Keyword view
Generating statements through Step Generator
Generating Steps through Keyword view
Add the object using OR Click on the keyword view where you want to Enter the step use the drop down to select the operation on the test object.
Generating statements through Step Generator
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 16
Add the object using OR
Click on the keyword view and Click on Step Generator
Enter the steps, function or utility objects
Key Terms: Checkpoints Output value
Check Point
A checkpoint checks specific values or characteristics of a page, object, or text string and enables you to identify whether or not Web site or application is functioning correctly. A checkpoint compares the value of an element captured in your test when you recorded your test, with the value of the same element captured during the test run.
Output value
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 17
An output value is a value retrieved during the run session and entered into your Data Table or saved as a variable or a parameter.
Iteration
Each run session that uses a different set of parameterized data is called iteration.
Check point Types
Standard Checkpoint
Text Checkpoint
Text Area Checkpoint
Bitmap Checkpoint
Database Checkpoint
Accessibility Checkpoint
XML Checkpoint (From Application)
XML Checkpoint (From Resource)
Page Checkpoint
Image Checkpoint
Table Checkpoint
Accessibility Checkpoint identifies areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines.
Page Checkpoint checks the characteristics of a Web page. For example, you can check how long a Web page takes to load or whether a Web page contains broken links.
Database Checkpoint checks the contents of a database accessed by your application.
XML Checkpoint checks the data content of XML documents in XML files or XML documents in Web pages and frames.
Text/Text Area Checkpoint:
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 18
In the Text/Text Area Checkpoint Properties dialog box, you can specify the text to be checked as well as which text is displayed before and after the checked text. These configuration options are particularly helpful when the text string you want to check appears several times or when it could change in a predictable way during run sessions.
Table and DB Checkpoints:
By adding table checkpoints to your tests or components, you can check that a specified value is displayed in a cell in a table on your application.
By adding database checkpoints to your tests or components, you can check the contents of databases accessed by your application. The results displayed for table and database checkpoints are similar.
• Page Checkpoint: A Standard Checkpoint created for a web page can be called a Page Checkpoint. It is used to check total number of links & images on a web page. Page Checkpoints can be used to check Load Time i.e. time taken to load a web page.
• Bitmap Checkpoint helps a user in checking the bitmap of an image or a full web page. It does a pixel by pixel comparison between actual and expected images.
• Image Checkpoint enables you to check properties like source file location of a web image. Unlike, Bitmap Checkpoint you cannot check pixels(bitmaps) using image checkpoint.
• Text Checkpoint is used to check expected text in a web-page or application. This text could be from a specific region of the application or a small portion of text displayed
• Accessibility Checkpoints verifies compliance with World Wide Web Consortium (W3C) instructions and guidelines for Web-based technology and information systems. These Guidelines make it easy for disabled to access the web.
• Database Checkpoint creates a query during record time and database values are stored as expected values. Same query is executed during run time and actual & expected values are compared.
• In Table Checkpoint you dynamically can check the contents of cells of a table (grid) appearing in your environment. You can also check various table properties like row height, cell width and so on. Table Checkpoint is similar to Database Checkpoint
• Using XML Checkpoints you can verify XML Data ,XML Schema, XML Data
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 19
Table Check Points
Web Advance Options
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 20
Synchronization
To cause to occur or operate with exact coincidence in time or rate: We synchronized our watches.
Static Synchronization
Inserting Wait Statement Increasing Tool Default Synchronization Time
Synchronization point is nothing but time interface between Tool and Application build. Generally Synchronization point is to give waiting time to the tool before executing next step in Test script
Dynamic Synchronization
Inserting Synchronization Point Sync method (only for web) Selecting appropriate method
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "xxxx"
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 21
Dialog("Login").WinEdit("Password:").SetSecure "50b6fa25bca091b2921db5b2008b7e2db9c01c3b"
Dialog("Login").WinButton("OK").Click
Wait(5)
'Set Global Synchronization to 2 Secs.
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111114"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "London"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Type "A"
Window("Flight Reservation").WinEdit("Name:").Set "xxxx"
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 10000
'Error will occur here.
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Change global sync time
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 22
Parameterization
Data Driven Testing through Data Table Data Driven Testing through Loop statements Dynamic Test Data Submission through Looping Importing Test Data from External files (Text and Excel Files) Creating a Database, Tables and Entering Data
Data Driven Testing using Data Table Methods
We can use the datatable import method to fetch the data from xls file to run time table. See the below code
Datatable.Import "c:\FlightData.xls"
rowcount = Datatable.GetRowCount ‘ Get the row count
'Check the settings Run -> run for only 1 iteration
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 23
For cnt = 1 to rowcount
.
.
.
Datatable.SetNextRow‘ Move to next row
Next
Data Driven Testing using Text file
'ForReading 1 Open a file for reading only. You can't write to this file.
'ForWriting 2 Open a file for writing.
'ForAppending 8 Open a file and write to the end of the file.
Dim fso, f1, ts
ConstForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
'fso.CreateTextFile ("c:\test1.txt")
'Set ts = fso.OpenTextFile("c:\test1.txt", ForWriting, True)
'For i = 0 to 5
' ts.writeline "Hello world "&i
' ts.writeblanklines 3
'
'Next
'ts.Close
Data Driven Testing using Excel file
Set ExcelObj = CreateObject("Excel.Application") ‘Create Excel Object.
ExcelObj.Workbooks.Open "C:\Test.xls" ‘ Create the workBook
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 24
Set NewSheet = ExcelObj.Sheets.Item(1) ‘ Get the reference of first sheet
'Write data to Excel Sheet
NewSheet.Cells(2,1) = " QTP Training"
NewSheet.Cells(2,2) = "Passed"
'Retrieve data to Excel Sheet
sScriptName = NewSheet.Cells(2,1)
sStatus = NewSheet.Cells(2,2)
msgbox(sScriptName)
msgbox(sStatus)
ExcelObj.ActiveWorkbook.Save ‘ Save the work book
ExcelObj.Application.Quit‘ Close the Excel
Set ExcelObj = Nothing ‘ Make reference as Null.
Actions
Action:
Set of Statements for performing a Task(s) We divide our test into actions to streamline the process of testing.
Purpose of Actions:
For understandability
For reusing components
Types of Actions:
1) Non Re usable actions
2) Re usable actions
3) External actions
Operations on Actions:
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 25
Splitting Actions Renaming Actions Deleting Actions Calling an Action 1) Call to Action 2) Insert Call to New action Copying an Action : Insert Call to copy -From the same Action & Other Actions Making an Action Reusable/Non Reusable
Creating an Action:
Insert>call to new action>enter name of the action>click ok Steps:
1. Create required actions (exlogin, insert, delete)
2. Prepare Scripts for those actions.
Splitting an action:(Creating Independent actions or Nested action)
Navigation: Place cursor in desired location>Edit menu>action>split action>Enter Action 1 name & action 2 name.
Steps:
1. Generate total test in the default action
2. Split into meaningful actions.
Note: At a time we can split one actions into 2 actions.
Renaming actions:
Select desired action in action drop down box> edit menu>action>rename action>modify the name>click ok.
Deleting Actions:
Select desired action in action drop down box>edit menu>action>delete action>confirm deletion.
Calling an action:
Insert>call to existing action>browse path of the test>select desired action>click ok.
Note: U can’t edit
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 26
Copying an action:
Insert>call to copy of action>browse path of the test>select desired action>click ok.
Note: we can edit this action.
Making an action reusable:
Select Non Reusable action >edit >action>action properties>check reusable action check box >click ok.
Transaction
You can measure how long it takes to run a section of your test by defining transactions.
You define transactions within your test by enclosing the appropriate sections of the test with start and end transaction statements.
For example, you may want to note the time taken to book a flight
In QTP, select the appropriate statement where you want to start your transaction.
Select Insert Start Transaction.
Start Transaction Dialog Box opens
Give the transaction a suitable name, say "Booking Time"
A start transaction statement is added in the test
Select the statement where you want to end the transaction
Click Insert > End Transaction
End Transaction Dialog Box Opens with the list of all available transactions
Click Okay. An end transaction statement is added
In results, the end transaction statement gives the time taken to insert the order
Transactions can be inserted anywhere in the script
There is no limit to the number of transactions that can be added to a test.
You can also insert a transaction within a transaction
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 27
Transaction name should not contains the spaces
End Transaction Dialog Box Opens with the list of all available transactions
Click Okay. An end transaction statement is added
Reporter Event
Associated Methods
ReportEvent Method
ReportNote Method
Associated Properties
Filter Property
ReportPath Property
RunStatus Property
Description
The object used for sending information to the run results.
Reporter.ReportNote "Report Notes ."
Reporter.ReportEventmicDone, "Test Step1" , "Step Done..."
Print "Done = " &Reporter.RunStatus
Reporter.ReportEventmicPass ,"Test Step3", "Step Pass"
print "Pass = " &Reporter.RunStatus
Reporter.ReportEventmicWarning, "Test Step4", "Step Warning"
print "Warning = " &Reporter.RunStatus
Reporter.ReportEventmicFail ,"Test Step2" , "Step Fail"
print "Fail = " &Reporter.RunStatus
Mode Description
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 28
0 or rfEnableAll Default.
All reported events are displayed in the Run Results.
1 or rfEnableErrorsAndWarnings
Only event with a warning or fail status are displayed in the Run Results.
2 or rfEnableErrorsOnly
Only events with a fail status are displayed in the Run Results.
3 or rfDisableAll
No events are displayed in the Run Results.
0 or micPass:
If this step runs test passes which is shown in test report.
1 or micFail:
If this step runs test fails which is shown in test report.
2 or micDone:
Used to send message to the test report and does not affect status of test.
3 or micWarning:
Again, used to send warning message to the test report and doesnot affect status of test.
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected.
Including interactive debugging (msgbox, print)
control flow and integration testing,
log files
Monitoring (application, system)
Memory dumps
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 29
profiling
Statistical Process Control
Special design tactics to improve detection while simplifying changes.
• Break Point
• Step Into Each step at a time. F11
• Step Out Come out from the step to Shift F11
• Step Over Each function or statement at time F10
Maintenance of scripts
Update Run– QTP is having Update Run mode for updating test object descriptions, the expected checkpoint values, and/or the Active Screen images and values. Choose Automation >Update Run Mode for running the scripts in update mode. When QuickTest updates a test, it does not update parameterized values, such as Data Table data and environment variables.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 30
Maintenance Run- In Maintenance Run Mode, QuickTest Professional identifies discrepancies between the objects in the repository and those in your application and then offers a solution for updating your objects and steps in real time.
1-If object has changed and QTP can recognize using SIM, it directly updates the object without showing it to user
2-If QTP fails to recognize it, it throws an error
3-Changed checkpoints values are updated and Pass/Fail message is not shown in either case
4-User can decide before run which objects (test object, checkpoints output values and active screen) should be updated once a mismatch occurs
Maintenance Run Mode
1-If object has changed and QTP can recognize it using SIM, it offers to update or keep the original object with displaying the changed properties.
2-If QTP fails to recognize it asks the user to point to the object and then update either all properties/single property/add as new object or keep original properties
3-Changed checkpoint values are not updated and fails in case of mismatch
4-User is allowed to decide the change after QTP faces a change during run session.
Recovery Scenario
What is Recovery Scenario?While executing your scripts you may get some UNEXPECTED/UNPREDICTABLE errors. (like printer out of paper).
To "recover" the test (and continue running) from these unexpected errors you use Recovery Scenarios. Recovery Scenarios are used to recover the test from unexpected errors and continue with execution.
What is unexpected error?Unexpected error or exception is a unpredictable/unexpected error which occurs suddenly during execution of the script. These kinds of errors make your script fail/stop/paused.
Step in Recovery scenario
Trigger events
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 31
Pop-Up window
Object State
Test Run Error
Application Crash
Recovery Operations
Keyboard or Mouse Operation
Close Application Process
Function Call
Restart Microsoft Windows
Creating Recovery Scenarios
Associating Recovery Scenarios
Recovery Scenario –Events
Recovery scenario manger can handle following four events:
1. Pop-up window: To handle unwanted pop ups.
2. Object state: To handle object related errors at runtime.
3. Test run error: To handle vb script statement errors at runtime.
4. Application crash: To handle crashed applications at runtime.
Error handing v/s Recovery Scenarios
If you can predict that a certain event may happen at a specific point in your test or component, it is recommended to handle that event directly within your test or component by adding steps such as If statements or optional steps or "on error resume next", rather than depending on a recovery scenario. Using Recovery Scenarios may result in unusually slow performance of your tests.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 32
They are designed to handle a more generic set of unpredictable events which CANNOT be handled pragmatically.
Descriptive Programming
Static Programming
Dynamic Programming
Retrieving Child Objects /Collection objects
Creating Library files using Constants
Handling Dynamic Objects
Handling duplicate Objects
Static Programming
Static Programming in descriptive programming
• Code the description in the step.
• Object description is constant
• Property/ies should be able to identifies the object uniquely
• Property and values are separated by :=
• Multiple properties are separates by comma
Dynamic Programming
1) Create the object description
2) Retrieving the child objects
3) Use the ordinal Identifier to Identify the object
Create Object Description
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 33
Set oDesc=Description.Create()
oDesc("micclass").value="WinButton“
oDesc("text").value="OK“
Retrieving Child Objects
Set oDesc=Description.Create()
oDesc("micclass").value="WinButton“
Set oAll=Window("text:=Flight Reservation").ChildObjects(buttonDesc)cnt=oAll.count
msgbox "Total number of Buttons: "&cnt
For i=0 to cnt-1
msgboxoAll(i).getroproperty("text")
If oAll(i).Getroproperty("text")="FLIGHT" Then
oAll(i).Click End IfNext
Advantages of Descriptive Programming
Scripts are portable (we can run these scripts from any machine easily) Maintenance is easy (less amount of resources) We can start Test creation process even though Application is not ready. Allows handling the duplicate objects Handling the dynamic objects
VBScript
VBScript is a scripting language
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 34
A scripting language is a lightweight programming language
VBScript is a light version of Microsoft's programming language Visual Basic
VBScript is a server scripting language
In Internet Explorer it can also be used as a browser language
VBScript Data Types
VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.
At its simplest, a Variant can contain either numeric or string information.
A Variant behaves as a number when you use it in a numeric context and as a string when you use it in a string context. That is, if you are working with data that looks like numbers, VBScript assumes that it is numbers and does what is most appropriate for numbers. Similarly, if you're working with data that can only be string data, VBScript treats it as string data. You can always make numbers behave as strings by enclosing them in quotation marks (" ").
Variant Subtypes
Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of numeric information. For example, you can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time.
You can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories of information that can be contained in a Variant are called subtypes. Most of the time, you can just put the kind of data you want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.
Subtype Description
EmptyVariant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.
Null Variant intentionally contains no valid data.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 35
Boolean Contains either True or False.
Byte Contains integer in the range 0 to 255.
Integer Contains integer in the range -32,768 to 32,767.
Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long Contains integer in the range -2,147,483,648 to 2,147,483,647.
SingleContains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
DoubleContains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
Date (Time) Contains a number that represents a date between January 1, 100 to December 31, 9999.
StringContains a variable-length string that can be up to approximately 2
billion characters in length.
Object Contains an object.
Error Contains an error number.
VBScript Variables
A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. For example, you might create a variable called ClickCount to store the number of times a user clicks an object on a particular Web page. Where the variable is stored in computer memory is
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 36
unimportant. What is important is that you only have to refer to a variable by name to see or change its value. In VBScript, variables are always of one fundamental data type, Variant.
Option Explicit
If used, the Option Explicit statement must appear in a script before any other statements.
When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs.
Variant Subtypes
Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of numeric information. For example, you can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time.
You can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories of information that can be contained in a Variant are called subtypes. Most of the time, you can just put the kind of data you want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.
Naming Restrictions
Variable names follow the standard rules for naming anything in VBScript.
A variable name:
Must begin with an alphabetic character.
Cannot contain an embedded period.
Must not exceed 255 characters.
Must be unique in the scope in which it is declared.
Declaring Variables
You declare variables explicitly in your script using the Dim statement, the Public statement, and the Private statement. For example:
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 37
Dim Degrees, Fahrenheit
You declare multiple variables by separating each variable name with a comma. For example:
Dim Top, Bottom, Left, Right
You can also declare a variable implicitly by simply using its name in your script. That is not generally a good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run. For that reason, the Option Explicit statement is available to require explicit declaration of all variables. The Option Explicit statement should be the first statement in your script.
Scope and Lifetime of Variables
A variable's scope is determined by where you declare it. When you declare a variable within a procedure, only code within that procedure can access or change the value of that variable. It has local scope and is a procedure-level variable. If you declare a variable outside a procedure, you make it recognizable to all the procedures in your script. This is a script-level variable, and it has script-level scope.
VBScript Constants
A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants.
Creating Constants
You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values. For example:
Constant
ConstMyString = "This is my string."
ConstMyAge = 49
Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. You represent Date literals and time literals by enclosing them in number signs (#). For example:
ConstCutoffDate = #6-1-97#
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 38
You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running. For example, you might want to use a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts.
VBScript Operators
VBScript has a full range of operators. We can see below types of Operators
Arithmetic operators perform the mathematical operations.
Comparison operators compare the various sub data types if they have equivalence
Concatenation operators concatenate the strings
Logical operators perform the logical comparison of the data
ArithmeticDescription Symbol
Exponentiation ^Unary negation -Multiplication *Division /Integer division \Modulus arithmetic ModAddition +Subtraction -String concatenation &
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 39
ComparisonDescription Symbol
Equality =Inequality <>Less than <Greater than >Less than or equal to <=Greater than or equal to >=Object equivalence Is
LogicalDescription Symbol
Logical negation NotLogical conjunction AndLogical disjunction OrLogical exclusion XorLogical equivalence EqvLogical implication Imp
Operator Precedence
When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence. You can use parentheses to override the order of precedence and force some parts of an expression to be evaluated before others.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 40
Operations within parentheses are always performed before those outside. Within parentheses, however, standard operator precedence is maintained.
When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last. Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear. Arithmetic and logical operators are evaluated in the following order of precedence.
When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right.
Likewise, when addition and subtraction occur together in an expression, each operation is evaluated in order of appearance from left to right.
The string concatenation (&) operator is not an arithmetic operator, but in precedence it falls after all arithmetic operators and before all comparison operators.
The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine if two object references refer to the same object.
VBScript Conditional Statements
Running a statement if condition is true (Single line Syntax)
Running a block of Statements if Condition is true
Running Certain Statements if a Condition is True and Running Others if a Condition is False
Deciding Among Several Alternatives (IF, Else If…)
Executing a certain block of statements when two / more conditions are True (Nested If…)
Deciding among several Alternatives (Select Case Statement)
if (condition) statement1
If condition Then statements [Elseelsestatements ]
Ifcondition Then [statements][ElseIfcondition-nThen
Select Case expression [Case expressionlist-n
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 41
End If End If [elseifstatements]] . . .[Else [elsestatements]]End If
[statements-n]] . . . [Case Else [elsestatements-n]]End Select
Loops in VB Script
Loops Loop executes a sequence of statements which is specified once but which may be carried out several times in succession. VB Script allows four looping construct as shown below.
While … Wend
Do… Loop For… Next For each… Next
While condition
[statements]
Wend
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next
For Each element In collection
[statements]
[Exit For]
[statements]
Next [element]
Do...Loop: Loops while or until a condition is True.
While...Wend: Loops while a condition is True.
For...Next: Uses a counter to run statements a specified number of times.
For Each...Next: Repeats a group of statements for each item in a collection or each element of an array.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 42
Exercise
Input parameters names are Pswd.
Declare a constant MY_PASSWORD.
Declare a constant MAX_RETRY = 3.
Ifthepasswordiscorrectdisplay a micPassmessage.
Ifthepasswordistypedwrong more thenMAX_RETRY times, display a micFailmessage.
Use the Do..Loop(WhileorUntil).
Tip
Use theExitLoopstatement.
Functions
String Functions
Mathematical Functions
Date and Time Functions
Format Functions
Array Functions
Conversion Functions
VBScript Procedures
In VBScript, there are two kinds of procedures
In VBScript, there are two kinds of procedures
The Sub procedure
The Function procedure
The Sub procedure
The Function procedure
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 43
Sub Procedures
A Sub procedure is a series of VBScript statements (enclosed by Sub and End Sub statements) that perform actions but don't return a value.
A Sub procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure).
If a Sub procedure has no arguments, its Sub statement must include an empty set of parentheses ().
Function Procedures
VBScript Procedures
Sub Procedures
A Sub procedure is a series of VBScript statements (enclosed by Sub and End Sub statements) that perform actions but don't return a value.
A Sub procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure).
If a Sub procedure has no arguments, its Sub statement must include an empty set of parentheses ().
Function Procedures
A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements.
A Function procedure is similar to a Sub procedure, but can also return a value.
If a Function procedure has no arguments, the Function statement must include an empty set of parentheses.
A Function returns a value by assigning a value to its name in one or more statements of the procedure.
The return type of a Function is always a Variant.
The MsgBox and InputBox, are VBScript functions.
Rules for function
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 44
If not explicitly specified using either Public or Private, Sub procedures are public by default, that is, they are visible to all other procedures in your script.
The value of local variables in a Sub or a Function procedure is not preserved between calls to the procedure.
You can't define a Sub procedure inside any other procedure.
The Exit Sub, Exit Function statement causes an immediate exit from a Sub or Function procedure.
Any number of Exit Sub or Exit Function statements can appear anywhere in a Sub or Function procedure.
If not explicitly specified using either Public or Private, Sub procedures are public by default, that is, they are visible to all other procedures in your script.
The value of local variables in a Sub or a Function procedure is not preserved between calls to the procedure.
You can't define a Sub procedure inside any other procedure.
The Exit Sub, Exit Function statement causes an immediate exit from a Sub or Function procedure.
Any number of Exit Sub or Exit Function statements can appear anywhere in a Sub or Function procedure.
Function Procedures
To return a value from a function, assign the value to the function name.
If no value is assigned to name, the procedure returns a default value
A numeric function returns 0
String function returns a zero-length string ("").
A function that returns an object reference returns Nothing if no object reference is assigned to name
Variables in Functions
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 45
Variables used in Function procedures fall into two categories: those that are explicitly declared within the procedure and those are not.
Variables that are explicitly declared in a procedure (using Dim or the equivalent) are always local to the procedure.
Variables that are used but not explicitly declared in a procedure are also local unless they are explicitly declared at some higher level outside the procedure.
Option Explicit
Caution A procedure can use a variable that is not explicitly declared in the procedure, but a naming conflict can occur if anything you have defined at the script level has the same name.
If your procedure refers to an undeclared variable that has the same name as another procedure, constant, or variable, it is assumed that your procedure is referring to that script-level name.
To avoid this kind of conflict, use an Option Explicit statement to force explicit declaration of variables.
File System Object
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
Methods
Close Method (FileSystemObject)
Read MethodReadAll MethodReadLine MethodSkipLine Method
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 46
Write Method (FileSystemObject)WriteLine Method (FileSystemObject)WriteBlankLines Method
Read and write to file
ConstForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, Msg
Set fso = CreateObject("Scripting.FileSystemObject")
‘True means create the file if not exists.
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "Hello world!"
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
ReadTextFileTest = f.Read(5)
f.close()
AtEndOfLine
ConstForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfLine<> True
retstring = theFile.Read(1)
Loop
theFile.Close
ReadEntireFile = retstring
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 47
AtEndOfStream
ConstForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfStream<> True
retstring = theFile.ReadLine
Loop
theFile.Close
ReadEntireFile = retstring
ActiveX Data Objects
Allows to create the connection and send the SQL query
Fetch data from database.
Iterate through the record set.
Close all the connections
Set cnBiblio = CreateObject("ADODB.Connection")
' Set the Connection String.
cnBiblio.ConnectionString =
"DSN=QT_Flight32;DBQ=C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb;Driver=C:\WINDOWS\system32\odbcjt32.dll;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;”
cnBiblio.Open("DSN=QT_Flight32")
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 48
Set rcRecordSet= cnBiblio.Execute("SELECT order_number from Orders order by order_numberdesc")
rcRecordSet.MoveFirst
var_order_num = rcRecordSet.fields("Order_Number")
rcRecordSet.close
cnBiblio.close
setrcRecordSet = nothing
setcnBiblio = nothing
Regular Expression
Regular Expression in QTP allows to add the
Understanding & Using Regular Expressions
Handling Dynamic Objects
Using Regular Expressions in Checkpoints
Defining Regular Expressions
Regular expressions in Recovery scenarios
Regular Expression Object
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 49
Regular Expression Examples
Match any number
[0-9].*
Date dd/mm/yyyy
[0-9]{1,2}/[[0-9]{1,2}/[0-9][0-9][0-9][0-9]
12/12/2012 match
12/12/12 does not match
\d{1,2}/\d{1,2}/\d{2,4}
(W|L)in
This text is about Window and Linux operating system
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 50
^[A-Z][a-z]+ matches proper name
^[A-Z][a-z]+$
^[A-Z][a-z]*$
Check month is between 1 -12
[0-9]{1,2}/([0-9]|[1][0-2])/[0-9][0-9][0-9][0-9]
Date in format yyyy-MM-dd
(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])
Error Handling
Sources for error
Syntax Error Error in compiling and dry run
Coding Error /logical Error Debugging /watch window
Synchronization Wait, wait property, exist, enable, sync
No Graceful exit Exit Function, For, Test, Action
Overview on Error Handling
Error Handling Methods in QTP
On Error Statement
Recovery scenarios
Synchronization
Wait
Wait property
Verify with Exists Property
Exit Statement
on error resume next
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 51
‘On error goto 0
On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
MsgBox ("Error # "&CStr(Err.Number) & " " &Err.Description)
Err.Clear ' Clear the error.
Err Object
Err Object contains information about run-time errors.
Accepts the Raise and Clear methods for generating and clearing run-time errors.
Remarks
The Err object is an intrinsic object with global scope — there is no need to create an instance of it in your code. The properties of the Err object are set by the generator of an error — Visual Basic, an Automation object, or the VBScript programmer.
The default property of the Err object is Number. Err.Number contains an integer and can be used by an Automation object to return an SCODE.
When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it. To generate a run-time error in your code, use the Raise method.
The Err object's properties are reset to zero or zero-length strings ("") after an On Error Resume Next statement. The Clear method can be used to explicitly reset Err.
On Error Resume Next
Dim Msg
Err.Clear
Err.Raise 6 ' Generate "Overflow" error.
Err.Helpfile = "yourHelp.hlp"
Err.HelpContext = yourContextID
If Err.Number<> 0 Then
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 52
Msg = "Press F1 or Help to see "&Err.Helpfile& " topic for" & _ "the following HelpContext: " &Err.HelpContext
MsgBoxMsg, , "error: " &Err.Description, Err.Helpfile, Err.HelpContext
End If
Introduction, Framework
Record and replay also called linear
Data Driven Script run for different set of data set
Modular
Function Composition
Test script Modular frame work(Internal File )
Test Library Modular framework (External File Script + utility Library)
Hybrid Framework
Keyword Driven Framework
Goals of the Automation:
Application independent
Easy to Expand
Decouple test from data
Identify and abstraction of common functions
Decouple complex business functions
Structure scripts with minimal dependency
Process for design framework
Flow of the Creating Framework
Analyze the application and Test cases
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 53
Design and architecture
Create OR
Create functions
Create Library
Integrate
Dry run and Test
Keyword Driven Framework
In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure for design enhancement.
Keyword
Keywordcarries a specific meaning or action it intended to do.
Design
Design is the creation of a plan or convention for the construction of an object or a system as blueprints.
Architecture
Architecture is both the process and product of planning, designing and build.
Flow of the Creating Keyword Framework
Identify Keywords
Create the Functional library
Creating Folder Structure
Creating & Storing Automation Resources
Organizing & Managing Resources
Generating Driver Scripts
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 54
Integrate all
Dry run
Trainings offered @ TS technologies
1) Load runner11.0/11.5
2) Manual testing/QTP
3) Selenium testing with java basics
4) SOA Testing/ETL testing
5) QTP frame work designing Workshop
6) JAVA/.NET/FileNet/PHP
Advance training on Performance testing
1) Analysis & Performance tuning2) Sitescope & Wily Introscope3) Performance Center4) Jmeter/ Neoload 5) LR11 Protocol Based
Flex, Ajax, Citrix, web services
TS Technologies, Flat 303, Padmaja’s Raja Enclave, KPHB Main Road, OPP: RS Brothers, beside KS Bakers,(O)040-40202015,(M)9951180008,Hyd.
Ts technologies contact: 040-40202015, 9951180008, web: www.tstechnologies.co.in.Page 55