HP QTP
Basic knowledge required to work on QTP/UFT projects
1. Basic programming knowledge on VB scripting – just to modify the recorded scripts. QTP/UFT allows record/play back, using that application transactions can be recorded and later modified based on requirements. Need to learn usage of functions. Instead of functions, QTP/UFT inbuilt feature “reusable” actions can be used.
2. Looping and Parameterization – Parameterization is required to change the already recorded data. Basically the user id, password, input values to be entered in the AUT. To repeat a transaction, looping is used. For looping “For-Next” , “Do-while” etc are used
3. Object Spy & Object Repository– QTP developer can view the run-time/Application object properties and methods of any object in the application. This is helpful during debug mode and find out Dynamic objects. Object Repository is the place where recorded objects are stored by displaying the object properties and values. QTP developer can do some changes on values – using regular expression as an example to handle Dynamic objects.
4. Import / Export data sheet – This is used for very basic reporting where coding is done to store AUT values, some error validations and input values in QTP datasheet or already imported spreadsheet.
QTP/UFT related topics (please search below contents in my site)
- How to do parameterization in UFT/QTP
- How to do smart identification in QTP
- How to setup Recovery scenario’s in QTP/UFT
Select Case example for QTP script development
X = RandomNumber(1,4)
Select Case X
Case 1
msgbox ” number is 1″
Case 2
msgbox ” number is 2″
Case 3
msgbox ” number is 3″
Case Else
msgbox ” number is 4″
End Select
How to connect Oracle using QTP scripts.
Dim connectionMS, recordsetMS
Set connectionMS = createobject(“adodb.connection”)
Set recordsetMS =createobject(“adodb.recordset”)
connectionMS.open “Driver={Microsoft ODBC for Oracle};Server=QTPWorld; Uid=your_username;Pwd=your_password;”
recordsetMS.open “select * from yourtablename”,connectionMS
databaseValue = recordsetMS.fields.item(0)
msgbox databaseValue
Set connectionMS = nothing
Set recordsetMS = nothing
How to connect sqlserver using QTP scripts.
Dim connectionMS, recordsetMS
Set connectionMS = createobject(“adodb.connection”)
Set recordsetMS =createobject(“adodb.recordset”)
connectionMS.open”Driver={SQL Server};server=YourSqlServer;uid=YourUserName;pwd=YourPassword;database=dbname”
recordsetMS.open “select * from tablename”,connectionMS
databaseValue = recordsetMS.fields.item(0)
msgbox databaseValue
Set connectionMS = nothing
Set recordsetMS = nothing
How to connect MS Access using QTP scripts and display results
Dim connectionMS, recordsetMS
Set connectionMS = createobject(“adodb.connection”)
Set recordsetMS =createobject(“adodb.recordset”)
connectionMS.provider= “microsoft.jet.oledb.4.0”
connectionMS.open “C:\yourdatabase.mdb”
recordsetMS.open “select * from YourtableName”,connectionMS
databaseValue = recordsetMS.fields.item(0)
msgbox databaseValue
Set connectionMS = nothing
Set recordsetMS = nothing
QTP program to display odd and even numbers
‘ program to display odd numbers
Dim OddNum, o
o = Inputbox(“enter any value to check list of odd numbers in it”)
For OddNum = 1 To o Step 2
print OddNum
Next
‘ program to display even numbers
Dim EvenNum, e
e = Inputbox(“enter any value to check list of even numbers in it”)
For EvenNum = 2 To e Step 2
print EvenNum
Next
How to do string reverse in qtp
How to do string reverse in qtp
Dim String1, String2, StringLength, i
String1 = “Happy Valentine’s Day”
StringLength = len(String1)
For i = StringLength To 1 step -1
String2 = String2 & mid(String1, i, 1)
Next
Msgbox String2
String reverse in qtp
Dim String1, String2, StringLength, i
String1 = “Shalima Prakash”
StringLength = len(String1)
For i = StringLength To 1 step -1
String2 = String2 & mid(String1, i, 1)
Next
Msgbox String2
19 regular expression methods in UFT/QTP
1. Period (.) is used to represent or replace any symbol except new line
2. Asterisk (*) represents zero or more occurrences
3. Caret (^) sign instructs beginning of the line
4. Dollar ($) sign instructs end of line
5. \b instructs Word boundary
6. ? instructs zero or more occurrences
7. + instructs one or more occurrences
8. {} represents exact number of occurrences
9. [] represents any character in the set
10. [^] represents any character NOT in the set
11. () represents Group
12. I represents Or
13. \n represents new line
14. \W represents any non-Word character
15. \d is any digit
16. \D is any non-digit
17. \s is any white space character
18. \S is any non- white space character
19. \ is escape special character
How to setup Recovery scenarios in QTP/UFT
To handle unexpected errors, popup etc , QTP/UFT uses this feature (also when existing code is not designed to handle this issue)
1. Navigate to Resources > Recovery Scenario Manager
2. Click on below marked icon. Select the trigger (here is Pop up window)
3. Now record the trigger – if required Regular expression can be added. It will add window title automatically.
4. Now select the recovery operation.
5. After recovery operation go to post recovery operation as copied
below