'------
'THE WEBSITE I'M TESTING IS www.gamersfirst.com - currently I'm working on its home page
'------
'======
'Function to count pages on a browser
'======
Public Function sPage()
'set the broser
Set gBrowser = GlobalDictionary("gBrowser")
'declare an dynamic array
Dim temp()
'create an object
Set pDesc = Description.Create()
'set it class as page
pDesc("micclass").Value = "Page"
'get the page child objects
Set pList = gBrowser.ChildObjects(pDesc)
'store the number of page objects
GlobalDictionary("numPage") = pList.Count()
're-declare the dynamic array with number of items equals the number of page elements
ReDim Preserve temp(GlobalDictionary("numPage")-1)
'copy the array elements from pLists to temp
For y = 0 to GlobalDictionary("numPage")-1
Set temp(y) = pList(y)
Next
'return the sPage object
sPage = temp
End Function
'======
'Function to get and store a particular type of objects from the page
'======
Public Function sElement(sPage, eT)
'set the type variable
eType = eT
'declare an dynamic array
Dim tempG()
'create an element description
Set eDesc = Description.Create()
eDesc("micclass").Value = eType
'get the list of child objects matching the object description
Set eList = sPage.ChildObjects(eDesc)
'get the count of objects of description eType
eCount = eList.Count()
'set the respecitve global count variable
Select Case eType
Case "WebEdit"
GlobalDictionary("numEdit") = eCount
Case "WebElement"
GlobalDictionary("numWebEl") = eCount
Case "WebButton"
GlobalDictionary("numBtn") = eCount
Case "Link"
GlobalDictionary("numLink") = eCount
End Select
're-declare the dynamic array with number of items equals the number of page elements
ReDim Preserve tempG(eCount-1)
'copy the array elements from WElLists to temp
For y = 0 to eCount-1
Set tempG(y) = eList(y)
Next
'return the sWebElement object
sElement = tempG
End Function
'======
'======
'------XML FUNCTIONS ------
'======
'======
'======
'add page element
'======
Public Function xmlAddPage(eP, pIndex, ip)
'set index as index of the browser
index =cStr(ip+1)
Set ePg = eP
'create and open a xml object
Set xmlD = XMLUtil.CreateXML()
xmlD.LoadFile "z:\smoke.xml"
Set root = xmlD.GetRootElement()
'set the browser element
Set children = root.ChildElements()
Set eBrowser = children.ItemByName("Browser")
'add a page element
eBrowser.AddChildElementByName "Page", ePg.GetROProperty("title")
'save the xml doc
xmlD.SaveFile "z:\smoke.xml"
'get the index of the browser / parent
Set bChildren = eBrowser.ChildElements()
'Set bAttr = eBrowser.Attributes
' 'set the index of the page as "browserindex_pageindex"
' i = 1
' Do while i < bAttr.Count()
'
' Set attr = bAttr.Item(i)
'
' If lcase(attr.Name()) = "index" Then
'
' index = attr.Value() & "_" & index
'
' 'once the index is found, exit do while loop
' Exit do
' End If'
' Loop
index = pIndex & "." & index
'set the page element
Set ePage = bChildren.ItemByName("Page")
'add attributes to page element
ePage.AddAttribute "index", index
ePage.AddAttribute "Description", "Page on G1 Home"
'save the xml document
xmlD.SaveFile "z:\smoke.xml"
'return the index of the page
xmlAddPage = index
End Function
'======
'======
'======
'add an element node to the page node
'======
Public Function xmlAddElementNode(eE, pIndex, ix, ip, eT)
'set index as index of the browser
'add a leading zeroes to make index a 3 digit string
If ix < 9 Then
index = "00" & cStr(ix+1)
ElseIf index < 99 Then
index = "0" & cStr(ix+1)
Else
index =cStr(ix+1)
End If
Set eEle = eE
eType = eT
'create and open a xml object
Set xmlD = XMLUtil.CreateXML()
xmlD.LoadFile "z:\smoke.xml"
Set root = xmlD.GetRootElement()
'set the browser element
Set children = root.ChildElements()
Set eBrowser = children.ItemByName("Browser")
'get the index of the parent
Set bChildren = eBrowser.ChildElements()
Set ePage = bChildren.Item(ip)
'Add the element node
ePage.AddChildElementByName eType, ""
'save the xml doc
xmlD.SaveFile "z:\smoke.xml"
'set the page element
Set pChildren = ePage.ChildElements()
Set eElementColl = pChildren.AllItemsByName(eType)
Set eElement = eElementColl.Item(ix+1)
'create a customized index extention
Select Case eType
Case "WebEdit"
temp2 = ".1"
Case "WebElement"
temp2 = ".2"
Case "WebButton"
temp2 = ".3"
Case "Link"
temp2 = ".4"
End Select
'set the index
index = pIndex & temp2 & index
'add attributes to page element
eElement.AddAttribute "index", index
'add name attribute for all but webelement
If eType > "WebElement" Then
eElement.AddAttribute "name", eEle.GetROProperty("name")
'add width for webelement only
Else
eElement.AddAttribute "width", CStr(eEle.GetROProperty("width"))
End If
'add disabled for webedit or webbutton
If eType = "WebEdit" or eType = "WebButton" Then
eElement.AddAttribute "disabled", CStr(eEle.GetROProperty("disabled"))
End If
'add innertext for webelement or link
If eType = "WebElement" or eType = "Link" Then
eElement.AddAttribute "innertext", eEle.GetROProperty("innertext")
End If
'add html tag and html id for webelement and webbutton
If eType = "WebElement" or eType = "WebButton" Then
eElement.AddAttribute "html_tag", eEle.GetROProperty("html tag")
eElement.AddAttribute "html_id", eEle.GetROProperty("html id")
End If
'add href and height for link
If eType = "Link" Then
eElement.AddAttribute "href", eEle.GetROProperty("href")
eElement.AddAttribute "height", CStr(eEle.GetROProperty("height"))
End If
'save the xml document
xmlD.SaveFile "z:\smoke.xml"
End Function
'======
'======
'
'======
'add attributes to Page node
'======
Public Function xmlAddAttribute(indx, atName, atValue)
'set index as index of the browser
index = indx
'create and open a xml object
Set xmlD = XMLUtil.CreateXML()
xmlD.LoadFile "z:\smoke.xml"
Set root = xmlD.GetRootElement()
'set the browser element
Set children = root.ChildElements()
Set eBrowser = children.ItemByName("Browser", 1)
Set bChildren = eBrowser.ChildElements()
Set ePage = bChildren.ItemByName("Page", index+1)
'Set ePage = eElementColl.Item(index+1)
'add attributes to page element
ePage.AddAttribute atName, CStr(atValue)
'save the xml document
xmlD.SaveFile "z:\smoke.xml"
End Function
'======
'======