Function load data from Word Doc to XML file
Function GetTableData2
Function GetColumnNumber
Function clickRadio
Function getDatatype
Function dropDowngetValue
Function getRandomNum
Function verifyWebElement
Function pageWait
Function checkStringLength
Function handle unexpected Window on Page
Function Counting records in WebTable
Function Verify existance of the data in the table
Function CwLogin(Env, UID, PWD)
========================================================================================
' Function load data from Word Doc to XML file appeand superSize text and set back to Word Doc
' =====================================
'' =====================================
Public Function loadWordDoc(strBrowser, strPage)
On Error resume next
loadWordDoc = -1
set pg = Browser("name:=" & strBrowser).Page("title:=" & strPage ).Object
Set word = pg.WordAx
t = word.DocumentText
'word.DocumentText = "5th "
xml = word.DocumentXML
Set doc = XMLUtil.CreateXML()
doc.Load xml
doc.SaveFile "c:\temp\word.xml"
Set pars = doc.ChildElementsByPath("/w:wordDocument/w:body/wx:sect/w:p")
set lastPar = pars.Item(pars.count)
val = lastPar.Value
Set pText = XMLUtil.CreateXML()
Set sText = XMLUtil.CreateXML()
pText.Load "
sText.Load "
lastPar.AddChildElement(pText.GetRootElement())
lastPar.AddChildElement(sText.GetRootElement())
word.DocumentXML = doc.ToString()
'Set doc1 = XMLUtil.CreateXMLFromFile("c:\temp\word.xml")
'word.DocumentXML = doc1.ToString()
'msgbox xml
If Err.Number <> 0 Then
Err.Clear
End If
loadWordDoc = 0
End Function
' ==========================================
' ==========================================
Function GetTableData2
Public Function GetTableData2(strBrowser, strPage, strTable, numRow, numColumn, subString, strFlag)
On error resume next
GetTableData = -1
Set objPg = Browser("name:="& strBrowser).Page("title:="& strPage)
Select Case strFlag
Case "noData"
strData = objPg.WebTable("name:=Index", "innertext:=Index.*").GetCellData(numRow, numColumn)
Case "NoData"
If strData = "" Then
GetTableData = 0
msgbox "result1 "
GetTableData = 0
Err.Clear
Exit Function
End If
Case "sub"
strData = objPg.WebTable("name:=Index", "innertext:=Index.*").GetCellData(numRow, numColumn)
Case "SubStingExist"
If inStr (strData, subString) > 0 Then
myArr = Split(strData, " ")
If Ubound(myArr) >0 Then
GetTableData = 0
Err.Clear
Exit Function
End IF
End IF
End Select
If Err.Number <> 0 Then
Err.Clear
End If
End Function
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
'====================================================================
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
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
''' =================================================
''' 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
''' 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
getRandomNum(RandNum)
Function getRandomNum(RandNum)
RandNum = RandomNumber (100000000, 999999999)
Err.Clear
getRandomNum = 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
''' 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
''' ================================================
''' 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
' Function handle unexpected Window on Page
' strBrowser - Name of the Browser
' strPage - Title of the Page
'
''' s = UnexpectedWindow("CPortal","CView 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
48. ==========================================================
''' Counting records in WebTable.
''' c = CountRecords("Popup Select", "Popup Select", "SPAN", "2767", outResult)
''' strBrowser - Browsers Name
''' strPage - Pages Name
''' strHTML - Tags Name
''' intExpected - Expected quantity of records
'' outResult -
''' ==============================================================
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
'=================================================================================================
'
' Verify existance of the data in the table
'
' Input: strBrowser - "
' strTableID - "treeTable"
' strFind - "Any search string"
' strFindMore- could be empty or another search string
'=================================================================================================
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 CwLogin(Env, UID, PWD)
Function CwLogin(Env, UID, PWD)
Dim strURL, objUser
Select Case LCase(Env)
Case "dev"
strURL = "https://"
Case "sit"
strURL = "https"
Case "uat"
strURL = ""
Case "prodfix"
strURL = ""
Case "production"
strURL = ""
End Select
Set objUser = New TestUser
With objUser
.App = "cv"
.UserID = UID
.PWD = PWD
.Domain = "qa-ent"
.URL = strURL
.PageTitle = ""
.Sample = ""
End with
If objUser.Login("IEXPLORE.EXE") = False Then
cwLogin = -1
Else
CwLogin = 0
End If
If Err.Number <> 0 Then Err.Clear
End Function