简体   繁体   中英

Fire event in gwt java testing not changing the value of checkbox

I added three radio buttons in a group and it works fine when I load page from browser.

Java code:

@UiHandler({
"RadioButton1",
"RadioButton2",
"RadioButton3"
})  
void radioButtonClickHandler(ClickEvent event){
  if(RadioButton1.getValue()){
    // do something
  } else if(RadioButton2.getValue()) {
    // do something
  } else if (RadioButton3.getValue()){
    // do something
  }
}

I am trying to write test cases for this function.

public void TestRadio1ClickEvent(){
    // all values set 
    // Value of Radiobutton2 set to true
    view.RadioButton1.fireEvent(new ClickEvent() {});

    assertTrue(view.RadioButton1.getValue());
    assertFalse(view.RadioButton2.getValue());
    assertFalse(view.RadioButton3.getValue());
}

The values of radio buttons are not changing when I fire click event. Value of RadioButton1 remains false and RadioButton2 remains true.

I can set values manually in click handler but I don't want to do that. How is clicking of button different from firing event? Does click change radio button value and then call click handler?

Try using the following method on the radio button. setValue(java.lang.Boolean value, boolean fireEvents)

    radioButton.setValue(true,true) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM