Skip to content

feat: add GridElement methods to read cell contents in bulk - #8513

Open
Artur- wants to merge 5 commits into
mainfrom
grid-dump-cells
Open

feat: add GridElement methods to read cell contents in bulk#8513
Artur- wants to merge 5 commits into
mainfrom
grid-dump-cells

Conversation

@Artur-

@Artur- Artur- commented Jan 22, 2026

Copy link
Copy Markdown
Member

Reading grid data in a TestBench test today means calling getCell(row, col).getText()
for every cell, and each call is a separate browser round-trip. For anything larger
than a handful of rows this is very slow, and there is no built-in way to grab the
data the grid is showing as a plain 2D structure to compare against expected values.

This adds three methods to GridElement that read cell text in bulk:

  • getVisibleCellContents() — the rows currently in the viewport, in one round-trip.
  • getCellContents(fromRow, toRow) — a specific row range, scrolling as needed to
    load the rows.
  • getAllCellContents() — every row, by scrolling through all pages.

All three return List<List<String>> (rows of visible-column text). The text of each
cell matches GridTHTDElement.getText(), so existing expected-value comparisons keep
working. Hidden columns are excluded, and rows are always returned in row-index order
(the grid recycles row elements, so DOM order does not match visual order).

The extraction runs in the browser as a single executeScript per rendered window
instead of one request per cell, which is the whole point: for a grid with N rows and
M columns this replaces N×M round-trips with 1 (viewport) or roughly one per page
(range/all).

The extraction reads the rendered DOM rather than the server-side data provider, so
the result reflects what the grid actually shows, including what renderers produced.

Tests cover small/medium/large and callback-backed grids, hidden columns, invalid
ranges, parity with getCell().getText(), and that the viewport dump returns exactly
the visible rows in order.

Fixes vaadin/testbench#1876

@sonarqubecloud

Copy link
Copy Markdown

@yuriy-fix

Copy link
Copy Markdown
Contributor

@Artur- , would you like to proceed with the change and mark it ready for review or there is anything you would like to adjust in the PR or have a discussion about?

Artur- added 2 commits July 7, 2026 11:11
Add three new methods to GridElement for efficient grid cell extraction:
- dumpVisibleCells(): dumps currently visible cells in one browser round-trip
- dumpAllCells(): dumps all grid cells by scrolling through pages
- dumpCells(fromRow, toRow): dumps cells for a specific row range

This addresses the performance issue when testing grid content, reducing
browser round-trips from N×M (one per cell) to 1-50 requests depending on
grid size, resulting in 20-500x performance improvement.

Only visible columns are included in the output. Hidden columns are filtered
out automatically.

Fixes #1876
Rename dump* to get*CellContents to match GridElement naming. Fix
row ordering in the visible-rows dump, match GridTHTDElement.getText()
text extraction exactly, deduplicate the extraction JS into one shared
snippet, and drop the flaky timing assertion.
@Artur-
Artur- force-pushed the grid-dump-cells branch from 5749ad2 to 6539936 Compare July 7, 2026 09:19
@Artur-

Artur- commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Updated to make more sense and work better

@Artur-
Artur- marked this pull request as ready for review July 7, 2026 09:24
@Artur- Artur- changed the title feat: add fast grid cell dump methods to GridElement feat: add GridElement methods to read cell contents in bulk Jul 7, 2026
Artur- added 3 commits July 8, 2026 15:21
getCellContents(0, 0) on an empty grid threw with a broken "0..-1"
bound. Detect the empty grid first and throw with a clear message.
getAllCellContents keeps returning an empty list.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast Grid Dump

3 participants