You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dan Kaplan <dk...@citizenhawk.com> on 2007/12/19 08:27:52 UTC
WicketTester trouble resubmitting a form
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WicketTester trouble resubmitting a form
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 18 Dec 2007, Dan Kaplan wrote:
> IModel model = new Model() {
> public void setObject(Object obj) {
> name = obj.toString();
> }
> };
This is suspicious, I think that you should also override
getObject() to return name. Otherwise the model works a bit
strangely (always returns null).
> 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);
> }
Could it be that WicketTester does not clear the error
message at any point? You could try clearing it explicitly
in between the submits and / or find out if it is a
WicketTester bug.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org