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 |
通過這種方式實現了測試對象的過度復用,更符合自動化測試的思想,在項目的測試過程中,我們只要不斷的加入新類型的測試對象即可,關鍵是這些測試對象基本不需要怎么維護,便可以很好的進行復用,這些對象不僅僅在一個項目中可以使用,只要是同一類型的項目,我們都可以來使用這些對象,而不需要隨著不同的項目我們還要去重復的去維護一個個的對象倉庫了。這樣大大的提高了我們的測試效率,也便于多人集體合作。
文章來源于領測軟件測試網 http://www.kjueaiud.com/