HP QTP

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

  1. How to do parameterization in UFT/QTP
  2. How to do smart identification in QTP
  3. 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

1 Recovery scenarios manager
1 Recovery scenarios manager

2.       Click on below marked icon. Select the trigger (here is Pop up window)

2 Recovery scenarios trigger
2 Recovery scenarios trigger

3.       Now record the trigger – if required Regular expression can be added. It will add window title automatically.

3 Recovery scenarios trigger config
3 Recovery scenarios trigger config

4.       Now select the recovery operation.

4 Recovery scenarios trigger operation
4 Recovery scenarios trigger operation

5.       After recovery operation go to post recovery operation as copied

below

5 post Recovery scenarios
5 post Recovery scenarios                                                                                    How to do smart identification in QTP
Smart identification is needed when recorded script fails to recognize the application object (it may be due to multiple objects has same properties/values or recorded property value is changed)
Smart identification uses additional 2 set of object identification layers (1. Base filter properties 2. Optional filter properties) apart from regular mandatory, assistive properties.
1.       To get smart identification enabled – navigate Tools > Object identification.
1 object identification
2.       On object identification window – click on configure to add 1. Base filter properties 2. Optional filter properties as shown below.
2 object identification properties                                                            Descriptive programming in UFT
What is Descriptive Programming?
Descriptive programming is a way writing and implementing QTP scripts by avoiding the object repository. Usually Non – Descriptive programming access this object repository, where the required object’s properties and values are stored, and execute the scripts.
While in Descriptive programming, the object properties and values are directly written in the code so no need to access the object repository while script execution time.
For example.
If QTP script needs to close a browser the following descriptive program can be used and it can close any single open browse no matter what is the content or name of the browser.
Browser(“micClass:=Browser”).close
What are the common ways that the Descriptive Programming scripts can be written?
1. Static Descriptive Programming
Here the object properties and values are directly written in the code assuming that we know the expected properties and values.
For example.
If scripts wanted to input user name and password and click ok button to login to an application.
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“type:=text”,”name:=username”).set “– USERNAME”
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“type:=text”,”name:=password”).set “PASSWORD”
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebButton(“type:=Button”,”name:=Login”).set “LOGIN”
2. Dynamic Descriptive Programming
Here the object properties and values collections are created and used while scrip execution time
‘ this is to declare the object variable
Dim oDesc
‘to create an blank description
Set oDesc = Description.Create
Now assign values to the blank description in “oDesc”
oDesc(“type”).value= “text”
oDesc(“name”).value= “username”
now implement it in code as below
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(oDesc).Set “– USERNAME”
Note: Dynamic Descriptive Programming is really helpful when you want to handly an array of objects and child objects.

 

 

 

 

 

 

Leave a Reply