51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4148|回复: 15
打印 上一主题 下一主题

[原创] 发点有质量的贴——QTP自定义检查点

[复制链接]

该用户从未签到

1#
发表于 2010-9-12 12:48:29 | 显示全部楼层

请教一个问题

楼主你好,我想请问一下,在你代码里面的obj是怎么定义的呢?我测试了一下你的代码总是出错,我的是obj = Window("Flight Reservation").Dialog("Flight Reservations").Static("The information has changed.").GetROProperty("text")     谢谢!在线等
回复 支持 反对

使用道具 举报

该用户从未签到

2#
发表于 2010-9-12 22:47:15 | 显示全部楼层

回复楼上

非常感谢您的回复,但我这里还有有问题,其实我的目的就是设置一个TextCheckpoint,strText是期望结果,obj是被测对象。代码如下:

Dim a
Dim b

Function Check_Objects_Text(obj,strText)
   Dim i
   Dim Cnt
        strText = "The information has changed.Save changes?"
        obj = Window("Flight Reservation").Dialog("Flight Reservations").Static("The information has changed.")
                txtArray = Split(obj.GetVisibleText(),vbCrLf,-1,1)
    Cnt = UBound(txtArray)  '取数组上限
        For i = 0 to Cnt
                If   Trim(txtArray(i)) = Trim(strText) Then
                        'Reporter.ReportEvent micPass,"检查字符串是否一致","界面中包含字符串:"&strText
                                                Msgbox("Pass")
                        Exit Function           
                End If
        Next
                        'Reporter.ReportEvent micFail,"检查字符串是否一致","界面中不包含字符串:"&strText
                                                Msgbox("Fail")
End Function

a = obj                   'Window("Flight Reservation").Dialog("Flight Reservations").static("The information has changed. Save changes?").GetROProperty("text")
b = strText               '"The information has changed. Save changes?"   

Check_Objects_Text a,b


报的错是:Object doesn't support this property or method
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2010-9-18 15:08:24 | 显示全部楼层
谢谢lantianwei 的积极回复。后来我没有用Split函数来通过比较每个字母是否相同来判断两个字符串是否相同,而是用strComp函数来直接比较两个字符串。现将我的代码复制如下,测的是QTP自带的小飞机程序,供大家指点:
Dim a,b
a = Window("Flight Reservation").Dialog("Flight Reservations").Static("The information has changed. Save changes?").GetROProperty("text")
b = "The information has changed. Save changes?"   
Check_Objects_Text a, b
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("No").Click

Function Check_Objects_Text(realText,strText)
   Dim Mycomp
   strText = "The information has changed. Save changes?"
   Mycomp = StrComp(realText, strText, 1)
   msgbox strText
   msgbox realText
  If Mycomp = 0 Then
        Reporter.ReportEvent micPass,"检查字符串是否一致","界面中包含字符串:"&strText
  else
    Reporter.ReportEvent micFail,"检查字符串是否一致","界面中不包含字符串:"&strText
   End If
End Function
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /2 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-6-19 10:51 , Processed in 0.179543 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表