透析QTP自动化测试框架SAFFRON(下)

发表于:2009-5-25 15:08

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

 作者:未知    来源:网络转载

  4.7 检查对象是否存在

  前面的小例子仅仅实现了启动浏览器、导航、点击链接和按钮的功能,如果要组成一个完整的测试用例,还缺少一些东西,例如检查指定的对象是否存在,在SAFFRON中,用Verify函数来实现这个功能,Verify函数的定义如下所示:

' 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

  由于判断不同对象的存在需要采用不同的属性,因此Verify函数中对不同的对象类型进行判断、分别处理。例如,对于Link类型的对象,用innertext属性,对于WebButton,则采用value属性,但是最后都需要组合成一条语句,后接"Exist",通过Execute方法执行这个语句,从而实现对象是否存在的判断。

  对于页面对象(Page)的存在性检查有点不一样,采用的是以下脚本:

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

  通过GetROProperty方法获取当前页面的title属性,然后与传入的"text"参数进行比较,如果相等,则认为页面对象是存在的。

  在测试脚本中可以这样使用Verify函数:

' 启动浏览器

Launch "website","http://127.0.0.1:1080"

' 导航到“http://127.0.0.1:1080/WebTours”

BrowseTo "http://127.0.0.1:1080/WebTours/"

If Verify ("Link","administration")= False then

Reporter.ReportEvent micFail,"检查链接","链接不存在"

Else

' 点击名为“administration”的链接

Activate "Link","administration"

End IF

  脚本中先用Verify检查名为"administration"的链接对象是否存在,如果不存在则提示错误,如果存在则进一步调用Activate函数点击链接。

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

精彩评论

  • iorising
    2011-7-18 12:22:16

    收藏

  • vickywang_no1
    2009-9-24 16:54:00

    看完了,有意思。受益匪浅。

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号