Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
1.5.4
-
None
Description
When using WicketTester#startComponentInPage with a component class, wicket will instantiate the component and give it an id.
As an example, a starting a panel with a link inside will generate these page relative paths:
testObject
testObject:link
This id is automatically generated by wicket and not known to the developer, wich makes it impossible for the developer to reference components by path, as the first segment of the path is unknown.
To remedy this, wicket appends the id of the component to the path given by the developer in getComponentFromLastRenderedPage().
If the developer calls clickLink("link"), getComponentFromLastRenderedPage will append the generated id and form the path "testObject:link"
This is OK as long as the developer explicitly gives the path, omitting the id of the component.
But, when retrieving the path from the components themselves this creates a problem.
Say a developer is iterating through all links in the page and clicking them:
Link link = getLink();
wicketTester.clickLink(link.getPageRelativePath());
ClickLink is then called with the path "testObject:link", and getComponentFromLastRenderedPage will append the generated id forming the path "testObject:testObject:link" wich clearly fails.
This is illustrated by a simple testcase:
@Test
public void clickShouldWork() {
WicketTester tester = new WicketTester();
tester.startComponentInPage(TestLink.class);
Link link = (Link) tester.getLastRenderedPage().get(0);
String path = link.getPageRelativePath();
wicketTester.clickLink(path);
}
public static class TestLink extends Link {
public TestLink(String id)
public void onClick() {}
}