我在對象倉庫里只設置一個按鈕對象AnyButton,label特征屬性值填任意值,然后用下面腳本執行測試
JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "New")
JavaWindow("Test").JavaButton("AnyButton").Click
JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Modify")
JavaWindow("Test").JavaButton("AnyButton").Click
JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Delete")
JavaWindow("Test").JavaButton("AnyButton").Click
JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Check")
JavaWindow("Test").JavaButton("AnyButton").Click
另外,QTP還支持腳本描述的方法來定義和訪問對象,即不需要在倉庫里定義,也能訪問和操作實際對象
如上面兩個任務,可以如下實現
1. 不需要在倉庫里定義Check按鈕對象,直接用下面腳本來實現測試
buttonNum = CInt(JavaWindow("Test").JavaEdit("Record Num").GetROProperty("value"))
For buttonIndex = 0 to buttonNum - 1
JavaWindow("Test").JavaButton("label:=Check", "index:="+CStr(buttonIndex)).Click
Next
2. 不需要在倉庫里定義New、Modify、Delete、Check按鈕對象,直接用下面腳本來實現測試
JavaWindow("Test").JavaButton("label:=New").Click
JavaWindow("Test").JavaButton("label:=Modify").Click
JavaWindow("Test").JavaButton("label:=Delete").Click
JavaWindow("Test").JavaButton("label:=Check").Click
文章來源于領測軟件測試網 http://www.kjueaiud.com/