Hi,

try with an additional formTester:

    tester.startPage(HomePage.class);
    FormTester firstRequest = tester.newFormTester("form");
    firstRequest.select("sites", 1);
    
tester.executeBehavior((AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage("form:sites").getBehaviors().get(0));
    tester.assertLabel("form:chosen","Bing");

    FormTester secondRequest = tester.newFormTester("form");
    secondRequest.submit("detailButton");
    tester.assertInfoMessages("feedback","Bing");

Note that *when FormTester is created*, it pushes all values of a form into the current request.

With your setup the value of the choice is missing in the second request.

Have fun
Sven



On 14.03.2017 10:16, Hans-Heinrich Braun wrote:
In my Application i have a DropDownSelect which changes a Label onUpdate


  by  AjaxFormComponentUpdatingBehaviorThen there is a Button which tries
access at the selected item. In the real Webapp it works fine but when i
  test itwhen i click the Button the selected Item is null.What I am doing
  wrong.
----------------------------------Here the HomePage:

public class HomePage extends WebPage {
private static final longserialVersionUID = 1L;
private static final List<String> SEARCH_ENGINES = Arrays.asList(new String[] { "Google", 
"Bing", "Baidu" }); //
private String selected = "Google";
Model<String> model = new Model<String>() {                    public String 
getObject() {              return getSelected();          }      };

private Label chosen=new Label("chosen", model);
  public HomePage(final PageParameters parameters) { super(parameters);

FeedbackPanel feedback=new FeedbackPanel("feedback"); add(feedback);

feedback.setVisible(true); // other pages will set this to visible
feedback.setEscapeModelStrings(false); add(new
Label("version",getApplication().getFrameworkSettings().getVersion()));

DropDownChoice<String> listSites = new DropDownChoice<String>( "sites", new

PropertyModel<String>(this, "selected"), SEARCH_ENGINES);

Form<?> form = new Form<Void>("form");
final  Button detailButton=new Button("detailButton") {
@Override public void onSubmit(){info(getSelected()); } };
detailButton.setOutputMarkupId(true);

chosen.setOutputMarkupId(true);  listSites.add(new  
AjaxFormComponentUpdatingBehavior("onchange")        {
@Override            protected void onUpdate(AjaxRequestTarget target)
        {                              target.add(chosen);
  target.add(detailButton);                      }        });

form.add(chosen);  add(form); form.add(listSites); form.add(detailButton);
    }

   public String getSelected() { return selected; }
public void setSelected(String selected) { this.selected = selected; }}

----------------------------------------and here the Test :

public class TestHomePage{ private WicketTester tester;

@Before public void setUp() {
tester = new WicketTester(new WicketApplication()); }

@Test public void homepageRendersSuccessfully() {
tester.startPage(HomePage.class);
  FormTester  formTester = tester.newFormTester("form");
  formTester.select("sites", 1);  tester.executeBehavior((
AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage("form:sites").getBehaviors().get(0));
tester.assertLabel("form:chosen","Bing");
  formTester.submit("detailButton");
tester.assertInfoMessages("feedback","Bing");
}}
  I am using wicket 6.26.0




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to