Professional Documents
Culture Documents
Working With QTP
Working With QTP
Working With QTP
Some Time we have to Check that particular Cell Value Exist or Not and required the Cell
address
rem this function return the first find Cell address value of your Excel sheet & Change
Color of Cell find value
rem input parameter xlFilePath := xls file path || FindValue =value which need to be find
dim sXLpath , FindValue ,getCellAddress
sXLpath =”C:\RajivKumarNandvani.xls” rem define xls file path
FindValue =”Rajiv” rem check rajiv in cell exist or not
getCellAddress = FindCellAddress(sXLpath ,FindValue )
msgbox getCellAddress
Do
Exit function
End If
rem if not found then return the Empty
FindCellAddress=”NOT FOUND”
sXLpath =”C:\TESTXML\Rajiv.xls”
myArray = GetALLColumn(sXLpath)
Next
GetALLColumn =AllColumn
Set objectSheet =nothing
Set ObjAppExcel =nothing
End Function
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*************************************************************************
**
call fn_RadioButtonSelect(objRadiobutton,nIndex)
End If
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
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
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 by RajivKumarNandvani at 4:29 AM 0 comments
Labels: ListBox, QTP, WebList
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).
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:
row = 1 : col = 1
row = -1 : col = -1
LocateTextInTableDOM = False
End Function
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
function samplefunc(c)
c = c^2-1
samplefunc = (c mod 2 = 1)
end function
q=8
samplefunc q
msgbox q ‘ returns 63
‘ With call:
r = 10
call samplefunc(r)
msgbox r ‘ returns 99, because r is returned byRef
‘ 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) )
rem ********************************
call fn_DeletesubFolderAndFiles(”C:\DOCUME~1\%USERNAME%\Cookies”)
rem *********************************
call fn_DeletesubFolderAndFiles(”C:\DOCUME~1\%USERNAME%\Locals~1\Tempor~1″)
rem ***********************************
REM *************************************************************************
Rem this Function delete the files & subfolder under the specified path
REM Note := IF file Protected then it will not delete without giving Error
REM Created: 17/April/2009 Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM *************************************************************************
rem get count the files under the folder and loop run for delete the files
objFileSystem.DeleteFile oFile
Err.clear
Next
rem get count the subfolders under the folder and loop run for delete the subfolders
objFileSystem.DeleteFolder oSubFolder
Err.clear
Next
Err.clear
End function
REM
*************************************************************************ss
REM This function kill the given process exe through task manager
rem example call fn_CloseApplication(”EXCEL.EXE”)
Some Time we want create a folder Or File with unique name then we current date time
value for creating the file or folder that we can use this method for create the file OR folder
as decribed here
REM this function return the current date time in text format
Dim sDateTime
sDateTime = now
sDateTime =replace(sDateTime,”:”,”_”)
sDateTime =replace(sDateTime,”>”,”_”)
sDateTime =replace(sDateTime,”<”,”_”)
sDateTime =replace(sDateTime,”/”,”_”)
sDateTime =replace(sDateTime,”|”,”_”)
sDateTime =replace(sDateTime,”\”,”_”)
sDateTime =replace(sDateTime,”*”,”_”)
sDateTime =replace(sDateTime,”"”",”_”)
sDateTime =replace(sDateTime,”#”,”")
fn_GetDateTimeText =sDateTime
End Function
dim sGetCurrentDateTime
sGetCurrentDateTime = fn_GetDateTimeText()
REM ************************************************
Rem This Function Check XML File Valid OR not if File not valid XML then return False Else
True
REM Function fn_CheckXMLValid( sXMLfilepath)
REM Input sXMLfilepath := XMLfilepath
REM Output(ReturnType) := True or False
REM Created: 21/April/2009 Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM *************************************************************************
End Function
REM ************************************************
End If
rem if not found then return the Empty
FindColumnAddress =”NOT FOUND”