QTP – Record an end-to-end test scenario

by seetaram on October 2, 2011

Test automation is a process of automating end-to-end test scenarios. Although, the recording test steps using QTP looks much simple that becomes complex when the scenario has many steps as well as involves different kinds of objects.

According to me, to learn QTP we should start with a simple test then the recording should extend to a little more complex scenario. Once we are comfortable with recording, then go ahead and record much more complex scenario.

Objective of this post is to learn recording a bit complex scenario than the last one and try to understand different objects, script, etc.

Test Scenario: Flight – Insert a new order

  1. Open the Flight application
  2. Login with appropriate credentials (username / password)
  3. Click on New Order
  4. Fill in the Order form
  5. Click on Insert Order
  6. Close the application

Below is the code generated by QTP after recording the above test steps:

'Script "Inserts an Order into the Flight application
'Author - Seetaram Hegde
'Copyrights - All rights reserved

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").SetSecure "4e88a26da2bc6325ef384d8e5d82e53a03c50d42"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").ActiveX("MaskEdBox").Type "120212"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "Seetaram Hegde"
Window("Flight Reservation").WinRadioButton("Business").Set
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

In the above script, while recording type password as “mercury”, then QTP will convert it to some string and sets it using SetSecure.

Now, let us try to understand the script generated by the QTP.

  1. What are the objects involved in this script?
  2. What are the methods / functions used in this script?

Objects:

  • Dialog
  • Window
  • WinMenu
  • ActiveX(“MaskEdBox”)
  • WinComboBox
  • WinButton
  • WinEdit
  • WinRadioButton
  • WinButton

This end-to-end to scenario involved above objects. Since, Flight is a windows application all the objects are prefixed with “Win”.

When some test scenario on an AUT (Application Under Test) is recorded various objects particular to that application will be identified and used in the script. For example, if you click on a button while recording the script recorded will be the object hierarchy (Button might be located on a window+dialog box, then Window().Dialog().WinButton().click)plus the WinButton(buttonname).click.

Methods / Functions:

  • Set – Sets a value into an edit box
  • SetSecure – Sets the value for a password field
  • Select – Selects the value from a dropdown
  • Type – Inserts value into an edit box character by character
  • Click – Clicks on a button / link / image

This explains well the script, the objects contained in the script, and the methods / functions that are used in the script. So, what next? Go ahead and record the script, then replay it.. See the magic QTP does..

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email