Wednesday, October 10, 2007

qtp programmer

The software industry is at a level where the time spent to look down on earth seems crazy. Testing world is growing day by day and so the automation industry. QTP counts as one of the best available tools to be used for automation. But are we the users to use it we are the programmers to program it. Why just be happy with record and playback? Let's go ahead and learn all that makes QTP the best automation tool and us the best automation engineers.
Using Windows Shell scripts and the best of VB, let's take the biggest deal with QTP features.....


I start a code snippet "How to verify that a particular window appears at the center of monitor screen? "

' To verify that the 'X' window(.net application should be displayed at the center of the screen

intScreenabsx=SwfWindow("X").GetROProperty("abs_x")
intScreenabsy=SwfWindow("X").GetROProperty("abs_y")
intScreenHeight=SwfWindow("X").GetROProperty("Height")
intScreenWidth=SwfWindow("X").GetROProperty("Width")
blnCentered = IsWindowCentered(intScreenabsx,intScreenabsy,intScreenHeight,intScreenWidth)

If blnCentered= True Then
Reporter.ReportEvent micPass,"Test Step Passed","The window is displayed at the center of the screen"
Else
Reporter.ReportEvent micFail ,"Test Step Failed"," The window is not displayed at the center of the screen"
End If

Function IsWindowCentered(intABSX,intABSY,intHeight,intWidth)
Dim strComputer : strComputer = "." ' The local computer
Dim objWMIService ' objects to get the WMI service
Dim ItemsCollection ' objects used to get the collection of all items
Dim ObjItem
Dim intScreenHeight 'The actual screen resolution (height)
Dim intScreenWidth 'The actual screen resolution (Width)

'Following code is to get the the desktops resolution
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set ItemsCollection = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
For Each objItem in ItemsCollection
intScreenHeight = objItem.ScreenHeight
intScreenWidth=objItem.ScreenWidth
Next

'Verify whether the window is centered
If (cint(intABSX) +cint(intWidth/2)) =(cint(intScreenWidth/2)) And (cint(intABSY) +cint(intHeight/2)) =cint(intScreenHeight/2) Then
IsWindowCentered = True
Else
IsWindowCentered = False
End If
End Function

No comments: