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

Reply via email to