谁知道SAFFRON
请问SAFFRON是一个什么样的框架?是工具么?可以下载么?谢谢。
Mercury SAFFRON
http://www.uml.org.cn/Test/200810108.asp[ 本帖最后由 shanxi 于 2009-4-10 09:41 编辑 ]
S.A.F.F.R.O.N
一部分'************************************************************
' S.A.F.F.R.O.N. Prototype 1.1'
' Simple Automation Framework For Remarkably Obvious Notes
' Copyright © 2006 Mercury Interactive Corporation
'
' Notes:
'
' Requires QuickTest Professional 9.1
'
' Author : Adam Gensler
' Created : July 12, 2006
' Last Updated : September 11, 2006
'
' This prototype framework is provided AS IS, and is meant
' to be used for instructional purposes.
'
' This framework is a prototype, and is not supported
' by Mercury Interactive.
'
'************************************************************
initialized = false
thirdlevel = ""
level = ""
desc = ""
object = ""
objectDescription = ""
levelsubdescripti
leveldescdelimiter = "|"
objectdelimiter = "|"
leveldelimiter = "|"
objectsDescripti
webLevels = "Browser|Page|Frame"
webLevelsDesc = "micclass:=Browser|micclass:=Page|micclass:=Frame|"
' 扩展对Image对象的支持
objects = "Link|WebButton|WebList|WebEdit|Image"
objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image"
' Generates a generic description based up on the "level" viarable
' levelstr - will be one of the values that is in the level array
' returns - string representative of the object hierarchy
Public Function GenerateDescription (levelstr)
l = IndexOf(level, levelstr)
If l >=0 Then
fdesc = level(0) & "(" & Quote(desc(0)) & ")."
If l >= 1 Then
fdesc = fdesc + level(1) & "(" & Quote(desc(1)) & ")."
If 2 >= l Then
If thirdlevel <> "" Then
fdesc = fdesc + level(2) & "(" & Quote(desc(2)) & "," & Quote("name:=" & thirdlevel) & ")."
End If
End If
End If
End If
GenerateDescription = fdesc
End Function
' Generates an object description based upon the object, and objectDescription arrays
' obj - name of the object in the object array
' prop - additional property to help uniquely identify the object
' returns - a string representative of the object description
Public Function GenerateObjectDescription (obj, prop)
i = IndexOf(object, obj)
ndesc = ""
If i <> -1 Then
ndesc = obj & "(" & Quote(objectDescription(i)) & "," & Quote(prop) & ")."
End If
GenerateobjectDescription = ndesc
End Function
' given an array, returns the index of the value to search for
' ary - an array
' str - value to search for in an array
' returns - index in array
Public Function IndexOf (ary, str)
val = -1
For i = 0 to UBound(ary)
If ary(i) = str Then
val = i
End If
Next
IndexOf = val
End Function ' 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 知道了,谢谢各位~
页:
[1]