javawicket-tester

Wickettester on two submits of same form


I'm having trouble sending a wickettester form twice and validating that the error message given the first time is removed in the second submit.

In the code given below I first submit an empty form which is giving an error message. Then I want to submit the same form but with valid input and assert that the error message from the first go is now removed.

The test seems to be running correctly BUT when I change the java code under test so that it does not remove the error message when the search is submitted, correctly, the second time the test is still asserting that there are no error messages... the second submit in the test seems to be starting from the same place as the first submit and hence the first submit is not taking part of my test.

@Test
public void assertThatErrorMessagesAreRemoved() {
    PageParameters pp = new PageParameters();
    // given
    WicetTester tester = new WicketTester(new MyApplication());
    tester.startComponentInPage(new MyPanel("myPanel", pp));

    //when
    FormTester form = tester.newFormTester("panel:formcontainer:form");
    form.submit();

    // then
    tester.assertErrorMessages("searchTerm.Required_value");

    //and given
    form = tester.newFormTester("panel:formcontainer:form");
    form.setValue("searchTerm", "a");

    //when
    form.submit();

    // then
    tester.assertNoErrorMessage();
}

Solution

  • As commented above:

    I found the solution to my question by my self. The issue was that I did not add the FeedbackPanel on the ajax return target, target.add(feedbackpanel);. The error I was seeing after the second submit was not sent on the response and WicketTester did not find it. But since I did not add the FeedbackPanel on target for the Ajax call the html did get re-rendered and the error was still visible.