依然以登陸頁面為例,登陸任務會依次調用 Common Task 里的文本輸入方法輸入用戶名和密碼,并調用鼠標點擊動作進行表單信息的提交。Common Task 會繼續調用 Test Logger 里的 loggerForTextInput 執行登陸操作,并往日志里插入文本輸入信息輸入的狀態。成功顯示 Pass,如果失敗則顯示失誤相關的信息,幫助監控所有操作執行的情況和準確定位失誤的位置。
清單 3.界面操作識別定位
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
//登陸 Task public class LoginOps extends LoginOpsHelper { BrowserOps browserOps = new BrowserOps(); CommonOps commonOps = new CommonOps(); ObjRepository objRepo = new ObjRepository(); public void login(String uname, String psd) { commonOps.setText(objRepo.unameText, uname); commonOps.setText(objRepo.userPsdText, psd); commonOps.clickButton(objRepo.loginBtn); } } //Common Task public class CommonOps extends CommonOpsHelper { ObjFinder objectFinder = new ObjFinder(); //文本輸入 public void setText(String properties, String text) { WTextField wText = new WTextField( objectFinder.findTextField(properties)); TestLogger.loggerForTextInput(wText, properties, text); } //鼠標點擊 public void clickButton(String properties) { WButton button = new WButton(objectFinder.findTextField(properties)); TestLogger.loggerForClickButton(button, properties); } //其他基本操作 } //TestLogger public class TestLogger extends TestLoggerHelper { public void loggerForTextInput(WTextField t, String property, String sInputText) { try { t.setText(sInputText); TestLogger.logScriptInfo("Pass - Input Text: " + sInputText + " into Text Widget (" + property + " )"); } catch (Exception e) { TestLogger.errorHandler("Fail - Input Text: " + sInputText + " into Text Widget (" + property + " )", e); } } |
原文轉自:http://www.ibm.com/developerworks/cn/rational/1611_xux_rft/index.html