SIFL全称Software Inquisition Foundation Library
其中包含很多QTP的基础库函数,可以称之为一个QTP的基础框架,主要库函数文件包括:
AssertLib.vbs:处理断言语句和写结果。
BrowserFunctions.vbs:扩展Browser测试对象,例如OpenNewBrowser函数用于打开一个新的IE浏览器实例。
ObjectMethods.vbs:扩展各种测试对象,例如注册到WebList的WebListItemsArray函数可以返回一个代表WebList各项元素的数组。
StringFunctions.vbs:处理字符串,例如StringIsEmpty函数用于判断给定的字符串是否为空。
Utility.vbs: 工具类,siChildren函数用于获取WebElement的满足指定描述的子对象元素
WebTableMethods.vbs:扩展WebTable测试对象,例如WebTableGetRowValues函数用于返回指定行的数据。
作者主页:
http://www.softwareinquisition.com/
(注:现在好像不能访问了)
摘录WebTableMethods的函数如下:
''' <summary>
''' Returns an array containing the values from the given row
''' </summary>
''' <param name="oTable" type="WebTable">WebTable under test</param>
''' <param name="iRowNumber" type="Integer">Row number to grab</param>
''' <returns type="String()"></returns>
Public Function WebTableGetRowValues( oTable, iRowNumber)
Dim aReturn
For colNumber = 1 To oTable.ColumnCount(iRowNumber)
arrayPush aReturn, Trim(oTable.GetCellData(iRowNumber, colNumber))
Next
WebTableGetRowValues = aReturn
End Function
RegisterUserFunc "WebTable", "GetRowValues", "WebTableGetRowValues", True
''' <summary>
''' Returns the Column Number for the first occurance of sMatchString or 0 if it doesn't occur
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sMatchString" type="String">String to match</param>
''' <returns type="Integer"></returns>
Public Function WebTableGetColumnNumber (ByRef oTable, sMatchString)
If stringContains(sMatchString, "^#/d+$") Then
WebTableGetColumnNumber = GetMatch(sMatchString, "^#(/d+)$")
Else
For rowNumber = 1 To oTable.RowCount
For colNumber = 1 To oTable.ColumnCount(rowNumber)
If StringContains(oTable.GetCellData(rowNumber, colNumber), sMatchString) Then
WebTableGetColumnNumber = colNumber
Exit Function
End If
Next
Next
WebTableGetColumnNumber = 0
End If
End Function
RegisterUserFunc "WebTable", "GetColumnNumber", "WebTableGetColumnNumber", True
''' <summary>
''' Returns the Column Index for the first occurance of sMatchString or -1 if no match
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sMatchString" type="String">String to match</param>
''' <returns type="Integer"></returns>
Public Function WebTableGetColumnIndex(ByRef oTable, sMatchString)
WebTableGetColumnIndex = WebTableGetColumnNumber(oTable, sMatchString) - 1
End Function
RegisterUserFunc "WebTable", "GetColumnIndex", "WebTableGetColumnIndex", True
''' <summary>
''' Gets the Row index for the first occurance of sMatchString
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sMatchString" type="String">String to match</param>
''' <returns type="Integer">returns row index or -1 if sMatchString isn't found</returns>
Public Function WebTableGetRowIndex (ByRef oTable, sMatchString)
WebTableGetRowIndex = WebTableGetRowNumber(oTable, sMatchString) - 1
End Function
RegisterUserFunc "WebTable", "GetRowIndex", "WebTableGetRowIndex", True
''' <summary>
''' Gets the Row number for the first occurance of sMatchString
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sMatchString" type="String">String to match</param>
''' <returns type="Integer">returns row number or 0 if sMatchString isn't found</returns>
Public Function WebTableGetRowNumber (ByRef oTable, sMatchString)
If stringContains(sMatchString, "^#/d+$") Then
WebTableGetRowNumber = GetMatch(sMatchString, "^#(/d+)$")
Else
For rowNumber = 1 To oTable.RowCount
For colNumber = 1 To oTable.ColumnCount(rowNumber)
If StringContains(oTable.GetCellData(rowNumber, colNumber), sMatchString) Then
WebTableGetRowNumber = rowNumber
Exit Function
End If
Next
Next
WebTableGetRowNumber = 0
End If
End Function
RegisterUserFunc "WebTable", "GetRowNumber", "WebTableGetRowNumber", True
''' <summary>
''' Search for a string of text in the cell data of a WebTable, and return the coordinates of the cell
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sSearch" type="String">String to match</param>
''' <returns type="String">Returns a string in the form of "intRowNumber,intColumnNumber"</returns>
Public Function WebTableGetCellCoords (ByRef oTable, ByRef sSearch)
For rowNumber = 1 To oTable.RowCount
For ColumnNumber = 1 To oTable.ColumnCount(oTable.RowCount)
If StringContains(oTable.GetCellData(rowNumber, ColumnNumber), sSearch) Then
bFound = True
WebTableGetCellCoords = CStr(rowNumber) & "," & CStr(ColumnNumber)
Exit Function
End If
Next
Next
'Return 0 if it wasn't found
WebTableGetCellCoords = "0"
End Function
RegisterUserFunc "WebTable", "GetCellCoords", "WebTableGetCellCoords", True
''' <summary>
''' Search one column in a webtable for a string.
''' </summary>
''' <param name="oTable" type="WebTable">Table (possibly) containing sMatchString</param>
''' <param name="sColumnHeader" type="String">Column to Search</param>
''' <param name="sSearchString" type="String">Search string</param>
''' <returns type="Boolean"></returns>
Public Function WebTableColumnContains (ByRef oTable, sColumnHeader, sSearchString)
headerRowNumber = WebTableGetRowNumber(oTable, sColumnHeader)
ColumnNumber = WebTableGetColumnNumber(oTable, sColumnHeader)
WebTableColumnContains = False
For rowNumber = headerRowNumber To oTable.RowCount
If StringContains(oTable.GetCellData(rowNumber, ColumnNumber), sSearchString) Then
WebTableColumnContains = True
Exit Function
End If
Next
End Function
RegisterUserFunc "WebTable", "ColumnContains", "WebTableColumnContains", True
''' <summary>
''' Asserts if a table is sorted by specified column
''' </summary>
''' <param name="oTable" type="WebTable">Table to check</param>
''' <param name="sHeader" type="String">Column to check</param>
''' <param name="sOrder" type="String">Asserting order, ascending or descending</param>
''' <example>
''' Assert if first table on page "Legal Assistant Scan Categories" is sorted by
''' column "Scan Name" in ascending order
''' NavigateToPage "Legal Assistant Scan Categories"
''' Set oTable = SelectFirstTable
''' oTable.AssertSortedByColumn "Scan Name", "Ascending"
''' <code>
''' LoginProfile "SUPER"
''' assertSetupMenuLinkExists "Eligible Populations"
''' </code>
''' </example>
''' <returns type="Boolean"></returns>
Public Function WebTableAssertSortedByColumn (ByRef oTable, sHeader, sOrder)
WebTableAssertSortedByColumn = reportStatus( WebTableVerifySortOrderInColumnAdv( oTable, sHeader, Array( "SortOrder", sOrder ) ), "AssertSortedByColumn", "Table sorted by '" & sHeader & "' ordered " & sOrder )
End Function
RegisterUserFunc "WebTable", "AssertSortedByColumn", "WebTableAssertSortedByColumn", True
''' <summary>
''' Verify oTable has correct order
''' </summary>
''' <param name="oTable" type="WebTable">Table to check</param>
''' <param name="Header" type="String">Column to check</param>
''' <returns type="Boolean"></returns>
Public Function WebTableVerifySortOrderInColumn (ByRef oTable, Header)
WebTableVerifySortOrderInColumn = WebTableVerifySortOrderInColumnAdv( oTable, Header, Null )
End Function
RegisterUserFunc "WebTable", "VerifySortOrderInColumn", "WebTableVerifySortOrderInColumn", True
''' <summary>
''' Verify oTable has correct order
''' </summary>
''' <param name="oTable" type="WebTable">Table to check</param>
''' <param name="Header" type="String">Column to check</param>
''' <param name="aOptions" type="Object()"></param>
''' <array-elements param="aOptions">
''' <element name="SortOrder" type="String" default="Ascending">Should it be sorted asecnding or descending</element>
''' <element name="SortType" type="String" default="Alphabetical">Is it supposed to be sorted alphabetically? Probably so.</element>
''' </array-elements>
''' <returns type="Boolean"></returns>
Public Function WebTableVerifySortOrderInColumnAdv (ByRef oTable, Header, aOptions)
Set oOptions = GetOpts( Array ( _
"SortOrder", "Ascending", _
"SortType", "Alphabetical" _
), aOptions)
headerRowNumber = WebTableGetRowNumber (oTable, Header)
ColumnNumber = WebTableGetColumnNumber(oTable, Header)
bReturn = False
'subtract the Header row number from the row count. If there are 0 or 1 rows in the table, don't worry about sort order, just
' say it's sorted, and exit
If oTable.GetROProperty("rows") - headerRowNumber <= 1 Then
WebTableVerifySortOrderInColumnAdv = True
Exit Function
Else
rowNumber = headerRowNumber + 1 'initialize the row number to the row below the header
For iRow = rowNumber + 1 To oTable.GetROProperty("rows")
sText1 = oTable.GetCellData(iRow - 1, ColumnNumber)
sText2 = oTable.GetCellData(iRow , ColumnNumber)
'If the sort order is descending, reverse the variables
If LCase( oOptions("SortOrder") ) = "descending" Then
sTemp = sText1
sText1 = sText2
sText2 = sTemp
End If
If sText1 < sText2 Then
bReturn = True
Else
'If we've found an exception to the intended sort order, short circuit out of here
WebTableVerifySortOrderInColumnAdv = False
Exit Function
End If
Next
End If
WebTableVerifySortOrderInColumnAdv = bReturn
End Function
RegisterUserFunc "WebTable", "VerifySortOrderInColumnAdv", "WebTableVerifySortOrderInColumnAdv", True
''' <summary>
''' Determines whether a cell exists
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="iColumn" type="Integer"></param>
''' <param name="iRow" type="Integer"></param>
''' <returns type="Boolean"></returns>
Public Function WebTableCellExists( oTable, iRow, iColumn)
sCellData = oTable.GetCellData(iRow, iColumn)
WebTableCellExists = isFalse(StringContains(sCellData, "ERROR: The specified cell does not exist."))
End Function
RegisterUserFunc "WebTable", "CellExists", "WebTableCellExists", True
''' <summary>
''' Get values from specified column
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sHeader" type="String">Column to grab</param>
''' <returns type="String()">Array of column values</returns>
Public Function WebTableGetColumnValues( oTable, sHeader )
WebTableGetColumnValues = WebTableGetColumnValuesAdv( oTable, sHeader, Null)
End Function
RegisterUserFunc "WebTable", "GetColumnValues", "WebTableGetColumnValues", True
''' <summary>
''' Get values from specified column
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sHeader" type="String">Column to grab</param>
''' <returns type="String()">Array of column values</returns>
Public Function WebTableGetColumnValuesAdv( oTable, sHeader, aOptions )
Set oOptions = getopts(Array("iFooterRows", 0), aOptions)
iFooterRows = oOptions("iFooterRows")
' For i = WebTableGetHeaderRow(oTable, sHeader) + 1 to oTable.rowCount
For i = 1 To oTable.rowCount - (WebTableGetHeaderRow(oTable, sHeader)) - iFooterRows
ArrayPush aReturn, WebTableGetXInColumn(oTable, sHeader, i)
'print WebTableGetXInColumn(oTable, sHeader, i)
Next
WebTableGetColumnValuesAdv = aReturn
' msgbox oTable.rowCount - (WebTableGetHeaderRow(oTable, sHeader) + 1)
End Function
RegisterUserFunc "WebTable", "GetColumnValuesAdv", "WebTableGetColumnValuesAdv", True
''' <summary>
''' Grabs contents of cell at Row X in the specified column
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String">Column in question</param>
''' <param name="iRow" type="Integer">Row number</param>
''' <returns type="String">Cell contents</returns>
Public Function WebTableGetXInColumn (ByRef oTable, Header, iRow)
headerRowNumber = WebTableGetHeaderRow (oTable, Header)
ColumnNumber = WebTableGetColumnNumber(oTable, Header)
'IsObject(oTable.ChildItem(headerRowNumber + iRow, ColumnNumber, "WebElement", 0))
If webTableCellExists(oTable, headerRowNumber + iRow, ColumnNumber) Then
WebTableGetXInColumn = Trim( oTable.GetCellData(headerRowNumber + iRow, ColumnNumber) )
End If
End Function
RegisterUserFunc "WebTable", "GetXInColumn", "WebTableGetXInColumn", True
''' <summary>
''' Gets the cell's WebElement based on the cell's position in the given column
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String"></param>
''' <param name="iRow" type="Integer"></param>
''' <returns type="WebElement"></returns>
Public Function WebTableCellXInColumn(ByRef oTable, Header, iRow)
headerRowNumber = WebTableGetHeaderRow (oTable, Header)
ColumnNumber = WebTableGetColumnNumber(oTable, Header)
Set WebTableCellXInColumn = WebTableGetCell(oTable, iRow + headerRowNumber, ColumnNumber )
End Function
RegisterUserFunc "WebTable", "CellXinColumn", "WebTableCellXInColumn"
''' <summary>
''' Gets a Cell's WebElement object based on the row and column numbers
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="iRow" type="Integer">Row Number</param>
''' <param name="iColumn" type="Integer">Column Number</param>
''' <returns type="WebElement"></returns>
Public Function WebTableGetCell(ByRef oTable, iRow, iColumn)
Set oRowDesc = descriptionBuild(Array("html tag", "TR"))
Set oRows = oTable.ChildObjects(oRowDesc)
Set oRow = oRows(iRow - 1)
Set oCells = oRow.ChildObjects(descriptionBuild(Array("html tag", "T[D|H]")))
iStartCol = 0
iCellCounter = 0
For i = 0 To oCells.count - 1
iStartCol = iStartCol + oCells(i).object.colSpan
If iStartCol >= CInt(iColumn) Then
Exit For
End If
iCellCounter = iCellCounter + 1
Next
Set oCell = oCells(iCellCounter)
Set WebTableGetCell = oCell
End Function
RegisterUserFunc "WebTable", "GetCell", "WebTableGetCell", True
''' <summary>
''' Gets a Cell's Image object based on the row and column numbers
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="iRow" type="Integer">Row Number</param>
''' <param name="iColumn" type="Integer">Column Number</param>
''' <returns type="Image"></returns>
Public Function WebTableGetCellImage(ByRef oTable, iRow, iColumn)
Set oRowDesc = descriptionBuild(Array("html tag", "TR"))
Set oRows = oTable.ChildObjects(oRowDesc)
Set oRow = oRows(iRow - 1)
Set oCells = oRow.ChildObjects(descriptionBuild(Array("html tag", "T[D|H]")))
iStartCol = 0
iCellCounter = 0
For i = 0 To oCells.count - 1
iStartCol = iStartCol + oCells(i).object.colSpan
If iStartCol >= CInt(iColumn) Then
Exit For
End If
iCellCounter = iCellCounter + 1
Next
Set oCell = oCells(iCellCounter)
Set WebTableGetCell = oCell
End Function
RegisterUserFunc "WebTable", "GetCell", "WebTableGetCell", True
''' <summary>
''' Finds the row number of sString in oTable relative to the header row
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sHeader" type="String"></param>
''' <param name="sString" type="String"></param>
''' <returns type="Integer()">Row Numbers relative to header row</returns>
Public Function WebTableFindStringInColumnAdv (ByRef oTable, sHeader, sString, aOptions)
Set oOptions = GetOpts( Array(_
"bJustFirstMatch", True _
), aOptions)
iHeaderRow = WebTableGetHeaderRow (oTable, sHeader)
ColumnNumber = WebTableGetColumnNumber(oTable, sHeader)
iMatches = 0
aReturn = Array()
For i = iHeaderRow + 1 To oTable.RowCount
If StringContains(Trim(oTable.GetCellData(i, ColumnNumber)), Trim(sString)) Then
arrayPush aReturn, i - iHeaderRow
iMatches = iMatches + 1
End If
Next
If oOptions("bJustFirstMatch") = True Then
If iMatches > 0 Then
WebTableFindStringInColumnAdv = aReturn(0)
Else
WebTableFindStringInColumnAdv = Null
End If
Else
WebTableFindStringInColumnAdv = aReturn
End If
End Function
RegisterUserFunc "WebTable", "FindStringInColumnAdv", "WebTableFindStringInColumnAdv"
''' <summary>
''' Finds the row number of sString in oTable relative to the header row
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sHeader" type="String"></param>
''' <param name="sString" type="String"></param>
''' <returns type="Integer">Row Number relative to header row</returns>
Public Function WebTableFindStringInColumn(ByRef oTable, sHeader, sString)
WebTableFindStringInColumn = WebTableFindStringInColumnAdv(oTable, sHeader, sString, Null)
End Function
RegisterUserFunc "WebTable", "FindStringInColumn", "WebTableFindStringInColumn"
''' <summary>
''' Gets the cell data from column X in the row where column Y has the value sYValue
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sXHeader" type="String"></param>
''' <param name="sYHeader" type="String"></param>
''' <param name="sYValue" type="String"></param>
''' <returns type="String">cell data of target cell</returns>
Public Function WebTableGetXWhereYisString (ByRef oTable, sXHeader, sYHeader, sYValue)
Yrow = WebTableFindStringInColumn (oTable, sYHeader, sYValue)
If Not IsNull(Yrow) Then WebTableGetXWhereYisString = WebTableGetXInColumn (oTable, sXHeader, Yrow)
End Function
RegisterUserFunc "WebTable", "GetXWhereYisString", "WebTableGetXWhereYisString"
''' <summary>
''' Finds the row of sYValue in oTable and clicks a link object in column X
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sXHeader" type="String"></param>
''' <param name="sYHeader" type="String"></param>
''' <param name="sYValue" type="String"></param>
''' <returns type="Boolean">True on success</returns>
Public Function WebTableClickXWhereYisString (ByRef oTable, sXHeader, sYHeader, sYValue)
Yrow = WebTableFindStringInColumn (oTable, sYHeader, sYValue)
If Not IsNull(Yrow) Then WebTableClickXWhereYisString = WebTableClickXInColumn (oTable, sXHeader, Yrow)
End Function
RegisterUserFunc "WebTable", "ClickXWhereYisString", "WebTableClickXWhereYisString"
''' <summary>
''' Clicks an element in the specified column of row X (iRow)
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String"></param>
''' <param name="iRow" type="Integer">Row Number relative to header row</param>
''' <returns type="Boolean">True on success</returns>
Public Function WebTableClickXInColumn (ByRef oTable, Header, iRow)
iHeaderRow = WebTableGetHeaderRow (oTable, Header)
ColumnNumber = WebTableGetColumnNumber(oTable, Header)
bReturn = False
'If IsObject(oTable.ChildItem(iHeaderRow + iRow, ColumnNumber, "WebElement", 0)) Then
If oTable.ChildItemCount( iHeaderRow + iRow, ColumnNumber, "WebElement" ) > 0 Then
oTable.ChildItem(iHeaderRow + iRow, ColumnNumber, "WebElement", 0).Click
bReturn = True
End If
WebTableClickXInColumn = bReturn
End Function
RegisterUserFunc "WebTable", "ClickXInColumn", "WebTableClickXInColumn", True
''' <summary>
''' Clicks the column header specified by the Header parameter
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String"></param>
''' <returns type="Boolean">True on success</returns>
Public Function WebTableClickHeader (ByRef oTable, Header)
iHeaderRow = WebTableGetHeaderRow (oTable, Header)
ColumnNumber = WebTableGetColumnNumber(oTable, Header)
bReturn = False
If IsObject(oTable.ChildItem(iHeaderRow, ColumnNumber, "WebElement", 0)) Then
oTable.ChildItem(iHeaderRow, ColumnNumber, "WebElement", 0).Click
bReturn = True
End If
WebTableClickHeader = bReturn
End Function
RegisterUserFunc "WebTable", "ClickHeader", "WebTableClickHeader", True
''' <summary>
''' Returns the row number of the Header row as determined by the Header parameter. Returns 0 if there is no header row.
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String"></param>
''' <returns type="Integer">Header row number</returns>
Public Function WebTableGetHeaderRow (ByRef oTable, Header)
WebTableGetHeaderRow = 0
If stringContains(Header, "^#/d+$") Then
Set oRows = oTable.object.getElementsByTagName("TR")
For i = 0 To oRows.Length - 1
If oRows(i).GetElementsByTagName("TH").length > 0 Then
WebTableGetHeaderRow = i + 1
End If
Next
Else
WebTableGetHeaderRow = WebTableGetRowNumber (oTable, Header)
End If
End Function
RegisterUserFunc "WebTable", "GetHeaderRow", "WebTableGetHeaderRow", True
''' <summary>
''' Clicks on the first link in the specified column
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="Header" type="String"></param>
''' <returns type="Boolean">True for success</returns>
Public Function WebTableClickFirstInColumn (ByRef oTable, Header)
WebTableClickXInColumn oTable, Header, 1
End Function
RegisterUserFunc "WebTable", "ClickFirstInColumn", "WebTableClickFirstInColumn", True
''' <summary>
''' Clicks iRow in oTable
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="iRow" type="Integer">Index of row to click</param>
''' <returns type=""></returns>
Public Function WebTableClickRow (ByRef oTable, iRow)
Set oRow = oTable.object.rows(iRow)
oRow.click
WebTableClickRow = True
End Function
RegisterUserFunc "WebTable", "ClickRow", "WebTableClickRow"
''' <summary>
''' Clicks the row where column Y contains the specified string
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sYHeader" type="String"></param>
''' <param name="sYValue" type="String"></param>
''' <returns type="Boolean">True on success</returns>
Public Function WebTableClickRowWhereYisString (ByRef oTable, sYHeader, sYValue)
WebTableClickRowWhereYisString = False
iRowNumber = WebTableFindRowWhereYisString(oTable, sYHeader, sYValue)
If iRowNumber > 0 Then WebTableClickRowWhereYisString = WebTableClickRow (oTable, iRowNumber)
End Function
RegisterUserFunc "WebTable", "ClickRowWhereYisString", "WebTableClickRowWhereYisString"
''' <summary>
''' Gets the row number (relative to the header row) where column Y contains sYValue
''' </summary>
''' <remarks>Because ClickRowWhereYisString calls this, it's unit tests doubles for FindRowWhereYisString</remarks>
''' <param name="oTable" type="WebTable"></param>
''' <param name="sYHeader" type="String"></param>
''' <param name="sYValue" type="String"></param>
''' <returns type="Integer">Returns row number or 0 if it isn't found</returns>
Public Function WebTableFindRowWhereYisString (ByRef oTable, sYHeader, sYValue)
iReturn = 0
Yrow = WebTableFindStringInColumn (oTable, sYHeader, sYValue)
If Yrow > 0 Then iReturn = Yrow
WebTableFindRowWhereYisString = iReturn
End Function
RegisterUserFunc "WebTable", "FindRowWhereYisString", "WebTableFindRowWhereYisString"
''' <summary>
''' Returns a list of row numbers matching dictCriteria
''' </summary>
''' <param name="dictCriteria" type="Dictionary"></param>
''' <param name="aOptions" type="Object"></param>
''' <returns type="Integer()"></returns>
Public Function WebTableFindRowsAdv( oTable, dictCriteria, aOptions )
Set oOptions = getopts( Array( _
"bJustFirstMatch", False _
), aOptions)
bFirstTime = True
aKeys = dictCriteria.Keys
aPotentialMatches = Array()
For i = 0 To UBound(aKeys)
sColumnHeader = aKeys(i)
sMatchPattern = dictCriteria.Item(sColumnHeader)
aMatches = WebTableFindStringInColumnAdv(oTable, sColumnHeader, sMatchPattern, Array("bJustFirstMatch", False))
If bFirstTime = True Then
aPotentialMatches = aMatches
Else
aPotentialMatches = arrayCommonElements(aPotentialMatches, aMatches)
End If
bFirstTime = False
Next
If oOptions("bJustFirstMatch") = False Then
WebTableFindRowsAdv = aPotentialMatches
Else
If UBound(aPotentialMatches) = -1 Then
WebTableFindRowsAdv = 0
Else
WebTableFindRowsAdv = aPotentialMatches(0)
End If
End If
End Function
RegisterUserFunc "WebTable", "FindRowsAdv", "WebTableFindRowsAdv"
''' <summary>
''' Clicks the table's first row
''' </summary>
''' <param name="oTable" type="WebTable"></param>
''' <returns type="Boolean">True on success</returns>
Public Function WebTableClickFirstRow (ByRef oTable)
WebTableClickFirstRow = False
HeaderRow = WebTableGetHeaderRow (oTable, "#1")
WebTableClickFirstRow = WebTableClickRow (oTable, HeaderRow + 1 - 1 )
End Function
RegisterUserFunc "WebTable", "ClickFirstRow", "WebTableClickFirstRow"
'################ INCOMPLETE FUNCTIONS BELOW
'@Description Clicks on the check box specified in row, or if row is a string, it finds the text and clicks the checkbox in the corresponding row
'TODO enable them to search under a column header (str) or column index (int)
Public Function WebTableCheckBox (ByRef oTable, sString, Setting)
If StringIsEmpty(Setting) Then
Setting = "OFF"
End If
'After the analysis is done, this var will contain the row specified (or found)
Dim iRow
If TypeName(sString) = "Integer" Then
iRow = sString
Else
sCoords = WebTableGetCellCoords(oTable, sString)
'If the search text was found in the table, check the first check box you can find
If sCoords <> "0" Then
Dim aCoords
aCoords = Split(sCoords, ",")
iRow = aCoords(0)
End If
End If
'We've found the row - now find the column where there exists a checkbox
For ColumnNumber = 1 To oTable.ColumnCount(iRow)
Set oCheckBox = oTable.ChildItem(iRow, ColumnNumber, "WebCheckBox", 0)
If TypeName(oCheckBox) <> "Nothing" Then
WebCheckBoxSmartSet oCheckBox, Setting
WebTableCheckBox = True
End If
Next
'If the search text was not found in the table, do nothing, just return false
WebTableCheckBox = False
End Function
RegisterUserFunc "WebTable", "CheckBox", "WebTableCheckBox", True