使用 RFT 对 Dojo Web 应用进行自动化测试(2)
 
- UID
- 1066743
|

使用 RFT 对 Dojo Web 应用进行自动化测试(2)
案例介绍下面我们以 Dojo 中的 eGrid 控件为例,详细介绍通过 RFT 实现如下自动化测试过程:
图 3.测试流程图 图 4.测试对象- eGrid 界面图 - 通过 RFT 识别 eGrid 上的工具栏以及工具栏上的子对象,获得对象树如下:图 5.工具栏在对象树中的属性
 - 展开 RFT 识别的内层 Grid,对象树如下:图 5: Dojo Grid 在对象树中的属性
 - 设置验证点,验证静态数据对静态的工具栏设置属性验证点,录制脚本中如下:
1
| html_dijit_Toolbar_1().performTest(dijit_Toolbar_1_standardVP());
|
图 6.工具栏的验证点属性编辑器 - 从图 5 中可以看到,该验证点下的所有 content 属性在回放脚本时都会被验证,比如:.class, .id, .text, .title, .style 等属性。
- 对 eGrid 内层的 column name bar 设置 Grid Data 验证点,代码如下:
1
| table_htmlTable_null2().performTest(HtmlTable_null_grid_2VP());
|
图 7.Grid Data 内容验证点属性编辑器 - 实现 eGrid 中筛选功能的脚本录制
- 设计一个测试用例,在 eGrid 中筛选 UPC 为 00263320_0000 记录。功能测试中的过程为:
- 打开 Filter 功能框。 (图 8)
- 在 Rules 的第一个选项卡中选择 UPC,在第二个选项卡中选择 equal, 在第三个文本框中输入筛选值。最后触发 Filter 按钮。(图 9)
图 8.Filter 功能框 图 9.测试对象 - 录制的自动化测试脚本示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| // Test object: Filter button
button_filter().click();
// Test object: the first dropdown box
table_dijit__WidgetsInTemplate().click(atCell(atRow(atIndex(0)),atColumn(atIndex(1));
// the first combobox selection
comboListBox_dijit__WidgetsInT().click(atPoint(76,29));
// Test object: the second dropdown box
table_dijit__WidgetsInTemplate2().click(atCell(atRow(atIndex(0)), atColumn(atIndex(1))));
// the second combobox selection
comboListBox_dijit__WidgetsInT2().click(atPoint(64,12));
// text box input
text__00825().setText("0085");
// Test object: filter button in dialog
button_filter2().click();
|
运行以上自动化测试脚本得到筛选数据,如何验证筛选结果的正确性,需要用一些动态的方法来处理。
- 获取 eGrid 中数据的参数类型RFT 中提供了 ITestData getTestData(StringtestDataType)来获取表格内容,我们用 getTestDataType来获得参数类型:
1
| System.out.println(eGrid().getTestDataTypes());
|
运行结果为:
{text=text} 返回的参数类型为可视文本
- 获取筛选出的 eGrid 中的数据:由于 eGrid 返回数据的特殊性,可以用 ITestData getTestData(String testDataType)方法可视文本的数据代码如下:
1
2
| ITestData eGrid = (ITestData) grid_gridx_Grid_1().getTestData("text");
System.out.println(eGrid);
|
动态验证筛选结果
用 RFT 提供的toString函数将ITestdata类型的 eGrid 数据转化为 String 类型,即可通过 indexOf 来判断字符串 00263320_0000 是否存在于测试对象 eGrid 中,如果没有则返回-1 值,如果有则 count 计数。
代码如下:
1
2
3
4
5
6
7
8
| int startIndex = 0;
int count=-1;
do{
startIndex = eGrid.toString().indexOf("00263320_0000", startIndex);
count++;
}
while(startIndex!=-1);
System.out.println(count);
|
|
|
|
|
|
|