51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1456|回复: 3
打印 上一主题 下一主题

[原创] 使用DP,QTP却提示对象在OR中未找到...

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2012-4-3 04:00:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 kar1 于 2012-4-6 02:10 编辑

刚接触QTP,如下想检查某些链接和图片是否在页面中存在,执行后再判断n、p值为true还是false:

Set objPage = Browser("title:=.*").Page("title:=.*")
n = objPage.Image("logo").exist(3)
p = objPage.Link("Profile").exist(3)

debug时看到objPage已经取得,但是QTP总是提示:
"The "logo"  object was not found in the Object Repository.
Check the Object Repository to confirm that the object exists or to find the correct name for the object."

下一行的Link也提示在OR里找不到。难道必须要把需要检查的object全都储存到OR里才可以吗?

我试过把对象加到OR里,的确能用,但格式是类似Browser("title:=home").Page("title:=home").Image("logo").exist,页面title被定死了,有没有办法写一个通用的语句来检查页面元素?请高手们指教!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    开心
    2021-10-13 13:59
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    2#
    发表于 2012-4-6 17:23:49 | 只看该作者
    对于这种采用描述性编程的角本是不需要把检查对像存储在OR里的,只要在实际运行中存在就能被检查出来,,
    你可以采用以下方法来实现:
        dim testobj
        testobj = inputbox("please enter the object text name you wanna tested“)
        webelementCheck(testobj)  
       public function webelementCheck(object)
         dim ob, obj,i
         ob("micclass").value = "xxx"
         ob("html tag").value = "xxx"
         ...
         set obj = Browser("title:=home").Page("title:=home").childobject(ob)
          for i = 0 to obj.count-1 step xx
               if obj(i).GetROProperty("title") = object then
                reporter.ReportEvent micPass, "Pass","step pass"
                ....
               else
               reporter.ReportEvent micfail, "failed","step failed"
             end if
      

      end function
    这样就能满足你的要求了
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
    发表于 2012-4-6 19:56:27 | 只看该作者
    父对象objPage用的是描述性编程,子对象Image和Link也得用描述性编程
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
     楼主| 发表于 2012-4-9 09:01:19 | 只看该作者
    帖子审核了一天多,我都忘了还有这帖子了...

    多谢三楼提醒!我知道错在哪里了

    二楼的注意很不错,我稍微做了一点修改,这下能用了:

    webElementCheck "logo\.jpg", "Image", "file name"

    public function webElementCheck(objText, objType, roProp)
            dim ob, obj,i
            Set ob = Description.Create()
            ob("micclass").value = objType
            'ob("html tag").value = "SPAN"

            set obj = Browser("title:=.*").Page("title:=.*").childobjects(ob)
            For i = 0 to obj.count-1' step xx
                    'msgbox obj(i).GetROProperty("name")
                    if StrComp(obj(i).GetROProperty(roProp), objText, 0) then
                            blnFlag = true
                            Exit for
                    else
                            blnFlag = false
                    end if
            next

            If blnFlag Then
                    reporter.ReportEvent micPass, "Check " + objType + ": " + objText, "assed"
            else
                    reporter.ReportEvent micfail, "Check " + objType + ": " + objText, "Failed"
            End If
    end function

    谢谢两位!
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-9-23 05:21 , Processed in 0.101718 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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