QTP面向对象的框架

发表于:2009-12-21 13:43

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:陈能技(CSDNBlog)    来源:51Testing软件测试网采编

  这种框架的核心思想是把某个窗口的测试对象和相关业务核心操作都封装在VBS的类中,称之为GUI层,或者叫GUI-业务桥接层。例如下面的登录界面类:

' 登录界面类,封装了界面对象数据以及相关业务操作
Class Login
  Private m_htChildObjects 'As Scripting.Dictionary
 
  Public Property Get ChildObjects()
    Set ChildObjects = m_htChildObjects
  End Property
 
  Public Property Let ChildObjects(ByRef dic)
    Set m_htChildObjects = dic
  End Property
 
  ' 初始化界面对象并验证对象是否存在
  Public Function Init()
    ChildObjects = CreateObject("Scripting.Dictionary")
    With ChildObjects
        .Add "LoginDialog", Dialog("text:=Login")
        .Add "AgentName", ChildObjects.Item("LoginDialog").WinEdit("attached text:=Agent Name:")
        .Add "Password", ChildObjects.Item("LoginDialog").WinEdit("attached text:=Password:")
        .Add "Submit", ChildObjects.Item("LoginDialog").WinButton("text:=OK")
    End With
    'IsContextLoaded is a function that iterates through the Dictionary and checks if the GUI objects "exist"
    Init = IsContextLoaded(ChildObjects)   ' 检查界面层对象是否存在
  End Function
 
  ' 与界面对象绑定的各类业务操作
  ' 测试数据从GlobalDictionary中获取(放在Data层),这里把测试数据做成函数参数可能会更好?!
  Public Function SetUsername()
    ChildObjects.Item("AgentName").Set GlobalDictionary.Item("AgentName") 
  End Function
 
  Public Function SetPassword()
    ChildObjects.Item("Password").Set GlobalDictionary.Item("Password") 
  End Function
 
  Public Function Submit()
       ChildObjects.Item("Submit").Click
  End Function
 
End Class
 
Public Function CreateLogin()
    Dim objLogin
    Set objLogin = New Login
    Set CreateLogin = objLogin
End Function

21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号