I'm using apache wicket and I run into trouble regarding testing the AjaxEventBehavior for a Radio button. Actually I want to test the "onClick" event like in my case when I select/click a radio button from a RadioGroup a specif page is rendered.
Code snippet:
RadioGroup<Boolean> selectPageRadioGroup =
new RadioGroup<Boolean>("selectPageRadioGroup", new Model<Boolean>(Boolean.TRUE));
selectPageRadioGroup.setDefaultModel(new Model<Boolean>(Boolean.TRUE));
final Radio<Boolean> radioButton1 =
new Radio<Boolean>("radioButton1", new Model<Boolean>(Boolean.FALSE));
radioButton1.add(new AjaxEventBehavior("onclick") {
@Override
protected void onEvent(AjaxRequestTarget target) {
setResponsePage(MyWebPage.class);
}
});
selectPageRadioGroup.add(radioButton1);
Assuming you have already done
WicketTester tester = new WicketTester();
tester.startPage(PageContainingRadioButton.class);
or a similar startPanel
(Wicket 1.4) or startComponent
(Wicket 1.5), so that your test has rendered a page containing the button at a known path you should be able to make WicketTester simulate the ajax behavior by something like
tester.executeAjaxEvent("blabla:form:selectPageRadioGroup:radioButton1", "onclick");
(You'll need to adjust that path of course.)
and then check that it did the right thing with
tester.assertRenderedPage(MyWebPage.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With