WORKING WITH QTP

TestEveryThinG

Posts Tagged ‘QTP’

Compare bitmap file using QTP ( using Mercury.FileCompare object )

Posted by rajivkumarnandvani on June 17, 2010

Hi All,
We can use QTP in-build method for File compare with the help of Mercury.FileCompare.
Here I am going to describe how to use that.

Rem variable to store the location of the expected bitmap file
strstoreBMPfile = “D:\rajivkumarnandvani.bmp”

Rem variable to store the location of the actual bitmap file
strActBMPfile = “D:\rajiv\runtimebmpfile.bmp”

Rem Activate the window

Window(“Flight Reservation”).Activate

Rem Capture the actual bitmap image from the application during run-time
Window(“Flight Reservation”).Static(“Static”).CaptureBitmap strActBMPfile , True

Rem here True will overwrite the file
Rem here we write the function for compare the bitmap file using qtp inbuild method Mercury.FileCompare.
Rem Function FnCompareTwoBMPfiles
Rem Description: this function Compares two bitmap images
Rem input pathExpBMPfile path of Expected bmp file
Rem input pathActBMPfile path of Actual bmp file
Rem return value 1 if both file are same ; 0 if different

Function FnCompareTwoBMPfiles( byval pathExpBMPfile , byval pathActBMPfile)
rem create qtp file system object
Set objMercuryFilecompare = CreateObject(“Mercury.FileCompare”)
rem here we use binary compare
if objMercuryFilecompare.IsEqualBin( pathExpBMPfile , pathActBMPfile , 0,1) Then
rem if match then return 1
FnCompareTwoBMPfiles = 1
else
rem if does not match then return 0
FnCompareTwoBMPfiles = 0
end if
rem discard the object
Set objMercuryFilecompare = nothing
End Function

Rem now we call this function

if FnCompareTwoBMPfiles(strstoreBMPfile ,strActBMPfile) = 1 then
msgbox “ BMP file match”

else
msgbox “BMP file not match”
end IF
Rem same thing we can use for other files also.

Posted in QTP, WINDOWS | Tagged: , , , | 9 Comments »

VB Get All Web page text ( Including All Webelement )

Posted by rajivkumarnandvani on October 1, 2009

Hi All,

Some Time we have to check that particular text is present on page or not during automation. If we get the page outer HTML in QTP we can not  get the whole text of all element like frame , webtable . div.etc…

So i created a function which will  check that the given text is present on page or not If Text present on page it will return True else False

REM  ——-   Set page object     ———-
set objpage = Browser(“BrowserName”).Page(“Pagename”)

msgbox   VerifyTextPresentOnPage(objpage ,”rajiv” )

Function VerifyTextPresentOnPage(byval objpage , byval Textvalue )
On error resume next

REM ——- Create child object description
Set childobjdes = Description.Create()
childobjdes(“micclass”).value=”WebElement”
childobjdes(“html tag”).value=”.*[A-Za-z0-9].*”
childobjdes(“outertext”).value =”.*[A-Za-z0-9].*”

REM  ———-Create ALL child object
set allobj = objpage.ChildObjects(childobjdes)
REM  get all  web element  outer text from web page and store in output variable
For i=1 to allobj.count-1
output=  output   & allobj.Item(i).GetROProperty(“outertext”)
Next
REM  now compare the value if the given value find or not
If instr(1,lcase(output),lcase(Textvalue)) > 0  Then

rem return true if found
VerifyTextPresentOnPage= True
Else

rem return true if  not found
VerifyTextPresentOnPage= False
End If
On Error GoTo
0
End Function

Posted in QTP | Tagged: , , , | 34 Comments »

Close All Browser Except OLD One QTP VB

Posted by rajivkumarnandvani on May 13, 2009

Hi All,

Some time we required that Only OLD open Browser Window( Only for IE) will remain Open and rest of all shall be closed during QTP scripting. Here is the Function which will close the all open Browser except OLD Open browser (Work only for Internet Explorer using QTP)

Public function fn_CloseAllBrowserRemainingOLD

rem create Browser description object
Set brwsr=Description.Create
brwsr(“micclass”).value=”Browser”
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
If  browserCount >1  Then
do
Browser(“CreationTime:=1″).Close
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
loop  until  browserCount =1
End If

End Function

Posted in QTP, WEB | Tagged: , , | 6 Comments »

Execute the qtp scripts when the system is locked

Posted by rajivkumarnandvani on May 9, 2009

Change the following registry settings..
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest
Locate the key “SkipEnvironmentChecks”

By Default the value will be “0″
Change the value to “1″ and restart the QTP.
Now QTP can run even if the system is lock.

Posted in QTP | Tagged: , | 3 Comments »

Running DOS Commands QTP VB

Posted by rajivkumarnandvani on May 3, 2009

Running DOS Commands

You can run standard DOS commands in your QuickTest test or function using the VBScript Windows Scripting Host Shell object (WSCript.shell). For example, you can open a DOS command window, change the path to C:\, and run the DIR command using the following statements:

Dim oShell

Set oShell = CreateObject (“WSCript.shell”)

oShell.run “cmd /K CD C:\ & Dir”

Set oShell = Nothing

Posted in Miscellaneous, QTP | Tagged: , , , | Leave a Comment »

Importance of Parenthes when we call Function or Sub QTP

Posted by rajivkumarnandvani on May 3, 2009

Whenever you define a function with using argument always define the argument type by using ByVal OR ByRef Because if u not define the argument type by default it take ByRef

Parenthesis matter in QTP (and VBScript). And they surely make a difference. During debugging a function call. There was different behaviour between these two function calls:
foo(bar)
call foo(bar)
Passing an argument to a function surrounded by parenthesis means: “Protect me” or in other words: treat me as byVal even if it is defined in the function as byRef.

Example:
sub samplesub (a, b) ‘ a and b are by default handled as byRef
a = a + b
end sub

And this is happening when we call samplesub:
x = 1
y = 2
z = 4
samplesub x, y
samplesub (z), y
msgbox x ‘ displays “3″
msgbox z ‘ displays “4″ because z was passed as if it was passed byVal

The same applies when you call a function:

function samplefunc(c)
c = c^2-1
samplefunc = (c mod 2 = 1)
end function

q = 8
samplefunc q
msgbox q ‘ returns 63

‘ When you accidentally forgot to call:
p = 9
samplefunc(p)
msgbox p ‘ returns 9, because p is returned byVal

‘ With call:
r = 10
call samplefunc(r)
msgbox r ‘ returns 99, because r is returned byRef

‘ With call and argument protected:
s = 11
call samplefunc( (s) )
msgbox s ‘ returns 11, s is returned byVal

‘ And a last example of a function call with multiple argument with combined protection:
call multifunc( (IamProtected), IamUnprotected )

Rules in short:
A sub/function call with an argument in protected mode overrides a byRef in the function.
A sub/function call with an argument in unprotected mode is returned byRef by default unless it is overridden in the function by a byVal.
An literal or const is always returned byVal.

Syntax proposal:
OK, it is ugly, but if you use parenthesis because they are part of the call, you should use them with spaces between the first and last argument and no space between the function:

call f( a, b )

If you want to use arguments in protected mode, you should use no spaces between the parenthesis and the arguments, but do use them between the function/sub and the parenthesis belonging to the function/sub call:

f (a), (b)
or
call f( (a), (b) )

Posted in Miscellaneous, QTP | Tagged: , , , , | Leave a Comment »

Performance increase in table lookup functions QTP

Posted by rajivkumarnandvani on May 3, 2009

Using object properties instead of QTP standard functions will improve the performance of QTP tests significantly. In our case, we often want to lookup the location of a certain value in a WebTable. QTP provides several functions to read out data from a table, but is slow when used iterating the table (like two for loops, one iterating the rows, the embedded second one iterating the columns per row).

Example of a conservative way to do this:

Public Function LocateTextInTable(byRef tbl, textToFind, byRef row, byRef col)

For row = 1 to tbl.RowCount
For col = 1 to tbl.ColCount
If tbl.GetCellData(row, col) = textToFind then
LocateTextInTable = True
Exit function
End if
Next
Next

row = -1 : col = -1
LocateTextInTable = False
End Function

The crux is this: .GetCellData is not a very fast method and with a table, consisting of 30 rows and 10 columns, this method is iterated up to 300 times in the most worse case scenario (= text not found).

A faster way to retrieve the data is through the Document Object Model (DOM). This allows you to use the more native properties of an object with the sacrifice of some ease of use.

A table consists of row elements and each row element contains one or more cells. We can iterate them just the same way as we did with the function above:

Public Function LocateTextInTableDOM(byRef tbl, textToFind, byRef row, byRef col)

Dim objRow, objCell

row = 1 : col = 1

For each objRow in tbl.object.Rows
For each objCol in objRow.Cells
If objCol.Value = textToFind then
LocateTextInTableDOM = True
Exit function
End if
col = col + 1
Next
row = row + 1
Next

row = -1 : col = -1
LocateTextInTableDOM = False
End Function

Posted in Miscellaneous, QTP | Tagged: , , , | 3 Comments »

Work With List Box QTP

Posted by rajivkumarnandvani on May 3, 2009

When we use list box Object in QTP. QTP perform following operation on listbox . like

Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”

It select the value from List Box that value must be present in list box otherwise QTP give an error like that

“Cannot identify the specified item of the ListBox object. Confirm that the specified item is included in the object’s item collection.”

So before selection any value in list box Always insure the value you are going to select in list box must be present by use this method/Function

dim objListBox, sValuematch ,bTrue
set objListBox = Browser(“Browser”).Page(“Page”)..WebList(“ListBox”)
sValuematch =”Type Value that need to be check”
bTrue = fn_Valuematch_for_weblistbx(objListBox ,sValuematch )
if bTrue =True then
Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”
end if

REM*************************************************************************************************************
REM ” this function Check the value u define match With in WEBListbox or Not if match return true otherwise False
Public Function fn_Valuematch_for_weblistbx(byval m_listboxobject, byval m_valuematch)
”check is m_listboxobject object or not
If IsObject(m_listboxobject ) = true and IsNull(m_valuematch) = false Then
Dim m_Getallfield,m_arAllfield,m_val,m_actual
m_arAllfield = m_listboxobject.GetROProperty(“all items”)
m_arAllfield =Split (m_arAllfield,”;”)
For each element in m_arAllfield
If m_valuematch = element then ‘ compare the text
fn_Valuematch_for_weblistbx=true ” if value match then return true & exit thr loop
exit for
else
fn_Valuematch_for_weblistbx = false
end if
Next
else
print “Error wrong Parameter for function fn_Valuematch_for_listbx”,”Check paramenter value”
End If
End Function
REM*************************************************************************************************************

Posted in QTP, WEB, WINDOWS | Tagged: , , | 19 Comments »

Work With text box( Windows WinEdit box) QTP

Posted by rajivkumarnandvani on May 3, 2009

In most cases, double-clicking on a data input field is the preferable method of selection; furthermore, it is usually necessary versus a single mouse click on the object. Double –clicking selects the all of the data in that field so that it can be replaced with the new data. A single- click operation, may only place the cursor in the input control , selecting none of the existing data and normally activates the insert mode . Not good. The existing data is not replaced with the new value. In some applications where multiple words or value separated by spaces can lives in a single edit box. We have found the even double-clicking may not get all of the text selected and ready for replacement. In this case, the method that consistently ensures that all of the data is selected is this: navigate to control via keyboard control, such as tabbing, right arrow or mouse click. Once the cursor is placed into the control, record these keystrokes:

Ctrl + Home
Ctrl + Shift + End
Delete

Like
Dialog(“Login”).WinEdit(“Agent Name:”).Type micCtrlDwn + micHome + micCtrlUp
Dialog(“Login”).WinEdit(“Agent Name:”).Type micCtrlDwn + micShiftDwn + micEnd + micShiftUp + micCtrlUp

Posted in Miscellaneous, QTP, WINDOWS | Tagged: , | Leave a Comment »

Select Radio Button QTP

Posted by rajivkumarnandvani on April 29, 2009

Rem**************************************************************************************


Rem This function select the radio button with specified number of index
REM  Input objRadiobutton:= radiobutton object intenetexplorer exe || nIndex:= number of specifed radio button which need to be   rem select
REM  Output(ReturnType) := None
REM  Created:    07/April/2009    Rajiv Kumar Nandvani  ##
REM Changed:MM/DD/YYYY

REM***************************************************************************

Public Function fn_RadioButtonSelect( byref  objRadiobutton,byval nIndex)

sItems= objRadiobutton.GetROProperty(“all items”)
sItems=split(sItems,”;”)
nIndex =nIndex-1

If  nIndex =< (ubound(sItems) ) Then
objRadiobutton.select sItems(nIndex)
else
Print  “Please check  number of radio button”

End If

Rem  Clear All  the Refrences to the Objects
Set objRadiobutton =nothing
End Function

Posted in QTP | Tagged: , , | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 152 other followers

%d bloggers like this: