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();
}