在功能的自动化测试中QTP被人们广泛的使用着,关于使用qtp自身的对象仓库的方法来管理测试对象的方式,本人认为存在着很大的局限性,在这里介绍一种通过函数的方式来管理和使用测试对象的方法,该方法的思想是基于利用函数来实现的,把要测试的每一类对象通过一个或几个公用的函数来实现,下面通过具体的code来说明,先建立一个 TestObject.qfl的文件,用来模拟对象仓库的功能。
Function getWindow Set win = description.Create Set getWindow = win End Function Function getWindowByTitle(title) Set win = description.Create Set getWindowByTitle = win End Function Function getDialog Set dia = description.Create Set getDialog = dia End Function Function getDialogByTitle(title) Set dia = description.Create Set getDialogByTitle = dia End Function Function getEdit Set edt = description.Create Set getEdit = edt End Function Function getEditByText(text) Set edt = description.Create Set getEditByText = edt End Function Function getEditByIndex(index) Set edt = description.Create Set getEditByIndex = edt End Function Function getButton Set btn = description.Create Set getButton = btn End Function Function getButtonByText(text) Set btn = description.Create 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的测试对象的进一步改进