QTP – Create a Simple Script without Recording

If the QTP’s recording engine is used to record a test scenario, then the script will have following issues:

  1. Script will have hardcoded values
  2. No proper naming convention
  3. No modularity
  4. No reusability
  5. Maintenance is difficult
  6. Difficult to accommodate frequent changes
  7. Difficult to debug

How to overcome these problems?

Simple!!

Create your own script… do not use recorded script..

Let us create a simple hand coded script and then compare with the recorded one.

Recorded Script:

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("Agent Name:").Type  micTab 
Dialog("Login").WinEdit("Password:").SetSecure "4eece6099d2b0bb2783b322b99abefc8f36ecf1c"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Script created without Recording:

'Script  - "LoginLogout" the Flight application 
'Username and Password are parameterized through DataTable
' Purpose - Demonstrates creating script without Recording Engine
'Author - Seetaram Hegde
'Copyrights - All rights reserved

Dim uname, pwd
uname=DataTable.Value("username","Global")
pwd=DataTable.Value("password","Global")
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("LoginDialog").WinEdit("AgentNameEdit").Set(uname)
Dialog("LoginDialog").WinEdit("PasswordEdit").SetSecure Crypt.Encrypt(pwd)
Dialog("LoginDialog").WinButton("OKBtn").Click
Window("FlightReservationWin").WinMenu("Menu").Select "File;Exit"

Compare both the scripts:

Recorded script:

  1. No proper naming convention
  2. Test data is hardcoded

Script without recording:

  1. Proper naming convention is used
  2. Test data is parameterized
  3. Easy maintenance

How to create a script without recording?

  1. Create local repository / shared repository with proper logical name for each object (http://goo.gl/CFjj9/http://goo.gl/aQnNR)
  2. Parameterize Test Data from data table (http://goo.gl/LOfHX)
  3. Start typing the code… Dialog( –> press open bracket that shows the number objects available, then just select the required object
  4. Use appropriate actions such as Click, Set, Type, etc

Run both the scripts and view the results. It is even easy to analyze the results if proper naming convention is used in the object repository. If there is any need to execute the same test scenario for multiple iterations, we need to add just some more rows in the data table, but there is no need to copy and paste the same recorded script again and again.

I hope this gives a fair idea of how to create a simple hand coded script in QuickTest Professional (QTP).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.