javawicket-tester

How can I test AutoComplete component with WicketTester


I'm wondering if anyone of you could know how to test auto-complete textfield using wickettester, I have tried

formTester.setValue("path","");
wicketTester.executeAjaxEvent("path","onchange");

I've tried also:

Component component = wicketTester.getComponentFromLastRenderedPage("path");
component.setDefaultModelObject(ObjectNeeded);

But none of these methods worked for me... Any Help will appreciated! Thanks


Solution

  • I have not tried this with real code, but something resembling this might work:

    formTester.setValue("path","");
    
    AbstractAutoCompleteBehavior behavior = (AbstractAutoCompleteBehavior)
    WicketTesterHelper.findBehavior(wicketTester.getComponentFromLastRenderedPage("path"),
    AbstractAutoCompleteBehavior.class);
    wicketTester.executeBehavior(behavior);
    

    The findBehavior call actually likely needs to be a longer path, as it's not done by formTester.