我有几个针对可排序数据表的检票口测试,特别是 ajax 单击可排序的列标题并断言呈现的正文行的内容。现在表格组件后代的组件层次结构由 wicket 框架自动生成,并导致排序链接 (ajax) 的路径类似于:
table:topToolbars:toolbars:0:headers:1:header:orderByLink
但是,当跨测试重新渲染 DataTable 时,工具栏组件的索引每次都会增加,即类似于:
table:topToolbars:toolbars:1:headers:1:header:orderByLink
然后会破坏后续测试的硬编码路径,因为它们将不再匹配。
数据表构建的代码片段如下:
final PayeesProvider dataProvider = new PayeesProvider();
table = new DataTable<ResponsePayeeDetails>("payees", columns, dataProvider, rowsPerPage);
table.setOutputMarkupId(true);
table.addTopToolbar(new AjaxFallbackHeadersToolbar(table, dataProvider) {
private static final long serialVersionUID = -3509487788284410429L;
@Override
protected WebMarkupContainer newSortableHeader(final String borderId, final String property, final ISortStateLocator locator) {
return new AjaxFallbackOrderByBorder(borderId, property, locator, getAjaxCallDecorator()) {
@Override
protected void onRender() {
System.out.printf("Path: %s\n", this.getPageRelativePath());
super.onRender();
}
private static final long serialVersionUID = -6399737639959498915L;
@Override
protected void onAjaxClick(final AjaxRequestTarget target) {
target.add(getTable(), navigator, navigatorInfoContainer);
}
@Override
protected void onSortChanged() {
super.onSortChanged();
getTable().setCurrentPage(0);
}
};
}
});
table.addBottomToolbar(new NoRecordsToolbar(table));
add(table);
准确地说,当我运行测试时,上面的 System.out.printf 语句会打印:
(第一次测试)
Path: payees:topToolbars:toolbars:0:headers:1:header
Path: payees:topToolbars:toolbars:0:headers:2:header
(第二次测试)
Path: payees:topToolbars:toolbars:2:headers:1:header
Path: payees:topToolbars:toolbars:2:headers:2:header
(第三次测试)
Path: payees:topToolbars:toolbars:4:headers:1:header
Path: payees:topToolbars:toolbars:4:headers:2:header
(第四次测试)
Path: payees:topToolbars:toolbars:6:headers:1:header
Path: payees:topToolbars:toolbars:6:headers:2:header
Path: payees:topToolbars:toolbars:6:headers:1:header
Path: payees:topToolbars:toolbars:6:headers:2:header
Path: payees:topToolbars:toolbars:6:headers:1:header
Path: payees:topToolbars:toolbars:6:headers:2:header
(第五次测试)
Path: payees:topToolbars:toolbars:8:headers:1:header
Path: payees:topToolbars:toolbars:8:headers:2:header
有谁知道我如何强制索引生成更具确定性/可重复性。或者,是否有一种通配符或以其他方式概括路径的方法,以使它们不受这些增量的影响?
任何帮助将不胜感激!