分层设计方法-GUI层
'这里通过把百度搜索封装成GUI层作为例子来举例:
Class BaiduSearch
Private m_htChildObjects '定义变量作为Scripting.Dictionary
'***********为变量设置Get Set方法*************
Public Property Get ChildObjects()
Set ChildObjects = m_htChildObjects
End Property
Public Property Let ChildObjects(ByRef dic)
Set m_htChildObjects = dic
End Property
'*************初始化GUI界面上的测试对象*************
Public Function Init()
ChildObjects = CreateObject("Scripting.Dictionary")
With ChildObjects
.Add "Browser", Browser("name:=百度一下, 你就知道")
.Add "Page", ChildObjects.item("Browser").Page("title:=百度一下, 你就知道")
.Add "SearchContent", ChildObjects.item("Page").WebEdit("html id:=k")
.Add "Submit", ChildObjects.item("Page").WebButton("value:=百度一下")
End With
Init = IsContextLoaded(ChildObjects)
End Function
'**********业务行为函数 - 百度输入搜索内容**************
Public Function SetSearchContent()
ChildObjects.item("SearchContent").Set "zzxxbb112"
End Function
'***********业务行为函数 - 百度点击搜索***************
Public Function Submit()
ChildObjects.item("Submit").Click
End Function
End Class
'*******检查GUI层所有对象是否已经存在,并返回结果,避免运行中途停止
Public Function IsContextLoaded(ByRef htContext)
Dim allExist, ix, aItems, aKeys, strDetails, strAdditionalRemarks
allExist = True
aItems = htContext.Items
aKeys = htContext.Keys
For ix = 0 To htContext.Count - 1
IsContextLoaded = aItems(ix).Exist(0)
strDetails = strDetails & vbNewLine & "Object #" & ix+1 & ": '" & akeys(ix) & "' was"
If IsContextLoaded Then
strDetails = strDetails & ""
strAdditionalRemarks = ""
Else
strDetails = strDetails & " not"
strAdditionalRemarks = " Please check the object properties"
allExist = False
End If
IsContextLoaded = IsContextLoaded And allExist
Select Case IsContextLoaded
Case True intStatus = micPass
Case False intStatus = micWarning
End Select
strDetails = strDetails & " found." & strAdditionalRemarks
Next
Reporter.ReportEvent intStatus, "IsContextLoaded", strDetails
End Function
'******调用********
Public Function CreateLogin()
Dim objLogin
Set objLogin = New BaiduSearch
Set CreateLogin = objLogin
End Function