When using Vaadin TestBench to click cells in a TreeGrid, the clickCount reported in ItemClickEvent is always 0.
Clicking manually in the browser produces the correct value of 1.
However, doubleClick() and `click(0,0) are not affected by the issue.
A potential cause could be that click() uses a JavaScript click() call rather than Selenium Actions. Programmatic JavaScript clicks might not populate the clickCount field in browser events, which is why the value arrives as 0.
To reproduce use the following view and test
@Route("")
public class TreeGridIssueView extends HorizontalLayout {
public TreeGridIssueView() {
Div logs = new Div();
logs.setId("logs");
logs.setWidth("50%");
TreeGrid<Item> grid = new TreeGrid<>();
grid.setId("tree-grid");
grid.setHeight("500px");
grid.setWidth("50%");
grid.setWidth("50%");
grid.addHierarchyColumn(Item::name).setHeader("Name").setWidth("300px");
grid.addColumn(Item::size).setHeader("Size");
grid.setTreeData(createTreeDataSample());
grid.addItemClickListener(event -> logs.add(new Div(
createLogMessage(event.getItem().name(), event.getColumn().getHeaderText(), event.getClickCount()))
));
add(grid, logs);
}
record Item(String name, long size, List<Item> children) {
}
static TreeData<Item> createTreeDataSample() {
TreeData<Item> data = new TreeData<>();
Item dirA = new Item("Directory A", 150, List.of(
new Item("File A", 50, List.of()),
new Item("File B", 50, List.of())
));
Item dirB = new Item("Directory B", 400, List.of(
new Item("File D", 250, List.of())
));
data.addItems(List.of(dirA, dirB), Item::children);
return data;
}
static String createLogMessage(String item, String column, int expectedCount) {
return String.format("clicked %s; column: %s; clickCount: %d",
item, column, expectedCount);
}
}
public class TreeGridIssueIT extends BrowserTestBase {
@BeforeEach
public void open() {
getDriver().get("http://localhost:8080/");
}
@BrowserTest
public void testClickTreeGridCell() {
TreeGridElement grid = $(TreeGridElement.class).waitForFirst();
GridColumnElement col1 = grid.getVisibleColumns().get(0);
grid.getRow(0).getCell(col1).click();
assertClickListenerExecuted("Directory A", "Name", 1);
}
@BrowserTest
public void testClickXYTreeGridCell() {
TreeGridElement grid = $(TreeGridElement.class).waitForFirst();
GridColumnElement col1 = grid.getVisibleColumns().get(0);
grid.getRow(0).getCell(col1).click(0,0);
assertClickListenerExecuted("Directory A", "Name", 1);
}
@BrowserTest
public void testDoubleClickTreeGridCell() {
TreeGridElement grid = $(TreeGridElement.class).waitForFirst();
GridColumnElement col1 = grid.getVisibleColumns().get(0);
grid.getRow(0).getCell(col1).doubleClick();
assertClickListenerExecuted("Directory A", "Name", 2);
}
private void assertClickListenerExecuted(String item, String column, int expectedCount) {
var lastMessage = waitUntil(d -> $(DivElement.class).id("logs")
.$(DivElement.class).last()).getText();
Assertions.assertEquals(TreeGridIssueView.createLogMessage(item, column, expectedCount), lastMessage);
}
}
When using Vaadin TestBench to click cells in a
TreeGrid, theclickCountreported inItemClickEventis always 0.Clicking manually in the browser produces the correct value of 1.
However,
doubleClick()and `click(0,0) are not affected by the issue.A potential cause could be that
click()uses a JavaScriptclick()call rather than Selenium Actions. Programmatic JavaScript clicks might not populate theclickCountfield in browser events, which is why the value arrives as 0.To reproduce use the following view and test