I'm having a Panel which has some fields. I'm trying to write a test
case to test the Panel. I have a form inside the Panel.
But When I call
formTester.form("submit")
It calls the HomePage.
It doesn't fail but when I try to get the values of the fields I get
null.
What is the difference between using a formtester.submit abd
wicketTester.submitForm.
How to use FormTester with Panels and how to retrieve the values of the
fields defined in the Panel.
wicketTester.startPanel(MyPanel.class);
wicketTester.assertComponent("panel:form:city",
TextField.class);
wicketTester.assertComponent("panel:form", Form.class);
FormTester formTester =
wicketTester.newFormTester("panel:form");
formTester.select("country", 0);
wicketTester.executeAjaxEvent("panel:form:country", "onchange");
wicketTester.assertComponentOnAjaxResponse("panel:form:state");
DropDownChoice stateDropDownChoice = (DropDownChoice)
wicketTester.getComponentFromLastRenderedPage(
"panel:form:state");
Assert.assertEquals(stateDropDownChoice.getChoices().size(), 2);
formTester.select("state", 1);
formTester.setValue("zipCodePanel:zip", "12345");
formTester.setValue("city", "ABC");
System.out.println("zip code *222** " +
formTester.getTextComponentValue("panel:form:city"));
//wicketTester.submitForm("panel:form");
formTester.submit("save");
System.out.println("zip code *111** " +
formTester.getTextComponentValue("city"));
Assert.assertEquals(formTester.getTextComponentValue("panel:form:city"),
"ABC");
System.out.println("zip code *111** " +
formTester.getTextComponentValue("panel:form:city"));
Assert.assertNotNull("country");
Assert.assertNotNull("state");
Assert.assertEquals(formTester.getForm().get("state"), 201L);