Im not sure, but i've been looking into the testing part of wicket
lately. I think its something about flows. If you start a formtester
youre in a flow, and by calling executeAjaxEvent in the middle you break
it somehow. As been discussed testing part of wicket should have a
overhaul. I guess having a formtester which could detect ajax behaviors
and fire them appropriately would be a great improvement..
regards Nino
Luke Ma wrote:
Nino,
Thanks! That did the trick.
Do you know why formTester and executeAjaxEvent can't be used simultaneously
right now? Unless I missed it, I don't think I saw anything in the docs
that said that behavior shouldn't work. I did notice that while setValue +
executeAjaxEvent would work in terms of firing off the form, form.submit and
tester.submitForm had different results: if I did setValue on my formTester
and then did tester.submitForm, none of the values got set. It seems to me
that formtester should work with executeAjaxEvent, or that it should be
documented otherwise?
Luke
Nino.Martinez wrote:
Like this:
Public class MyTestCase extends TestCase {
final MyWicketTester tester = new MyWicketTester(application);
...
...
...
public void testHomePage() {
tester.startPage(HomePage.class);
TextField tf=getComponentFromLastRenderedPage("inputForm:text1");
tf.getModel().setObject("Testing text");
tester.executeAjaxEvent("inputForm:text1", "onchange");
tester.Submitform("inputForm");
Not completely sure if this works, but should be something like it.
Nino Saturnino Martinez Vazquez Wael wrote:
Hi Luke
This is not the way it works. Currently cant do that combination.. You
have to run with form tester only or executeAjaxEvent only..
What you might want todo are set the models instead and fire the
ajaxevent then..
regards Nino
Luke Ma wrote:
There might be a bug with executeAjaxEvent in WicketTester: everytime
I use
it to fire off an ajax event in a form, page redirection goes nuts. For
example, the following test code:
Public class MyTestCase extends TestCase {
final MyWicketTester tester = new MyWicketTester(application);
...
...
...
public void testHomePage() {
tester.startPage(HomePage.class);
FormTester form = tester.newFormTester("inputForm");
form.setValue("text1", "Testing text");
tester.executeAjaxEvent("inputForm:text1", "onchange");
form.submit();
[0] tester.assertRenderedPage(OtherPage.class);
}
will fail at [0] with "expected OtherPage.class but got
HomePage.class". If, on the other hand, I remove the executeAjaxEvent
call, everything works
fine. The page code looks like this:
private class HomePage extends WebPage
public HomePage() {
add(new InputForm("inputForm"));
}
... ...
...
private class InputForm extends Form {
...
...
...
text1 = new TextField("text1", new PropertyModel(this, string1));
text1.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(final AjaxRequestTarget target) {
System.out.println("Text1 onChangeAjaxBehavior fired");
string2 = string1;
target.addComponent(text2);
}
});
add(text1);
text2 = new TextField("text2", new PropertyModel(this, string2));
text2.setOutputMarkupId(true);
add(text2);
...
...
...
public final void onSubmit()
{
setResponsePage(OtherPage.class);
}
...
...
...
I've checked for validation errors, errors in my code, tried using
behaviors
instead, tried firing the ajax event off multiple times, all to no
avail. Is executeAjaxEvent broken?
Luke
--
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
--
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684