Reputation: 43
I am doing some integration tests with vaadin version 7.6.4 and Testbench (4.0.3).
I have a view with several comboboxes. One of them has this property comboBox.setTextInputAllowed(false);
For testing purposes, I want to change the default value on the combobox and I need to select a different element then the default one.
To select an element I have tried the following code:
$(ComboBoxElement.class).selectByText("ElementName");
But this only works when comboBox.setTextInputAllowed(true);
I also have tried to use sendkeys()
to change the selected value:
$(ComboBoxElement.class).openPopup();
$(ComboBoxElement.class).sendKeys(keys.ARROW_DOWN);
$(ComboBoxElement.class).endKeys(Keys.ENTER);
This code opens the comboBox popup correctly but doesn't select any item. Neither if I set the focus with setFocus()
;
Could anybody please tell me how can I change the value of a combobox with property setTextInputAllowed(false)
?.
Upvotes: 4
Views: 978
Reputation: 15518
Indeed, your scenario does not seem to work as expected, at least with Vaadin 7.7.3 & TB 4.1.0.alpha1 I had.
Looking at the sources (line 43 atm), in the particular case when a combo is read-only, TestBench will make it writeable, send the specified text, and pick the corresponding item from the popup suggestion list. Nonetheless, during a small debug session, you can easily see that text.equals(popupSuggestions.get(0)
is not equal to Region - 5
as they were hoping.
In conclusion, there's a chance that this is a bug in TB itself. I have a few suppositions but I did not have the time to investigate thoroughly atm how and why.
As a workaround, you can open the popup, use an XPath expression to find the correct item and click it. I have a demo app with a combo containing items named Region - 1
to Region - 10
.
To select Region - 5
I did:
@Test
public void shouldOpenGridColumnVisibilityPopupAndSelectItems() {
getDriver().get("http://localhost:8080/");
ComboBoxElement combo = $(ComboBoxElement.class).first();
combo.openPopup();
findElement(By.xpath("//*[@id='VAADIN_COMBOBOX_OPTIONLIST']//span[text()='Region - 5']")).click();
}
Result:
Upvotes: 1