0

我想label1在某些应用程序中声明一些标签。我编写了以下junit测试用例:

wicketTester.assertLabel("label1", "Hello!");

添加标签的页面如下所示:

FooPage.java

public class FooPage extends WebPage {

    public FooPage() {
        add(new Label("label1", "Hello!"));
    }
}

对应的html页面如下所示:FooPage.html

<body>
..
...

<div wicket:id="label1"></div>
..
<body>

label1当有人点击链接时,我想断言的标签会显示

<a wicket:id="fooId" href="FooPage">Foo</a>

在以下页面中:

<html xmlns:wicket="http://wicket.apache.org/">
<body>
    <wicket:panel>

            <div class="xxx">
                <a wicket:id="fooId"
                    href="FooPage">Foo</a>
            </div>
    </wicket:panel>
</body>
</html>

当我运行 junit 测试时,我收到以下错误:

path: 'label1' does not exist for page: BarPage

我的问题是:如何为标签找到正确的路径label1

4

2 回答 2

1

您是否在测试中单击了链接“fooId”(使用 wicketTester.clickLink)?

于 2012-11-22T09:26:05.267 回答
0

你可以像这样找到你的组件路径

修改WicketApplication

在检票口 7

getDebugSettings().setComponentPathAttributeName("component_path");  

在 Wicket 6 或以上

getDebugSettings().setOutputComponentPath(true);

使用示例:

@Override
public RuntimeConfigurationType getConfigurationType() {
    if (Boolean.valueOf(getProperty("development.mode"))) {
        //show component path in html tag
        getDebugSettings().setComponentPathAttributeName("component_path");
        return RuntimeConfigurationType.DEVELOPMENT;
    }       
    return RuntimeConfigurationType.DEPLOYMENT;
}

如果您在 Web 浏览器中检查您的组件,您会发现类似以下内容:

<input type="text" value="" component_path="pageContent_form_username" name="username" id="username3" >

请不要忘记用 (:) 冒号更改所有下划线,如下所示:

pageContent_form_username -> pageContent:form:username

于 2014-09-03T12:50:47.587 回答