The First Three Secrets About Wicket (Translation)

Here you can find the translation of three "secrets" about Wicket posted on Tommaso Torti's Blog, that will help you to test a Wicket application.

The First Secret

Start the wicket tester

tester.startPage(YourPage.class);

Then, start descending in the component tree hierarchy until you reach the component you want to test.
Keep working on every assertion until you see the green bar!

tester.assertComponent("form", Form.class);
tester.assertComponent("form:table", ...);
tester.assertComponent("form:table:rows", ...)
...
tester.assertComponent("form:table:rows:1:cells:2:cell:select", DropDownChoice.class);

The Second Secret

After you complete the steps explained in the first secret, you'll be able to work on the component.

DropDownChoice yourDropDown = (DropDownChoice) tester.getComponentFromLastRenderedPage(wicketPath);
assertEquals(expected, yourDropDown.getModelObject());

The Third Sercret

If you get stuck in finding the correct path of a component, you have a last chance

System.out.println(tester.getServletResponse().getDocument());
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License