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