我使用junit断言wicket组件的存在:
wicketTester.assertComponent("dev1WicketId:dev2WicketId:formWicketId", Form.class);
Run Code Online (Sandbox Code Playgroud)
这适用于某些形式.对于复杂的结构,通过搜索所有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();
Run Code Online (Sandbox Code Playgroud)
您可以使用该visitChildren()方法获取标记容器的子级.以下示例显示如何Form从页面获取所有s.
List<Form> list = new ArrayList<Form<?>>();
Page page = wicketTester.getLastRenderedPage();
for (Form form : page.visitChildren(Form.class)) {
list.add(form);
}
Run Code Online (Sandbox Code Playgroud)
获取这些内容的简单方法是getDebugSettings().setOutputComponentPath(true);在初始化应用程序时调用.这将使Wicket将这些路径作为每个组件绑定标记的属性输出到生成的HTML.
建议仅在调试模式下启用此功能,但:
public class WicketApplication extends WebApplication {
@Override
public void init() {
super.init();
if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT) {
getDebugSettings().setOutputComponentPath(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6833 次 |
| 最近记录: |