依然以登陆页面为例,登陆任务会依次调用 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