How to check AjaxEventBehavior ("onClick") for Apache Wicket switch?

I use apick wicket and I am having problems testing the AjaxEventBehavior button for a radio. Actually I want to test the onClick event, as in my case, when I select / click the radio button from the RadioGroup that a particular page displays.

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); 
+4
source share
1 answer

Assuming you already done

 WicketTester tester = new WicketTester(); tester.startPage(PageContainingRadioButton.class); 

or a similar startPanel (Wicket 1.4) or startComponent (Wicket 1.5), so your test selects a page containing a button, in a known way, you should be able to get WicketTester to mimic ajax behavior with something like

 tester.executeAjaxEvent("blabla:form:selectPageRadioGroup:radioButton1", "onclick"); 

(Of course, you will need to adjust this path.)

and then make sure he did the right thing with

 tester.assertRenderedPage(MyWebPage.class); 
+8
source

Source: https://habr.com/ru/post/1385104/


All Articles