|
' configures framework to work within the context of a specific frame
' val - the Name of the frame to work within -- use Object Spy if you don't
' already know the frame name
Public Function WorkInFrame (val)
Report micPass, "Enter Frame", "Entered scope of frame " & Quote(val)
thirdlevel = val
End Function
' configures the framework to work outside the context of a specific frame
Public Function StopWorkingInFrame
Report micPass, "Exit Frame", "Exited scope of frame " & Quote(thirdlevel)
thirdlevel = ""
End Function
' generates a string with embedded/surrounding quotes
Public Function Quote (txt)
Quote = chr(34) & txt & chr(34)
End Function
' navigate to a site if the browser is already opened, otherwise run initialization
Public Function BrowseTo (url)
thirdlevel = ""
Report micPass, "Navigate to URL", "Navigating to URL: " & Quote(url)
If initialized Then
Execute GenerateDescription("Browser") & "Navigate " & Quote(url)
Else
Launch "website", url
End If
Reporter.Filter = rfDisableAll
End Function
' waits for the web page to finish loading
Public Function AutoSync
Execute GenerateDescription("Browser") & "Sync"
End Function
' close all opened browsers
Public Function CloseBrowsers
If Browser("micclass:=Browser").Exist (0) Then
Browser("micclass:=Browser").Close
End If
While Browser("micclass:=Browser", "index:=1").Exist (0)
Browser("index:=1").Close
Wend
If Browser("micclass:=Browser").Exist (0) Then
Browser("micclass:=Browser").Close
End If
End Function
' prepares the framework for usage, and configures all internal framework
' variables and structures
' apptype - used to launch different types of applications based
' upon different technologies -- currently there is only web
' val - string that represents what to launch
' returns - always returns true
Public Function Launch (apptype, val)
If "website" = apptype Then
thirdlevel = ""
Report micPass, "Initialize", "Initializing Framework"
level = split(webLevels, leveldelimiter, -1, 1)
desc = split(webLevelsDesc, leveldescdelimiter, -1, 1)
object = split(objects, objectdelimiter, -1, 1)
objectDescription = split(objectsDescription, objectsDescriptiondelimiter, -1, 1)
CloseBrowsers
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = true
IE.Navigate val
While IE.Busy
wait 1
Wend
End If
initialized = true
Launch = true
End Function
' Verify the Existence of an object
' objtype - values should be limited to values in the object array
' text - multi-purpose argument that indicates what to verify
' - for a link, or button, it's the text of the control
' - for a list, it's the name of the control
' - for a frame, it's the name of the frame
Public Function Verify (objtype, text)
rval = false
localDesc = ""
estr = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If
AutoSync()
Select Case objtype
Case "Page"
Execute "rval = " & GenerateDescription(level(1)) & "Exist (0)"
If rval Then
Execute "title = " & GenerateDescription(level(1)) & "GetROProperty(" & Quote("title") & ")"
If title = text Then
rval = true
Else
rval = false
End If
End If
Case "CurrentFrame"
If thirdlevel <> "" Then
estr = "rval = " & localDesc
End If
Case "Link"
estr = "rval = " & localDesc & GenerateObjectDescription("Link", "innertext:=" & text)
Case "WebButton"
estr = "rval = " & localDesc & GenerateObjectDescription("WebButton", "value:=" & text)
Case "WebList"
estr = "rval = " & localDesc & GenerateObjectDescription("WebList", "name:=" & text)
Case "WebEdit"
estr = "rval = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & text)
End Select
If estr <> "" Then
Execute estr + "Exist (0)"
End If
If rval Then
Report micPass, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was verified to exist"
Else
Report micFail, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was not found"
End If
If "True" = rval Then
rval = True
Else
rval = False
End If
Verify = rval
End Function
' Activates an object based upon its object type
' objtype - the type of object should be limited to values in the object array
' text - identifying text for the control - for a link, it's the text of the link
Public Function Activate (objtype, text)
localDesc = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If
AutoSync()
Select Case objtype
Case "Link"
Execute localDesc & GenerateObjectDescription("Link","innertext:=" & text) & "Click"
Report micPass, "Link Activation", "The Link " & Quote(text) & " was clicked."
Case "WebButton"
Execute localDesc & GenerateObjectDescription("WebButton", "value:=" & text) & "Click"
Report micPass, "WebButton Activation", "The WebButton " & Quote(text) & " was clicked."
' 扩展对Image类型的按钮的支持
Case "Image"
Execute localDesc & GenerateObjectDescription("Image", "alt:=" & text) & "Click"
Report micPass, "ImageButton Activation", "The ImageButton " & Quote(text) & " was clicked."
End Select
End Function
' Selects a specific value from a listbox, or combobox
' objname - name of the control -- use Object Spy if you don't know the name property
' text - the item in the combobox to select
Public Function SelectFromList (objname, text)
localDesc = ""
rv = ""
rval = false
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If
AutoSync()
localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objname)
Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
For i = 1 to cnt
Execute "rv = " & localDesc & "GetItem (" & i & ")"
If rv = text Then
rval = true
End If
Next
If rval Then
Execute localDesc & "Select " & Quote(text)
End If
If rval Then
Report micPass, "WebList Selection", "The WebList item " & Quote(text) & " was selected."
Else
Report micFail, "WebList Selection", "The WebList item " & Quote(text) & " was NOT found."
End If
SelectFromList = rval
End Function
' Enters text into an edit field
' objname - name of the control -- use Object Spy if you don't know what it is
' text - the text to enter into the control
Public Function EnterTextIn (objname, text)
localDesc = ""
rval = true
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If
AutoSync()
localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objname)
Execute localDesc & "Set (" & Quote(text) & ")"
Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objname)
EnterTextIn = rval
End Function
' Obtains text from a control
' objtype - is the type of control the get the text from
' objname - is the name of the control -- use Object Spy if you don't know the name
' returns - the text of the control
Public Function GetTextFrom (objtype, objname)
text = ""
localDesc = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If
AutoSync()
Select Case objtype
Case "WebEdit"
Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
Case "WebList"
Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
End Select
Report micPass, "Capture Text", "Text: " & Quote(text) & " was captured from the control " & Quote(objname)
GetTextFrom = text
End Function
' Wrapper for the Reporter.Report Event method
' - could be used to create custom reports more easily
' See Reporter.ReportEvent documentation for usage
Public Function Report (status, objtype, text)
Reporter.Filter = rtEnableAll
Reporter.ReportEvent status, objtype, text
Reporter.Filter = rfDisableAll
End Function |
|