2012-11-22 24 views
0

我想在某些應用程序中聲明某個標籤label1。我寫了下面的JUnit測試用例:Wicket錯誤路徑:'label1'不存在頁面:BarPage

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

的頁面,在標籤中添加如下所示:

FooPage.java

public class FooPage extends WebPage { 

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

和corresponed html頁面看起來是這樣的: FooPage.html

<body> 
.. 
... 

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

標籤label1 - 我想assert-顯示,當有人在以下頁面點擊鏈接

<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的正確路徑?

+0

而wicketTester加載哪一頁?我想你是在BarPage上,而標籤在FooPage上。因此錯誤。 – bert

+0

WicketTester加載BarPage和Label在FooPar –

回答

1

您是否在測試中點擊過鏈接'fooId'(使用wicketTester.clickLink)?

+0

hmm no。它有什麼影響? –

+0

你說過,標籤只有在用戶點擊鏈接'fooId'時才顯示?我不知道你的代碼的數據,但我想你應該點擊鏈接來呈現標籤。 –

+0

現在我明白了。你的答案是有用的非常感謝 –

0

你可以找出這樣

修改WicketApplication您的組件路徑

在Wicket 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:形式:用戶名