Thursday, February 23, 2012

Inserting picture in excel sheet using VBScript/ QTP

Following code can be used to insert pictures in to the excel file. All you need to give is the path of the excel file in which the picture to be inserted & the path of the picture file to be inserted.

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objworkbook  = objExcel.WorkBooks.Open("C:\exceltest.xls")
Set objworksheet = objworkbook.Worksheets(1)
Set objExcel = Nothing
Set objworkbook  = Nothing
Set objworksheet = Nothing
Set objusedrange = Nothing

Wednesday, February 22, 2012

Sorting an array using VBScript/ QTP

Following code can be used to sort an array using QTP. Let sortme is name of the array which is to be sorted. I have used "Bubble Sort" principle of sorting.

A) Descending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) > sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If

B) Ascending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) < sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If

Wednesday, February 15, 2012

Running Database Procedure using qtp

Following code can be used to execute the database procedure. Before proceeding you must know the connection-string to connect the database & the name of the procedure. If you dont know the connection-string of your database refer . This website provides an easy reference to connection-strings for various databases.

Set conn = CreateObject("ADODB.Connection")
Set adocommand = CreateObject("ADODB.Command")

conn.ConnectionString = "Connection-string of the running database"

Set adocommand.ActiveConnection = conn
adocommand.CommandText = "Name of the Stored Procedure"
adocommand.CommandTimeout = 30
adocommand.CommandType = 4



Set adocommand = Nothing
Set conn = Nothing

Thursday, February 9, 2012

Clicking at any point(x & y corodinates) on screen using qtp

Sometimes QTP do not identifies complex objects due to various reasons, in such case if you want to click on the unidentifiable object you can use following method. However you want to know the (x,y) position of that object in the browser/application.

Set obj=CreateObject("Mercury.DeviceReplay")
obj.MouseClick x,y,0

You can get the x & y coordinates of that object using the following code or you can use the approximation. This is also useful when QTP do not identify the methods associated/supported by any particular object.
e.g. There might be a webelement object which needs a click to activate, but QTP might not identify or support click method for that particular object then use following code to get the x & y coordinates of that object. Also note that the coordinates must be converted to integer subtype before passing into MouseClick method.

x= cint(x)
y= cint(y)

Set obj=CreateObject("Mercury.DeviceReplay")
obj.MouseClick x,y,0

Wednesday, February 8, 2012

Object Repository & Descriptive Programming together

Sometimes we need to use both QTP's own Object Repository and Descriptive Programming while defining complex objects. But this scenario do not works always.

The following care must be taken while designing scripts when you are using both Object Repository & descriptive Programming.

Scenario 1 : Parent object as Object Repository with child object as Descriptive Programming.
Browser("My Website").Page("micclass:=Page").WebEdit("micclass:=My Edit').Set "QuickTest"
'This code works properly

Scenario 2 : Parent object as  Descriptive Programming with child object as  Object Repository.

Browser("micclass:=Browser").Page("My Page").WebEdit("My Edit').Set "QuickTest"
'This code will generate error

Hence whenever you are using Object Repository & Descriptive Programming together take care that parent object should be from Object Repository & not from Descriptive Programming.

Maximize the Browser

If you are using QTP 9.2 or 9.5 or 11.0 version with Internet Explorer then following code should help to maximize/minimize or restore the browser window.

hwnd = object.Object.HWND
Set oWin = Window("hwnd:=" & hwnd)
'To maximize the application

'To restore the application

'To minimize the application

First post

Hello friends,

This is my first blog post :)

BTW I am a Software QA Engineer with expertise mainly in Automation testing.
Since long time I was thinking to create a space to record the challenges I faced while QTP testing when I was a beginner with solutions to them. I hope people who are planning to learn about HP QTP will find this blog useful.

thanks for vising my blog,

Navnath Patil