Re: WicketTester trouble resubmitting a form

2008-01-02 Thread Timo Rantalaiho
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 OyURL: http://www.ri.fi/ 

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



WicketTester trouble resubmitting a form

2007-12-18 Thread Dan Kaplan
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=feedbackFeedback/span
form wicket:id=form
table
trtdName:/tdtdinput 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]