Function Compare 2 strings, witch could contain < ' > character.
Function Compare 2 strings, witch could contain different delimeter characters
Function get officecode from look up window with office inffo like 41ST & CAPITOLA OFFICE #533 .
Function CloseBrowser
Function Compare strings format : MaxXX, IncXX, MinXX
Function return number of column with specified header
How to deal with web table objects
Function Select Single Record selects
Function generates random number
Multiple items
''' Select Multiple items from the Web List.
''' ============================================================
Function selectAllitems(strBrowser, strPage, strListName, strFlag, strName, outPut)
'''' c = selectAllitems("CrPortal", "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
Compare 2 str
'' ==================================================
''' Compare 2 strings, witch could contain < ' > character.
''' ==================================================
's = StringCompare(123000, 23, "Yes", outPut)
Function StringCompare(str1, str2, exist, outPut)
StringCompare = 0
On error resume next
str1_= Replace(str1, "'", "*")
str2_ = Replace(str2, "'", "*")
Select Case (exist)
case "Yes"
if instr(str1_,str2_) > 0 Then
outPut = "<< PASS >> String <" &str2& "> found"
else
outPut = "<< FAIL >> String <" &str2& "> not found"
end if
case "No"
if instr(str1_,str2_) > 0 Then
outPut ="<< FAIL >> String <" &str2& "> found"
else
outPut = "<< PASS >> String <" &str2& "> not found"
end if
End Select
If err.number <> 0 Then
err.clear
End If
End Function
Compare 2 strings
'' ==========================================================
''' Compare 2 strings, witch could contain different delimeter characters.
''' ==========================================================
''''''a = StringsEqual(str1, str2, "-", "/", outPut)
Function StringsEqual(str1, str2, strDelimeter1, strDelimeter2, outPut)
strCompare = 0
On error resume next
str1_= Replace(str1, strDelimeter1, strDelimeter2)
str2_ = Replace(str2, strDelimeter1, strDelimeter2)
' if str1_= str2_
if instr(str1_,str2_) > 0 Then
StringCompare = 0
outPut = "<< PASS >> Strings are equal"
Else StringCompare = 0
outPut = "<< FAIL >> Strings are not equal
End if
If err.number <> 0 Then
err.clear
End If
End Function
LookUp
'This function get officecode from look up window with office inffo like 41ST & CAPITOLA OFFICE #533 .
' ============================================================
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
CloseBrowser
'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
Compare strings
' Function Compare strings format : MaxXX, IncXX, MinXX
'
' Input: strBrowser - Browser name
' strPage - Page title
' strTableID - WebTable html id or name
' strFirst, strSecond, strThird - formated strings
'
' Output: 0 - SUCCESS; -1 - FAILURE
's= CompareStrings("Cr Portal","Cr Portal", "Index", "10", "50", "5", "")
'======================================================================
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
ColumnNumber
'========================
'Function return number of column with specified header.
'
's=GetColumnNumber("Cr ortal", "Crortal", "feesTable", "Fixed ($)")
'
'========================
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
electSingleRecord
'===========================================
'SelectSingleRecord selects row in table witch contains data specified in strFind parameter
'j = SelectSingleRecord("Crortal","Crortal","treeTable","Liquidity (min)", "WebCheckBox")
'j = SelectSingleRecord("crrr","Crortal","Index","WFB Prime", "WebRadioGroup")
'= SelectSingleRecord("Crrtal","Crortal","treeTable","2. Line", "WebRadioGroup")
'strBrowser - browser name
'strPage - page name
'strTableID - Table Id or Index
' strFind - label for radiobotton or Checkbox ,
'strElement - WebRadioGroup or WebCheckBox
'objBr - object browser,
'objPg - object page
'objTbl - table with name or index equal strTableID
'oTbl - array of tables
'oTblz - table in array oTbl
'intRow - row counter
' intCount - step counter
' intStartRow - number of row with radioBotton or CheckBox with "0" index
'intSelCol - number of row with radioBotton or CheckBox with "0" index
'blnFound - indicate Table is found
'blnSelect - indicate Selection was made
Function SelectSingleRecord(strBrowser, strPage, strTableID, strFind, strElement)
Dim objBr, objPg, objTbl, oTbl, oTblz
Dim intRow, intCount
On Error Resume Next
SelectSingleRecord = -1
intCount = 0
intStartRow = -1
Set objBr = Browser("name:=" & strBrowser)
Set objPg = objBr.Page("title:=" & strPage)
Set oTblz = objPg.Object.getElementsByTagName("TABLE")
For Each oTbl In oTblz
If strTableID = oTbl.Id Then
blnFound = True
Else
If InStr(objPg.WebTable("index:=" & intCount).GetROProperty("name"), strTableID) > 0 Then
blnFound = True
End If
End If
If blnFound Then
Set objTbl = objPg.WebTable("html tag:=TABLE","index:=" & intCount)
For intRow = 1 To objTbl.RowCount
For intCol = 1 To objTbl.ColumnCount(intRow)
If intStartRow = -1Then
If Browser("name:=" & strBrowser).Page("title:=" & strPage).WebTable("index:=" & intCount, "html tag:=TABLE").ChildItemCount (intRow, intCol, strElement) > 0 Then
intStartRow = intRow
intSelCol = intCol
End If
End If
If Trim(objTbl.GetCellData(intRow, intCol)) = strFind Then
Select Case strElement
Case "WebRadioGroup"
Browser("name:=" & strBrowser).Page("title:=" & strPage).WebTable("index:=" & intCount, "html tag:=TABLE").ChildItem(intRow, intSelCol, strElement, 0).Select "#0" & intRow - intStartRow
Case "WebCheckBox"
Browser("name:=" & strBrowser).Page("title:=" & strPage).WebTable("index:=" & intCount, "html tag:=TABLE").ChildItem(intRow, intSelCol, strElement, 0).Set "ON"
End Select
blnSelect = True
Exit For
End If
If blnSelect Then
Exit For
End If
Next
If blnSelect Then
Exit For
End If
Next
End If
If blnFound Then
SelectSingleRecord = 0
Exit For
End If
intCount = intCount + 1
Next
If Err.Number <> 0 Then
Err.Clear
End If
End Function
random number
'============================================================================================
' 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
webtableobjects
how to deal with Web Table object.
Objective: Dealing with Web Table is sometimes a bit tricky, not very straightforward.
This document describes some tips for dealing with
How To Use Effectively Verify_WebTable_Cells.
1.1.1Verify_WebTable_Cells takes 3 parameters, pStrText, pIntIndex and pArytableData. We need to determine them in order to make the function work for your script.
1.1.2Here is an example web table that you want to verify with Verify_WebTable_Cells.
Say you want to verify Name, ID and Pool
1.1.3Use Object Spy and point the cursor on one of the cells in which value you want to verify (in this case, “Jun Client 112 Small”), and click
1.1.4Here is the object hierarchy in Object Spy
The target value is in a web table named “Name”, which is in another table but the same name as the one level deeper one, “Name”
1.1.5Use “Name” for the first parameter (pStrText), and use the “1” for the second parameter (pIntIndex) since index starts from 0.
Let’s move on to the third parameter, which is an array object.
1.1.6Although we don’t really record anything, push Record button
1.1.7Select “Standard Checkpoint”
1.1.8Point the cursor on the values again and click
1.1.9Select the deepest web table and OK.
1.1.10This is the spread sheet that illustrates the structure of the cells.
1.1.11Now, you make an array object based the spreadsheet. For example:
Click_Associated_Link_InTable
Use the function when there are the same name links in a table and want to click one of them based on some information in the other column.
1.1.12Now you want to click a “Staff” link for “Position A5”, but assume you don’t know in which row the position appears.
1.1.13Use Click_Associated_Link_InTable function. The first two parameters (pStrTableName, pIntTableIndex) can be found by following 1.1 How To Use Effectively Verify_WebTable_Cells.
1.1.14For the third parameter (pIntLookUpColumnNumber), specify a column number where you lookup a text value. In this case, 2.
1.1.15For the fourth parameter (pStrLookUpText), specify a text value in which row you want to click a link. In this case, “Position A5”.
1.1.16For the last parameter (pIntColumnNumberToClick), specify a column number to click a link. In this case, 3.
Code Example
Call Click_Link("Find", 0)
Call Click_Associated_Link_InTable("Position/Task.*", 0, 2, "Position A5", 3 )
Web Table object and focus
Keep in mind that use another clicking function at least one line before any functions of Web Table. There is a limitation.
Bad Code Example:
Call Click_Associated_Link_InTable("Position/Task.*", 0, 2, "Position A5", 3 )
This does NOT work
Good Code Example:
Call Click_Link("Find", 0) ‘ Have a clicking function.
Call Click_Associated_Link_InTable("Position/Task.*", 0, 2, "Position A5", 3 )
This works.
Checkbox object
How To Use Verify_CheckBox_Checked
1.1.17Verify_WebTable_Cells takes 2 parameters, pStrGroupName and pIntItemIndex. We need to determine them in order to make the function work for your script.
1.1.18Here is where we want to you the function. One is checked and the other is not.
1.1.19Use Object Spy and click on the first checkbox. Copy the name, which is the first parameter(pStrGroupName).
1.1.20To determine the second parameter(pIntItemIndex), spy other checkbox and see if any of them use the same name (the grouping name). if not, then the second parameter is 0. If yes, then decide an appropriate index number which you can start from index 0. You code should look like:
1.1.21Do the same thing for the second checkbox where you expect a failure since the second one is not checked. You code should look like:
NOTE: Evolve rarely uses the grouping concept for checkbox. Mostly they are an independent checkbox and have different names on each checkbox. See the image above.
1.1.22The result should look like:
TIPs for panes in detail pages
Use Expand_Profile and Edit_Profile
1.1.23If you want to open a pane in a detail page, use Expand_Profile function
Code Example
Call Expand_Profile("General Information")
1.1.24As a result, the pane should open.
1.1.25If you want to Edit the pane, use Edit_Profile function.
Code Example
Call Edit_Profile("General Information")
IFrame messages
IFrame message is not a popup windows, it’s a IFrame.
1.1.26If you want to click OK button like an image below. Use Click_IFrameButton function. (if you want to make sure if it is a IFrame message or a regular message box, use Object Spy)
Code Example
Call Click_IFrameButton("OK", 0)
Counting no.of links in a web page:
number of links in a webpage
Set linkdesc = Description.Create()
linkdesc("micclass").Value="WebButton"
Set pageColl = Browser("name:=Google").Page("title:=Google").ChildObjects(linkdesc)
print pageColl.count
Calculatot application
Window("Calculator").Activate
Window("Calculator").WinButton("clear").Click
Window("Calculator").WinButton("first operand").Click
Window("Calculator").WinButton("operator").Click
Window("Calculator").WinButton("second operand").Click
Window("Calculator").WinButton("equals").Click
Window("Calculator").WinEdit("result").SetCaretPos 3
Window("Calculator").WinEdit("result").Check CheckPoint("result")
Testcase for checking webpage
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Check CheckPoint("Check Welcome Page")
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebElement("User Name:").Check CheckPoint("Check User Name prompt")
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "banitha"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4795832fd90d055c33f6f9b038c01b6dc33289e70a3186b7"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 24,2
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Check CheckPoint("Check Find a Flight Page")
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "New York"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 61,19
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Check CheckPoint("Check Select a Flight Page")
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Image("banner2").Check CheckPoint("Check Banner Ad")
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Image("reserveFlights").Click 81,10
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").Check CheckPoint("Check Book a Flight Page")
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebTable("New York to Acapulco").Check CheckPoint("Check Price")
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("passFirst0").Set "banitha"
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("passLast0").Set "babburi"
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("creditnumber").Set "12317236173618"
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("passFirst0").Set "anitha"
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").Image("buyFlights").Click 74,15
Browser("Welcome: Mercury Tours").Page("Flight Confirmation: Mercury").Check CheckPoint("Check Departure Port_2")
Browser("Welcome: Mercury Tours").Page("Flight Confirmation: Mercury").Image("home").Click
parameterise using dtglobal sheet
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Check CheckPoint("Check Welcome Page")
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebElement("User Name:").Check CheckPoint("Check User Name prompt")
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "banitha"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4795832fd90d055c33f6f9b038c01b6dc33289e70a3186b7"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 24,2
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Check CheckPoint("Check Find a Flight Page")
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select DataTable("Departure", dtGlobalSheet)
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business"
reusable Actions
Window("Flight Reservation").WinComboBox("Fly From:").Select DataTable("Departing_City", dtLocalSheet)
Window("Flight Reservation").WinComboBox("Fly To:").Select "Portland"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set DataTable("passenger", dtLocalSheet)
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
myorder = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
mytotal = Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")
reporter.ReportEvent micPass, "order number is " & myorder, ""
reporter.ReportEvent micPass, "total price is " & mytotal, ""
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
(local sheet define values in datatable with headings departingcity,passenger,flightdate etc)
use reusable action for login.
select fax number
Window("Flight Reservation").WinObject("Date of Flight:").Type "091208"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "morley safir"
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinObject("Insert Done").WaitProperty "text", "Insert Done...", 10000
Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."
ordernum = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
Window("Flight Reservation").Dialog("text:=Fax Order No. " & ordernum).WinObject("attached text:=Fax Number:").Type "5203458898"
Window("Flight Reservation").Dialog("text:=Fax Order No. " & ordernum).WinButton("text:=&Send").Click
Property values
reporter.Filter = rfEnableAll
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "banitha"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4795832fd90d055c33f6f9b038c01b6dc33289e70a3186b7"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 24,2
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "New York"
strCurrentValue = Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort")_
.GetTOProperty("items count")
msgbox "number of items is " & strCurrentValue
reporter.ReportEvent micPass, "Counting Phase", "number of items is: " & strCurrentValue
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business"
For getting default value
strCurrentValue = Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury")_
.WebList("fromPort".GetTOProperty("default value"))
msgbox "strCurrentValue is " & strCurrentValue