Hi,

On Wed, Jan 16, 2013 at 10:02 AM, RalfButler <ralf.but...@web.de> wrote:

> Hi there,
>
> I'm using Wicket 6.4 and try to test a super simple form:
>
> public final class MyForm extends WebPage {
>
>     public MyForm() {
>         super();
>
>         Form form = new Form("form");
>
>         TextField textField = new TextField("textfield");
>         textField.setRequired(true);
>         form.add(textField);
>
>         DropDownChoice dropDownChoice = new DropDownChoice("dropdown", new
> Model(), new ArrayList(Arrays.asList("a", "b", "c"))){
>             @Override
>             protected boolean wantOnSelectionChangedNotifications() {
>                 return true;
>

This uses 'onchange' inline attribute but it is *not* Ajax submit.
This onchange just does this.form.submit();


>             }
>
>             @Override
>             protected void onSelectionChanged(Object newSelection) {
>                 System.out.println("change");
>             }
>         };
>         dropDownChoice.setRequired(true);
>         form.add(dropDownChoice);
>
>         form.add(new SubmitLink("submitLink") {
>             @Override
>             public void onSubmit() {
>                 // return back to the home page
>                 setResponsePage(HomePage.class);
>             }
>         });
>
>         add(form);
>     }
> }
>
> My test looks like this:
> public class TestMyForm {
>
>     private WicketTester tester;
>
>     @Before
>     public void setUp() {
>         tester = new WicketTester(new WicketApplication());
>     }
>
>     @Test
>     public void homepageRendersSuccessfully() {
>         //start and render the test page
>         tester.startPage(MyForm.class);
>
>         //assert rendered page class
>         tester.assertRenderedPage(MyForm.class);
>     }
>
>     @Test
>     public void enterData(){
>
>         tester.startPage(MyForm.class);
>         FormTester formTester = tester.newFormTester("form");
>         formTester.setValue("textfield", "Hello World");
>         formTester.select("dropdown", 1);
>         tester.executeAjaxEvent("form:dropdown", "onchange");
>

There is no Ajax behavior so the above wont work.
You need either to do: formTester.submit() or add
AjaxFormSubmitBehavior("change") to the drop down.


>
>         formTester.submit();
>
>         tester.assertNoErrorMessage();
>
>         tester.assertRenderedPage(HomePage.class);
>     }
>
> }
>
> The result is:
> Testcase: enterData(eu.sudus.TestMyForm):       FAILED
> expect no error message, but contains
>    'textfield' is required.
>    'dropdown' is required.
>
> I understand the textfield is less the problem, but the submitting the
> dropdownchoice value.
>
> Can someone help me out?
>
> Thanks,
> Ralf
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Reply via email to