浅谈QTP中的测试对象

发表于:2009-4-21 14:10

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

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

  在功能的自动化测试QTP被人们广泛的使用着,关于使用qtp自身的对象仓库的方法来管理测试对象的方式,本人认为存在着很大的局限性,在这里介绍一种通过函数的方式来管理和使用测试对象的方法,该方法的思想是基于利用函数来实现的,把要测试的每一类对象通过一个或几个公用的函数来实现,下面通过具体的code来说明,先建立一个 TestObject.qfl的文件,用来模拟对象仓库的功能。

Function getWindow

    Set win = description.Create
    win("class description").value = "window"

    Set getWindow = win

End Function

Function getWindowByTitle(title)

    Set win = description.Create
    win("class description").value = "window"
    win("title").value = title

    Set getWindowByTitle = win

End Function

Function getDialog

    Set dia = description.Create
    dia("class description").value = "window"

    Set getDialog = dia

End Function

Function getDialogByTitle(title)

    Set dia = description.Create
    dia("class description").value = "window"
    dia("title").value = title

    Set getDialogByTitle = dia

End Function

Function getEdit

    Set edt = description.Create
    edt("class description").value = "edit"

    Set getEdit = edt

End Function

Function getEditByText(text)

    Set edt = description.Create
    edt("class description").value = "edit"
    edt("attached text").value = text

    Set getEditByText = edt

End Function

Function getEditByIndex(index)

    Set edt = description.Create
    edt("class description").value = "edit"
    edt("index").value = index

    Set getEditByIndex = edt

End Function

Function getButton

    Set btn = description.Create
    btn("class description").value = "push_button"

    Set getButton = btn

End Function

Function getButtonByText(text)

    Set btn = description.Create
    btn("class description").value = "push_button"
    btn("attached text").value = text

    Set getButtonByText = btn

End Function

  我们通过以上这种方式,可以把我们测试项目中用到的所有的测试对象加入到这个“对象仓库”中来,在使用的时候,只需要调用相应的函数即可实现,如下面的coad所示。

SystemUtil.Run "fileName","","filePath"

If JavaWindow(getWindow).JavaDialog(getDialog).Exist(30) Then

    With JavaWindow(getWindow).JavaDialog(getDialog)

        .JavaEdit(getEditByText("User Name")).Set "userName"
        .JavaEdit(getEditByText("Password")).Set "userPwd"
        .JavaButton(getButtonByText("Ok")).Click
    End with
Else
    Reporter.ReportEvent micFail,"lauch error","launch error, please check the application!"
    ExitTest
End If

  通过这种方式实现了测试对象的过度复用,更符合自动化测试的思想,在项目的测试过程中,我们只要不断的加入新类型的测试对象即可,关键是这些测试对象基本不需要怎么维护,便可以很好的进行复用,这些对象不仅仅在一个项目中可以使用,只要是同一类型的项目,我们都可以来使用这些对象,而不需要随着不同的项目我们还要去重复的去维护一个个的对象仓库了。这样大大的提高了我们的测试效率,也便于多人集体合作。

版权声明:原创作品,转载时请务必以超链接形式标明文章原始出处作者信息本声明,否则将追究法律责任。本文出自yangzhengjiang的51Testing软件测试博客:http://www.51testing.com/?174344

相关阅读:

关于QTP的测试对象的进一步改进
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号