Hi,
I'm having asserts fail when I resubmit a form with WicketTester.  Here's
the scenario:  I go to a page with a form that has a requiredtextfield.
First, I set the field to "" and submit it.  It fails like it should.  Then,
in the same test, I set it to a value like "blah" and submit it.  It fails
with the same error: "The field is required".  It should not be complaining
about this since I did set it to a value.  I've found the workaround to this
is to submit the form only once.  I have written up a testcase for this:

//the html
<html>
<body>
<span wicket:id="feedback">Feedback</span>
<form wicket:id="form">
    <table>
        <tr><td>Name:</td><td><input type="text"
wicket:id="name"/></td></tr>        
    </table>
    <input type="submit" value="Submit Test"/>
</form>
</body>
</html>

//the webpage
public class Test extends WebPage {

    private String name;

    public Test() {
        IModel model = new Model() {
            public void setObject(Object obj) {
                name = obj.toString();
            }
        };
        Form form = new Form("form") {
            @Override
            public void onSubmit() {
                info("submitted " + name);
            }
        };
        form.add(new RequiredTextField("name", model));
        add(form);
        add(new FeedbackPanel("feedback"));
    }
}

//the test
public class MyTest extends BaseWebTest {

    public void testResubmit() {
        //note: tester initialized in parent
        tester.startPage(new Test());
        FormTester ft1 = tester.newFormTester("form");
        ft1.setValue("name", "");
        ft1.submit();
        tester.assertRenderedPage(Test.class);

        FormTester ft2 = tester.newFormTester("form");
        ft2.setValue("name", "testcity");
        ft2.submit();
        tester.assertNoErrorMessage();  //it fails here
        tester.assertRenderedPage(Test.class);
    }
}

//the exception
junit.framework.AssertionFailedError: expect no error message, but contains
   Field 'name' is required.
        at
org.apache.wicket.util.tester.WicketTester.assertNoErrorMessage(WicketTester
.java:476)
        at com.haverlocke.web.page.pub.MyTest.testResubmit(MyTest.java:25)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

//the BaseWebTest  (I really hope this doesn't matter)
protected WicketTester tester;

    public void setUp() throws Exception {
        super.setUp();

        MyApplication ha = new MyApplication() {
            public void init() {                
                addComponentInstantiationListener(new
SpringComponentInjector(this, applicationContext));
            }
        };
        tester = new WicketTester(ha);
    }

Can anyone explain this?

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to