If the QTP’s recording engine is used to record a test scenario, then the script will have following issues:
- Script will have hardcoded values
- No proper naming convention
- No modularity
- No reusability
- Maintenance is difficult
- Difficult to accommodate frequent changes
- 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:
- No proper naming convention
- Test data is hardcoded
Script without recording:
- Proper naming convention is used
- Test data is parameterized
- Easy maintenance
How to create a script without recording?
- Create local repository / shared repository with proper logical name for each object (http://goo.gl/CFjj9/http://goo.gl/aQnNR)
- Parameterize Test Data from data table (http://goo.gl/LOfHX)
- Start typing the code… Dialog( –> press open bracket that shows the number objects available, then just select the required object
- 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).