我使用junit声明检票口组件的存在:

wicketTester.assertComponent("dev1WicketId:dev2WicketId:formWicketId", Form.class);


这适用于某些形式。对于复杂的结构,很难通过搜索所有html文件来查找表单的路径。有什么方法可以轻松找出路径吗?

最佳答案

如果您具有组件,则可以调用#getPageRelativePath()。例如。

// Supposing c is a component that has been added to the page.
// Returns the full path to the component relative to the page, e.g., "path:to:label"
String pathToComponent = c.getPageRelativePath();


您可以使用visitChildren()方法获取标记容器的子代。以下示例显示如何从页面获取所有Form

List<Form> list = new ArrayList<Form<?>>();
Page page = wicketTester.getLastRenderedPage();
for (Form form : page.visitChildren(Form.class)) {
    list.add(form);
}

07-24 09:52
查看更多