Generate Playwright integration tests for Vaadin 25 views using the DramaFinder library. Use when the user wants to write IT tests for a Vaadin view, mentions DramaFinder, or asks about Playwright testing in a Vaadin project.
73
92%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
For the authoritative method list and signatures, see the auto-generated api-reference.md. This file focuses on behaviour and usage that signatures alone don't convey.
TreeGridElement is a Playwright element wrapper for <vaadin-grid> backed by a Vaadin TreeGrid. It extends GridElement with tree-specific APIs for querying hierarchy levels, checking expanded/collapsed/leaf state, and performing single-row or level-based bulk expand and collapse operations.
Note: Vaadin's
TreeGridrenders using the same<vaadin-grid>web component as the plainGrid. The hierarchy is expressed through<vaadin-grid-tree-toggle>elements that Vaadin renders inside each row's hierarchy column cell content.TreeGridElementtherefore shares the same tag name constant asGridElementand inherits all of its row, cell, header, selection, and sorting APIs.
All row and cell access methods auto-scroll the grid as needed to bring virtualized rows into view.
vaadin-gridVaadinElement
└── GridElement
└── TreeGridElementInherited from GridElement:
| Interface | Description |
|---|---|
FocusableElement | Focus operations |
HasStyleElement | CSS class support |
HasThemeElement | Theme attribute support |
HasEnabledElement | Enabled/disabled state |
| Constant | Value | Description |
|---|---|---|
FIELD_TAG_NAME | "vaadin-grid" | Same tag as GridElement |
TreeGridElement(Locator locator)Creates a new TreeGridElement from a Playwright locator pointing to the <vaadin-grid> element backed by a TreeGrid.
Get the first TreeGridElement on the page.
TreeGridElement grid = TreeGridElement.get(page);Get the first TreeGridElement within a parent locator.
TreeGridElement grid = TreeGridElement.get(page.locator("#container"));Get a TreeGridElement by its id attribute.
TreeGridElement grid = TreeGridElement.getById(page, "my-tree-grid");| Method | Return Type | Description |
|---|---|---|
findTreeRow(int rowIndex) | Optional<TreeRowElement> | Like findRow but returns a TreeRowElement with tree-specific APIs; auto-scrolls if needed |
isRowExpanded(int rowIndex) | boolean | true if the row's tree toggle has expanded = true |
isRowCollapsed(int rowIndex) | boolean | true if the row has children but is not expanded |
isRowLeaf(int rowIndex) | boolean | true if the row has no children (leaf = true on the toggle) |
getRowLevel(int rowIndex) | int | 0-based hierarchy depth of the row (root items = 0) |
getExpandedRowCount() | int | Number of currently visible expanded rows |
| Method | Description |
|---|---|
expandRow(int rowIndex) | Expand the row. No-op if already expanded or a leaf node |
collapseRow(int rowIndex) | Collapse the row. No-op if already collapsed or a leaf node |
toggleRow(int rowIndex) | Toggle expanded/collapsed state. No-op if the row is a leaf |
All GridElement methods are inherited unchanged, including:
getTotalRowCount(), getRenderedRowCount(), getColumnCount()findRow(int rowIndex), findCell(int row, int col), findCell(int row, String header)findHeaderCell(...), getHeaderCellContents()select(int), deselect(int), getSelectedItemCount()checkSelectAll(), uncheckSelectAll(), isSelectAllChecked(), isSelectAllIndeterminate(), isSelectAllUnchecked()waitForGridToStopLoading(), scrollToRow(int), scrollToStart(), scrollToEnd()Represents a row in a TreeGrid, extending RowElement with tree-specific state queries and expand/collapse actions. Use findTreeRow(int) to obtain one, or construct from an existing RowElement.
// Obtain directly (preferred — use findTreeRow on the grid)
TreeRowElement row = grid.findTreeRow(0).get();
// Upgrade an existing RowElement
TreeRowElement row = new TreeRowElement(grid.findRow(0).get());| Method | Return Type | Description |
|---|---|---|
getTreeToggleLocator() | Locator | Locator for the <vaadin-grid-tree-toggle> in this row's hierarchy cell |
isExpanded() | boolean | true if this row is expanded |
isCollapsed() | boolean | true if this row has children but is not expanded |
isLeaf() | boolean | true if this row has no children |
getLevel() | int | 0-based hierarchy depth of this row |
expand() | void | Expand this row. No-op if already expanded or a leaf |
collapse() | void | Collapse this row. No-op if already collapsed or a leaf |
toggle() | void | Toggle expanded/collapsed state. No-op if a leaf |
All RowElement methods are available: getRowLocator(), getRowIndex(), getCell(int), getCell(String), isSelected(), select(), deselect(), openDetails(), closeDetails(), isDetailsOpen().
<vaadin-grid-tree-toggle> exposes three key values, but they are surfaced differently:
| Value | Reflected as HTML attribute? | How it is read |
|---|---|---|
expanded | Yes | toggle.getAttribute("expanded") != null |
leaf | Yes | toggle.getAttribute("leaf") != null |
level | No (DOM property only) | toggle.evaluate("el => el.level") |
Because expanded and leaf are reflected boolean attributes, their presence in the DOM means true and their absence means false. This also means CSS attribute selectors work for them:
// Count all visible expanded toggles using a CSS selector — no JS needed
locator.locator("vaadin-grid-tree-toggle[expanded]").count();level is not reflected, so it must be read via JavaScript:
toggle.evaluate("el => el.level") // returns a NumberTreeGridElement searches all cells in the row for the one whose cell content contains a <vaadin-grid-tree-toggle>, rather than assuming the toggle is always in cell 0. This correctly handles:
<vaadin-grid-cell-content> intercepts pointer events, which causes Playwright's coordinate-based .click() to never reach the <vaadin-grid-tree-toggle> inside it. Toggle clicks are therefore performed via:
toggle.evaluate("el => el.click()")This matches how Vaadin's own TestBench performs the same operation via Selenium's WebElement.click().
TreeGridElement grid = TreeGridElement.getById(page, "my-tree-grid");
// Row counts
int total = grid.getTotalRowCount(); // visible rows (collapsed children not counted)
int expanded = grid.getExpandedRowCount(); // number of currently expanded rows
// Hierarchy state of row at index 0
boolean isLeaf = grid.isRowLeaf(0);
boolean isExpanded = grid.isRowExpanded(0);
boolean isCollapsed = grid.isRowCollapsed(0);
int level = grid.getRowLevel(0); // 0 = rootTreeGridElement grid = TreeGridElement.getById(page, "my-tree-grid");
// Expand root row 0 (no-op if already expanded or a leaf)
grid.expandRow(0);
assertTrue(grid.isRowExpanded(0));
// Access a child row that is now visible at flat index 1
var child = grid.findCell(1, "Name");
assertEquals("Child 0-0", child.get().getCellContentLocator().innerText());
// Collapse it again
grid.collapseRow(0);
assertEquals(3, grid.getTotalRowCount());TreeGridElement grid = TreeGridElement.getById(page, "my-tree-grid");
// Obtain a tree-aware row object
TreeGridElement.TreeRowElement row = grid.findTreeRow(0).get();
System.out.println(row.getLevel()); // 0
System.out.println(row.isLeaf()); // false
System.out.println(row.isExpanded()); // false
row.expand();
assertTrue(row.isExpanded());
row.collapse();
assertFalse(row.isExpanded());// If you already have a RowElement from a generic helper, wrap it:
GridElement.RowElement plainRow = grid.findRow(0).get();
TreeGridElement.TreeRowElement treeRow = new TreeGridElement.TreeRowElement(plainRow);
assertEquals(0, treeRow.getLevel());
assertFalse(treeRow.isLeaf());// Multi-select mode adds a checkbox column at index 0.
// TreeGridElement handles this automatically.
TreeGridElement grid = TreeGridElement.getById(page, "multi-select-tree-grid");
grid.select(0);
grid.select(1);
assertEquals(2, grid.getSelectedItemCount());
// Expand, then select a child row too
grid.expandRow(0);
grid.select(1); // first child of row 0
assertTrue(grid.findRow(1).get().isSelected());
// Select-all checkbox
grid.checkSelectAll();
assertTrue(grid.isSelectAllChecked());
grid.uncheckSelectAll();
assertEquals(0, grid.getSelectedItemCount());TreeGridElement grid = TreeGridElement.getById(page, "three-level-tree-grid");
assertEquals(2, grid.getTotalRowCount()); // only root divisions visible
// Expand Division A (index 0) to reveal its departments
grid.expandRow(0);
assertEquals(4, grid.getTotalRowCount()); // 2 divisions + Dept A1, Dept A2
// Expand Dept A1 (now at index 1) to reveal its employees
grid.expandRow(1);
assertEquals(6, grid.getTotalRowCount()); // + Employee A1a, Employee A1b
// Verify grandchild level and leaf state
assertEquals(2, grid.findTreeRow(2).get().getLevel()); // Employee A1a is level 2
assertTrue(grid.findTreeRow(2).get().isLeaf());
// Collapse Division A — hides all its descendants
grid.collapseRow(0);
assertEquals(2, grid.getTotalRowCount());