QTP imp functions
To get getTableData
Function for CountRecords
convNumb
ConvNumbWCents
Function handle unexpected Window on Page
checkStringLength(strBrowser, strPage ,strTable, ReqNum)
Page Wait specify time in intTime parametr
verifyWebElement(strBrowser, strPage, strName, strTag)
Function getRandomNum(RandNum)
dropDowngetValue Get value from dropdown list
For initial sorting function get dataType
Function getRandomNum(RandNum)
clickRadio
GetColumnNumber
ValidateCellData
Function generates random number
Function CompareStrings
Function getLookUp
Select Multiple items from the Web ListTo get getTableData
Function getTableData(strBrowser, strPage, strTableID, strFind, strFindMore)
Dim objBr, objPg, objTbl
Dim intCount, intRow, intCol, blnFound
On Error Resume Next
getTableData = -1
Set objBr = Browser("name:=" & strBrowser)
Set objPg = objBr.Page("title:=" & strPage)
Set objTbl = objPg.WebTable("html id:=" & strTableID, "html tag:=TABLE")
If objTbl.Exist = False Then
Set objTbl = objPg.WebTable("name:=" & strTableID, "html tag:=TABLE")
If objTbl.Exist = False Then
Err.Clear
Exit Function
End If
End If
intCount = objTbl.RowCount
blnFound = False
For intRow = 1 To intCount
For intCol = 1 To objTbl.ColumnCount(intRow)
If InStr(objTbl.GetCellData(intRow, intCol),strFind) > 0 Then
If Len(strFindMore) > 0 Then
For intF = intCol To objTbl.ColumnCount(intRow)
If InStr(objTbl.GetCellData(intRow,intF),strFindMore) > 0 Then
blnFound = True
getTableData = 0
Exit For
End If
Next
Else
blnFound = True
getTableData = 0
End If
End If
If blnFound Then Exit For
Next
If blnFound Then Exit For
Next
If Err.Number <> 0 Then
Err.Clear
End If
End Function
'===========================================
Function for CountRecords
Public Function CountRecords(strBrowser, strPage, strHTML, intExpected, outResult)
On error resume Next
CountRecords = -1
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
objPage.sync
Set objCount = objPage.Object.all.Tags(strHTML)
intActual = objCount.length
If abs(intExpected) = abs(intActual) Then
outResult = "<< PASS >> expected " & intExpected & " , actual result " & intActual & " records."
Err.clear
CountRecords = 0
Exit Function
else
outResult = "<< COMMENT >> expected " & intExpected & ", actual result " & intActual & " records."
Err.clear
CountRecords = 0
Exit Function
End If
'Err.clear
End Function
convNumb
Function convNumbWN(inpNum,outNum)
On Error Resume Next
Dim iSLen, iComma, iComma1,i,j,k
Dim sWork
inpNum=Trim(inpNum)
If InStr(1,inpNum,".") =0 Then
iSLen=Len(inpNum)
iComma = iSLen\3
iComma1 = iSLen/3
outNum=""
If iComma=iComma1 Then
iComma=iComma-1
End If
For i=1 to iComma
j=i*3
sWork=Mid(inpNum,iSLen-j+1,3)
outNum=","&sWork&outNum
Next
k=iSLen-j
sWork=Mid(inpNum,1,k)
If outNum="" and sWork="" Then
outNum="0"
End If
outNum=sWork&outNum
else
outNum=inpNum
end if
On Error Resume Next
convNumb=0
If Err.Number <> 0 Then
convNumb=-1
Err.clear
Else
convNumb= 0
End If
Err.Clear
End Function
ConvNumbWCents
Function ConvNumbWCents(inpNum,outNum)
Dim sWork,sWork2,sWork3
Dim i
i=InStr(1,inpNum,".")
sWork2=Mid(inpNum,1,i-1)
sWork=Mid(inpNum,i,3)
convNumbWN sWork2,sWork3
outNum=sWork3&sWork
End Function
' Function handle unexpected Window on Page
' strBrowser - Name of the Browser
' strPage - Title of the Page
'
''' s = UnexpectedWindow("Cv Portal","CV Portal",strOutput)
public Function UnexpectedWindow(strBrowser,strPage)
On error resume next
Set objPage = Browser("name:="&strBrowser)
objPage.sync
Set unexpectedWin = objPage.Dialog("regexpwndtitle:=Microsoft Internet Explorer")
If unexpectedWin.exist Then
unexpectedWin.WinButton("regexpwndtitle:=OK").Click
UnexpectedWindow = 0
Else
UnexpectedWindow = -1
End If
IF Err.Number > 0 Then
Err.Clear
End IF
End Function
''' ================================================
''' checkStringLength(strBrowser, strPage ,strTable, ReqNum)
''' ================================================
Function checkStringLength(strBrowser, strPage ,strTable, ReqNum)
On error resume next
checkStringLength = -1
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
strCell = objPage.WebTable("html id:="&strTable).GetCellData(4, 5)
If Len(strCell) <= ReqNum Then
checkStringLength = 0
End If
If Err.number > 0 Then
Err.Clear
End If
End Function
''' Page Wait specify time in intTime parametr
''' ================================================
Function pageWait(intTime)
On error resume next
wait (intTime)
If Err.Number <> 0 Then
Err.Clear
End If
pageWait = 0
End Function
'' verifyWebElement(strBrowser, strPage, strName, strTag)
''' ================================================
Function verifyWebElement (strBrowser, strPage, strName, strTag)
On error resume next
verifyWebElement = -1
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
Set objTags = objPage.Object.all.Tags(strTag)
For each Element in objTags
If inStr (Element.innertext, strName) > 0 Then
verifyWebElement = 0
Err.Clear
Exit Function
End If
Next
If Err.number > 0 Then
Err.Clear
End If
End Function
Function getRandomNum(RandNum)
Function getRandomNum(RandNum)
RandNum = RandomNumber (100000000, 999999999)
Err.Clear
getRandomNum = 0
End Function
''' dropDowngetValue Get value from dropdown list
''' ================================================
Function dropDowngetValue (strBrowser, strPage, strName, strValue)
Dim objPage, objPageTags
On error resume next
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
Set objPageTags = objPage.Object.all.Tags("option")
For each Element in objPageTags
If Trim( Element.innertext) = Trim(strValue) Then
If Trim(Element.value) = Trim(strValue) Then
dropDowngetValue = 0
Err.clear
Exit Function
End If
End If
Next
dropDowngetValue = -1
Reporter.ReportEvent 1, "Fail", strValue & "does not exist"
Err.clear
End Function
''' For initial sorting function get dataType
''' =================================================
Function getDatatype(rulesString, delimeter)
Dim arRule
On error resume next
arRule = Split (rulesString, delimeter)
If err.number > 0 Then
getRulesType = -1
err.clear
Exit Function
End If
getDatatype = arRule
End Function
Function getRandomNum(RandNum)
Function closeAllBrowsers()
Dim n
set oDesc = Description.Create()
oDesc("micclass").Value = "Browser"
Set bs = Desktop.ChildObjects(oDesc)
n = bs.count
For i = 0 to n-1
if not bs(i).GetROProperty("title")="Mercury Quality Center" then bs(i).Stop : bs(i).close()
Next
end Function
clickRadio
Function clickRadio(strBrowser, strPage, strValue)
''' c = clickRadio("CreditView Portal", "CreditView Portal", "portlet_creditProd_overviewwlw-radio_button_group_key:{actionForm.creditProductDetailsVO.guaranteesCollateralCodeFlag}")
On error resume next
Dim objPage
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
objPage.sync
Set objPageTagInput = objPage.Object.all.Tags("input")
For each Element in objPageTagInput
If Trim(Element.value) = Trim(strValue) or Trim(Element.id) = Trim(strValue) or Trim(Element.name) = Trim(strValue) Then
Element.click
clickRadio = 0
Err.clear
Exit Function
End If
Next
clickRadio = -1
Err.clear
End Function
GetColumnNumber(
GetColumnNumber
Function GetColumnNumber(strBrowser, strPage, strTableID, strHeader)
Dim objBr, objPg, objTbl
Dim intR, intC, blnFound
On Error Resume Next
GetColumnNumber = -1
Set objBr = Browser("name:=" & strBrowser)
Set objPg = objBr.Page("title:=" & strPage)
blnFound = False
Set objTbl = objPg.WebTable("html id:=" & strTableID, "html tag:=TABLE")
If objTbl.Exist =false Then
Set objTbl = objPg.WebTable("name:=" & strTableID, "html tag:=TABLE")
End If
For intR = 1 To objTbl.RowCount
If Not blnFound Then
For intC = 1 To objTbl.ColumnCount(intR)
If Trim(objTbl.GetCellData(intR, intC)) = strHeader Then
blnFound = True
GetColumnNumber = intC
Exit For
End If
Next
End If
Next
If Err.Number <> 0 Then
Err.Clear
End If
End Function
ValidateCellData
Public Function ValidateCellData(strBrowser, strPage, strTable, strFind, blnSelect, strHeader, strEspected )
On error resume next
Dim objBr, objPg, objTbl, data
ValidateCellData = -1
strRow = GetRowNumber(strBrowser, strPage, strTable, strFind, FALSE )
' msgbox strRow
strCol=GetColumnNumber(strBrowser, strPage, strTable, strHeader)
'msgbox strCol
Set objPg = Browser("name:="& strBrowser).Page("title:="& strPage)
Set objTbl = objPg.WebTable("html id:=" & strTable, "html tag:=TABLE")
strActual = objTbl.ChildItem(strRow, strCol, "WebEdit", 0).GetROProperty("value")
If abs(strActual) = abs(strEspected) Then
ValidateCellData = 0
End If
'objTbl.ChildItem(strRow, strCol, "WebEdit",0).GetROProperty("value").Set(123456)
If Err.Number <> 0 Then
Err.Clear
End If
End Function
' Function generates random number , based on parameters
' intIndex - length of number
' strOutPut - output number
' function returns 0 -success, -1 - failure
'============================================================================================
Function RndNum(intIndex, strOutPut)
On Error Resume Next
Dim intFirst, intLast, intRest, intTimes, strTemp
RndNum = 0
If intIndex < 1 Then
strOutPut = 0
Exit Function
End If
'find reminder
intRest = intIndex Mod 9
' find how many times by 9 needs to be executed
intTimes = intIndex - intRest
If intTimes > 0 Then
intTimes = (intIndex - intRest)/9
End If
If intTimes = 0 Then
intFirst = CLng(1 & String(intIndex-1,"0"))
intLast = CLng(String(intIndex,"9"))
strTemp = RandomNumber(intFirst,intLast)
Else
For i =1 to intTimes
strTemp = strTemp & RandomNumber(100000000,999999999)
Next
If intRest > 0 Then
intFirst = CLng(1 & String(intRest-1,"0"))
intLast = CLng(String(intRest,"9"))
strTemp = strTemp & RandomNumber(intFirst,intLast)
End If
End If
strOutPut = strTemp
If Err.Number <> 0 Then
RndNum = -1
End If
End Function
Function CompareStrings
======================================================================
Public Function CompareStrings(strBrowser, strPage, strTable, strFirst, strSecond, strThird, strOutput)
On error resume next
CompareStrings = -1
Set objPg = Browser("name:="& strBrowser).Page("title:="& strPage)
Set objTbl = objPg.WebTable("name:=" & strTable & ".*")
intRowCount = objTbl.RowCount - 2 ' the last record
'intColCount = objTbl.ColumnCount(intRowCount)
strActual = trim(objTbl.GetCellData(intRowCount,5))
strExpected =trim( "Min"&strFirst&",Inc"&strSecond&",Max"&strThird)
If instr(strActual, strExpected) <> 0 Then
strOutput = "PASS. Pricing option validation pass." & vbCrLf & "Expected result: <" & strExpected & ">" & vbCrLf & "Actual result: < " & strActual & "> are matched"
else
strOutput = "FAIL. Pricing option validation fail" & vbCrLf & "Expected result: <" & strExpected & vbCrLf & "and Actual result:<" & strActual & "> are not matched"
End If
CompareStrings=0
If Err.Number <> 0 Then
Err.Clear
End If
End Function
Function CloseBrowser
'Browser("title:=Popup Select").Close
'end Function
Function closeBrowser()
On Error Resume Next
browser("index:=0").close
if not Err.Number = 0 then
closeBrowser = -1
Err.clear
exit function
end if
closeBrowser = 0
End Function
Function getLookUp
Public Function getLookUp(strBrowser, strPage, strRadioGroup, strSimple, strOutput)
On error resume next
Dim objPage, objTagsString, objTagsRadio, Element,objTagsSpan,arrayElement(),counter
Dim testArrayLinks
Set objPage = Browser("name:="&strBrowser).Page("title:="&strPage)
objPage.sync
' Set objTagsRadio = objPage.Object.all.Tags("input")
Set objTagsSPAN = objPage.Object.all.Tags("SPAN")
If objTagsSPAN.length <> 0 Then
counter = objTagsSPAN.length
ReDim arrayElement(counter)
' ReDim arrayInputs(counter)
For i = 0 to counter - 1
arrayElement(i) = objTagsSPAN.item(i).innertext
' arrayInputs(i) = objTagsRadio.item(i).value
Next
y = 0
For each Element in objTagsSPAN
If instr(Element.innertext, strSimple)<>0 Then
strOutput= Left(Element.innertext,Instr(Element.innertext,"#")-2)
Set r = Element.ParentNode.ParentNode.GetElementsByTagName("input")
If r(0).checked = FALSE Then
' r(0).checked = TRUE
r(0).Click
getLookUp = 0
err.clear
Exit Function
else
Reporter.ReportEvent 1, "Radio Button was not found", strName & "Was not found on the page."
getLookUp = -1
err.clear
Exit Function
End If
End If
y = y+1
Next
End If
End Function
'' Select Multiple items from the Web List.
''' ============================================================
Function selectAllitems(strBrowser, strPage, strListName, strFlag, strName, outPut)
'''' c = selectAllitems(" Portal", " Portal", "portlet_collateral_detailswlw-select_key:{actionForm.selectedPledges}", "One", "Customer 4",outPut)
On error resume next
Dim itemCount
selectAllitems = -1
Set obj = Browser("name:=" & strBrowser).Page("title:=" & strPage)
Set objList = obj.WebList("name:=" & strListName)
itemCount = obj.WebList("name:=" & strListName).GetRoProperty("items count")
If itemCount <= 0 Then
selectAllitems = 0
outPut = "<< ERROR >> No Items found in the List to Select."
Exit Function
else
Select Case strFlag
Case "All"
For i = 0 to itemCount - 1
objList.ExtendSelect ("#" & i )
Next
selectAllitems = 0
outPut = "<< COMMENT >> " & itemCount & " items found and selected in the List."
Case "One"
objList.ExtendSelect (strName)
selectAllitems = 0
outPut = "<< COMMENT >> " & strName & " found and selected in the List."
End Select
End If
If err.number <> 0 Then
outPut = err.description
err.clear
End If
End Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment