Class GridElement

java.lang.Object
org.vaadin.addons.dramafinder.element.VaadinElement
org.vaadin.addons.dramafinder.element.GridElement
All Implemented Interfaces:
Findable<ComponentQuery<GridElement>>, FocusableElement, HasEnabledElement, HasLocatorElement, HasStyleElement, HasThemeElement
Direct Known Subclasses:
TreeGridElement

PlaywrightElement for <vaadin-grid>.

Provides helpers for scrolling, querying visible rows, accessing cell content, and interacting with the grid's header, body and selection. Cell access uses JavaScript evaluation on the grid's internal APIs since body cells live in shadow DOM and are virtualized.

A column index counts the visible (non-hidden) columns in display order, from 0 on the left: hidden columns are skipped, a selection column counts, and after the user drags a column to a new place the indexes follow the new order. A column without header text can be found by its id (Column.setId(..)) with getColumnIndexById(String). Counting the selection column matches TestBench's GridElement; Flow's Grid.getColumns() and browserless tests leave it out, so in a multi-select grid their index is one less.

  • Field Details

  • Constructor Details

    • GridElement

      public GridElement(com.microsoft.playwright.Locator locator)
      Create a new GridElement.
      Parameters:
      locator - the locator for the <vaadin-grid> element
  • Method Details

    • get

      public static GridElement get(com.microsoft.playwright.Page page)
      Get the first GridElement on the page.
      Parameters:
      page - the Playwright page
      Returns:
      the first matching GridElement
    • get

      public static GridElement get(com.microsoft.playwright.Locator parent)
      Get the first GridElement within a parent locator.
      Parameters:
      parent - the parent locator to search within
      Returns:
      the first matching GridElement
    • getRenderedRowCount

      public int getRenderedRowCount()
      Get the number of rows currently rendered in the DOM. This may be less than the total row count due to virtualization.
      Returns:
      count of rows currently rendered in the DOM
    • getTotalRowCount

      public int getTotalRowCount()
      Get the total number of rows (data items) in the grid.
      Returns:
      total item count
    • getColumnCount

      public int getColumnCount()
      Get the number of visible (non-hidden) columns.
      Returns:
      visible column count
    • findColumnIndexById

      public OptionalInt findColumnIndexById(String id)
      Find the index of the visible column with the given id, the one set with Column.setId(..) in Flow. The index counts visible columns in display order (see the class description), so it can be passed to findCell(int, int) or findHeaderCell(int). A column key (Column.setKey(..)) stays on the server and cannot be found this way.
      Parameters:
      id - the column id, matched exactly
      Returns:
      the 0-based column index; empty if no visible column has that id (the column does not exist or is hidden)
    • getColumnIndexById

      public int getColumnIndexById(String id)
      Get the index of the visible column with the given id, for a column that must exist. findColumnIndexById(String) is the variant that may find none.
      Parameters:
      id - the column id, matched exactly
      Returns:
      the 0-based column index, in display order
      Throws:
      IllegalArgumentException - if no visible column has that id
    • isAllRowsVisible

      public boolean isAllRowsVisible()
      Whether the grid has allRowsVisible enabled.
      Returns:
      true if all rows are visible (no vertical scroll)
    • isMultiSort

      public boolean isMultiSort()
      Whether the grid has multi-sort enabled.
      Returns:
      true if multi-sort is enabled
    • isColumnReorderingAllowed

      public boolean isColumnReorderingAllowed()
      Whether column reordering is allowed.
      Returns:
      true if column reordering is allowed
    • getHeaderRowCount

      protected int getHeaderRowCount()
      Get the number of header rows. Usually 1, but can be more if there are column groups.
      Returns:
      header row count
    • findHeaderCell

      public Optional<GridElement.HeaderCellElement> findHeaderCell(int columnIndex)
      Find a header cell by column index. Uses first header row.
      Parameters:
      columnIndex - 0-based visible column index
      Returns:
      optional header cell element. Empty if no header cell exists at the given column index.
    • findHeaderCell

      public Optional<GridElement.HeaderCellElement> findHeaderCell(int headerRowIndex, int columnIndex)
      Find a header cell by header row index and column index.
      Parameters:
      headerRowIndex - 0-based header row index. Use 0 for the first header row, 1 for the second, etc.
      columnIndex - 0-based visible column index.
      Returns:
      optional header cell element. Empty if no header cell exists at the given header row and column index.
    • findHeaderCellByText

      public Optional<GridElement.HeaderCellElement> findHeaderCellByText(String text)
      Find a header cell by its text content. Uses first header row.
      Parameters:
      text - the header text to find
      Returns:
      optional header cell element. Empty if no header cell with the given text is found.
    • findHeaderCellByText

      public Optional<GridElement.HeaderCellElement> findHeaderCellByText(int headerRowIndex, String text)
      Find a header cell by header row index and text content.
      Parameters:
      headerRowIndex - 0-based header row index. Use 0 for the first header row, 1 for the second, etc.
      text - the header text to find
      Returns:
      optional header cell element. Empty if no header cell with the given text is found in the given header row.
    • getHeaderCells

      public List<GridElement.HeaderCellElement> getHeaderCells(int columnIndex)
      Get the header cells of a column in every header row, top row first: the cell of the column itself and those of the column groups around it. In Flow these are the column's cells in every HeaderRow, e.g. a joined group header above and a filter field in an appended row below; a cell joined over several columns is returned for each column it spans. Scope a lookup to GridElement.CellElement.getCellContentLocator() to reach a component in a cell. Every returned cell reports columnIndex as its column index.
      Parameters:
      columnIndex - 0-based visible column index, in display order (see the class description)
      Returns:
      the header cells, top row first, leaving out header rows the grid hides because all their cells are empty; empty if the column has no shown header cell
      Throws:
      IllegalArgumentException - if the column index is negative or no visible column has it
    • getHeaderCellContents

      public List<String> getHeaderCellContents()
      Get the text content of all visible header cells.
      Returns:
      list of header cell text contents
    • matchesHeaderCell

      protected boolean matchesHeaderCell(GridElement.CellElement cell, String text)
      Determine if a header cell matches the given text. By default, compares the trimmed innerText of the cell content. Can be overridden for custom matching logic (e.g. ignoring case, or matching only a part of the text).
      Parameters:
      cell - the header cell to check
      text - the header text to match
      Returns:
      true if the cell matches the text, false otherwise
    • getFooterRowCount

      protected int getFooterRowCount()
      Get the number of footer rows. Usually 0 (no footer) or 1, but can be more if there are column groups.
      Returns:
      footer row count
    • findFooterCell

      public Optional<GridElement.FooterCellElement> findFooterCell(int columnIndex)
      Find a footer cell by column index. Uses the first footer row.
      Parameters:
      columnIndex - 0-based visible column index
      Returns:
      optional footer cell element. Empty if no footer cell exists at the given column index.
    • findFooterCell

      public Optional<GridElement.FooterCellElement> findFooterCell(int footerRowIndex, int columnIndex)
      Find a footer cell by footer row index and column index.
      Parameters:
      footerRowIndex - 0-based footer row index. Use 0 for the first footer row, 1 for the second, etc.
      columnIndex - 0-based visible column index.
      Returns:
      optional footer cell element. Empty if no footer cell exists at the given footer row and column index.
    • findFooterCellByText

      public Optional<GridElement.FooterCellElement> findFooterCellByText(String text)
      Find a footer cell by its text content. Uses the first footer row.
      Parameters:
      text - the footer text to find
      Returns:
      optional footer cell element. Empty if no footer cell with the given text is found.
    • findFooterCellByText

      public Optional<GridElement.FooterCellElement> findFooterCellByText(int footerRowIndex, String text)
      Find a footer cell by footer row index and text content.
      Parameters:
      footerRowIndex - 0-based footer row index. Use 0 for the first footer row, 1 for the second, etc.
      text - the footer text to find
      Returns:
      optional footer cell element. Empty if no footer cell with the given text is found in the given footer row.
    • getFooterCellContents

      public List<String> getFooterCellContents()
      Get the text content of all visible footer cells.
      Returns:
      list of footer cell text contents
    • matchesFooterCell

      protected boolean matchesFooterCell(GridElement.CellElement cell, String text)
      Determine if a footer cell matches the given text. By default, compares the trimmed innerText of the cell content. Can be overridden for custom matching logic (e.g. ignoring case, or matching only a part of the text).
      Parameters:
      cell - the footer cell to check
      text - the footer text to match
      Returns:
      true if the cell matches the text, false otherwise
    • findCell

      public Optional<GridElement.CellElement> findCell(int row, int column)
      Find a body cell by row index and column index.
      Parameters:
      row - row index, starting from 0.
      column - column index, starting from 0.
      Returns:
      optional cell element. Empty if no cell exists at the given row and column index.
    • findCell

      public Optional<GridElement.CellElement> findCell(int row, String columnHeaderText)
      Find a body cell by row index and column header text.
      Parameters:
      row - row index, starting from 0.
      columnHeaderText - the header text of the column to find.
      Returns:
      optional cell element. Empty if no cell exists at the given row and column header text.
    • findRowIndexesWithColumnText

      public List<Integer> findRowIndexesWithColumnText(int columnIndex, String text)
      Find row indexes where the cell in the given column has the given text. Reads the column a rendered page of rows at a time (see getColumnTexts(int)), so a lazy grid is scrolled once per page rather than once per row; each cell is compared with matchesCellText(String, String).
      Parameters:
      columnIndex - the column index to check the cell content in, starting from 0.
      text - the text to match in the cell content.
      Returns:
      list of row indexes where the cell in the given column matches the given text. Empty list if no match is found.
    • getColumnTexts

      public List<String> getColumnTexts(int columnIndex)
      Read the rendered text of every body cell in the given column, from the first row to the last. The grid is read a page at a time: one script reads all rows rendered at once, then the grid jumps to the first row not read yet and waits for it to load. A lazy grid therefore costs one scroll and one round trip per page instead of several per row. A row that is still not rendered after the jump is looked up on its own, as findRow(int) does. Leaves the grid scrolled to wherever the last page was.
      Parameters:
      columnIndex - the column index, starting from 0.
      Returns:
      the cell texts (the innerText of the cell content), indexed by row; an entry is null when that row could not be rendered. Empty for an empty grid.
      Throws:
      IllegalArgumentException - if the column index is negative, or the grid has rows and the column does not exist
    • findRow

      public Optional<GridElement.RowElement> findRow(int rowIndex)
      Find a row by its index. Scrolls the grid if necessary to find the row.
      Parameters:
      rowIndex - row index, starting from 0.
      Returns:
      optional row element. Empty if no row exists at the given index.
    • findRow

      protected Optional<GridElement.RowElement> findRow(int rowIndex, int headerRowCount)
      Find a row by its index, given the number of header rows.
      Parameters:
      rowIndex - row index, starting from 0.
      headerRowCount - number of header rows in the grid, used to calculate the aria-rowIndex for finding the row.
      Returns:
      optional row element. Empty if no row exists at the given index.
    • matchesCellContent

      @Deprecated(since="2.0.1", forRemoval=true) protected boolean matchesCellContent(GridElement.CellElement cell, String text)
      Deprecated, for removal: This API element is subject to removal in a future version.
      findRowIndexesWithColumnText(int, String) reads a whole column at once and no longer calls this method; override matchesCellText(String, String) to customise matching.
      Determine if a body cell matches the given text, by comparing its rendered text with matchesCellText(String, String).
      Parameters:
      cell - the body cell to check
      text - the text to match in the cell content
      Returns:
      true if the cell matches the text, false otherwise
    • matchesCellText

      protected boolean matchesCellText(String cellText, String text)
      Determine if a body cell's rendered text matches the given text. By default, the two must be equal. Override for custom matching logic (e.g. ignoring case, or matching only a part of the text).
      Parameters:
      cellText - the innerText of the cell content, never null
      text - the text to match
      Returns:
      true if the cell text matches, false otherwise
    • scrollToRow

      public void scrollToRow(int rowIndex)
      Scroll the grid so that the given row index becomes visible. Waits for the row to be rendered in the DOM before returning.
      Parameters:
      rowIndex - the 0-based row index to scroll to
    • scrollToStart

      public void scrollToStart()
      Scroll to the very beginning of the grid.
    • scrollToEnd

      public void scrollToEnd()
      Scroll to the very end of the grid.
    • select

      public void select(int rowIndex)
      Select a row by index, clicking it like a user would. Does nothing if the row is already selected.
      Parameters:
      rowIndex - index of the row to select, starting from 0.
      Throws:
      IllegalArgumentException - if no row exists at the given index
      AssertionError - if the row is not selected after the click, e.g. because the grid has no selection or the server rejected it
    • select

      protected void select(GridElement.RowElement row)
      Select the row. You can override this method to implement custom selection logic, for example if you want to select by clicking some other cell than the first one, or if you want to use some modifier keys for selection.
      Parameters:
      row - row to select.
      Throws:
      AssertionError - if the row is not selected after the click
    • deselect

      public void deselect(int rowIndex)
      Deselect a row by index, clicking it like a user would. Does nothing if the row is not selected.
      Parameters:
      rowIndex - index of the row to deselect, starting from 0.
      Throws:
      IllegalArgumentException - if no row exists at the given index
      AssertionError - if the row is still selected after the click, e.g. because the grid does not allow deselecting
    • deselect

      protected void deselect(GridElement.RowElement row)
      Deselect the row. You can override this method to implement custom selection logic, for example if you want to deselect by clicking some other cell than the first one, or if you want to use some modifier keys for deselection.
      Parameters:
      row - row to deselect.
      Throws:
      AssertionError - if the row is still selected after the click
    • clickRowForSelection

      protected void clickRowForSelection(GridElement.RowElement row)
      Toggle the selection of a row by clicking it like a user would. Clicks the selection checkbox of the first cell when there is one. Otherwise clicks the first cell that has a spot where a click reaches the grid rather than a component rendered in the cell, usually its padding, so a cell holding a link or a button still selects the row: the grid ignores clicks on links, buttons and other focusable content, which would only trigger that component. You can override this method to choose the cell to click yourself.
      Parameters:
      row - row to select or deselect
      Throws:
      IllegalStateException - if interactive content covers every cell of the row, padding included
    • clickCellForSelection

      protected void clickCellForSelection(GridElement.CellElement cell)
      Click the given cell to toggle the selection of its row. Clicks the selection checkbox when the cell holds one, otherwise a spot of the cell that is not covered by interactive content, typically its padding. You can override this method to implement custom selection logic for given cell.
      Parameters:
      cell - the body cell to click
      Throws:
      IllegalStateException - if interactive content covers the whole cell, padding included
    • getSelectedItemCount

      public int getSelectedItemCount()
      Get the number of currently selected items.
      Returns:
      selected item count
    • isSelectAllChecked

      public boolean isSelectAllChecked()
      Check if the select-all checkbox is checked.
      Returns:
      true if the select-all checkbox is checked (and not indeterminate), false otherwise
    • isSelectAllIndeterminate

      public boolean isSelectAllIndeterminate()
      Check if the select-all checkbox is indeterminate.
      Returns:
      true if the select-all checkbox is indeterminate, false otherwise
    • isSelectAllUnchecked

      public boolean isSelectAllUnchecked()
      Check if the select-all checkbox is unchecked.
      Returns:
      true if the select-all checkbox is unchecked, false otherwise
    • checkSelectAll

      public void checkSelectAll()
      Check the select-all checkbox. Does nothing if the select-all checkbox is already checked.
    • uncheckSelectAll

      public void uncheckSelectAll()
      Uncheck the select-all checkbox. Does nothing if the select-all checkbox is already unchecked.
    • openDetails

      protected void openDetails(GridElement.RowElement row)
      Open the details of a row by clicking it (see GridElement.RowElement.click()), which relies on the grid toggling details on click: Flow's Grid.setDetailsVisibleOnClick(true), the default. Does nothing if the details are already open. In a single-select grid the click also selects the row. Override this method if the details are opened another way, for example by a button.
      Parameters:
      row - row for which to open details
      Throws:
      AssertionError - if the details are not open after the click
    • closeDetails

      protected void closeDetails(GridElement.RowElement row)
      Close the details of a row by clicking it (see GridElement.RowElement.click()), which relies on the grid toggling details on click: Flow's Grid.setDetailsVisibleOnClick(true), the default. Does nothing if the details are already closed. Override this method if the details are closed another way, for example by a button.
      Parameters:
      row - row for which to close details
      Throws:
      AssertionError - if the details are still open after the click
    • waitForGridToStopLoading

      public void waitForGridToStopLoading()
      Wait for the grid to finish loading after a scroll or other action that triggers loading of new rows. Returns without waiting when the grid is no longer in the DOM, e.g. because a click on a cell navigated to another view.
    • isRowInView

      public boolean isRowInView(int rowIndex)
      Whether the row with the given index is currently scrolled into view (at least partially visible between the header and footer), without triggering any scrolling.
      Parameters:
      rowIndex - row index, starting from 0.
      Returns:
      true if the row is rendered and at least partially visible, false otherwise
    • assertRowCount

      public void assertRowCount(int expected)
      Assert that the grid has the given total number of rows (data items).
      Parameters:
      expected - the expected total row count
    • assertEmpty

      public void assertEmpty()
      Assert that the grid has no rows.
    • assertColumnCount

      public void assertColumnCount(int expected)
      Assert that the grid has the given number of visible (non-hidden) columns.
      Parameters:
      expected - the expected visible column count
    • assertAllRowsVisible

      public void assertAllRowsVisible()
      Assert that allRowsVisible is enabled.
    • assertNotAllRowsVisible

      public void assertNotAllRowsVisible()
      Assert that allRowsVisible is not enabled.
    • assertMultiSort

      public void assertMultiSort()
      Assert that multi-sort is enabled.
    • assertNotMultiSort

      public void assertNotMultiSort()
      Assert that multi-sort is not enabled.
    • assertColumnReorderingAllowed

      public void assertColumnReorderingAllowed()
      Assert that column reordering is allowed.
    • assertColumnReorderingNotAllowed

      public void assertColumnReorderingNotAllowed()
      Assert that column reordering is not allowed.
    • assertCellContent

      public void assertCellContent(int row, int column, String expected)
      Assert that the body cell at the given row and column has the given text content. Auto-scrolls the grid if necessary to bring the row into view.
      Parameters:
      row - row index, starting from 0.
      column - column index, starting from 0.
      expected - the expected cell text content
    • assertCellContent

      public void assertCellContent(int row, String columnHeaderText, String expected)
      Assert that the body cell at the given row and column header has the given text content. Auto-scrolls the grid if necessary to bring the row into view.
      Parameters:
      row - row index, starting from 0.
      columnHeaderText - the header text of the column.
      expected - the expected cell text content
    • assertCellPresent

      public void assertCellPresent(int row, int column)
      Assert that a cell exists at the given row and column.
      Parameters:
      row - row index, starting from 0.
      column - column index, starting from 0.
    • assertCellNotPresent

      public void assertCellNotPresent(int row, int column)
      Assert that no cell exists at the given row and column.
      Parameters:
      row - row index, starting from 0.
      column - column index, starting from 0.
    • assertHeaderCellContents

      public void assertHeaderCellContents(String... expected)
      Assert that the visible header cells have exactly the given text contents, in order.
      Parameters:
      expected - the expected header cell text contents
    • assertHeaderCell

      public void assertHeaderCell(int column, String expected)
      Assert that the header cell at the given column has the given text content.
      Parameters:
      column - column index, starting from 0.
      expected - the expected header cell text content
    • assertColumnPresent

      public void assertColumnPresent(String headerText)
      Assert that a column with the given header text exists.
      Parameters:
      headerText - the header text to look for
    • assertColumnNotPresent

      public void assertColumnNotPresent(String headerText)
      Assert that no column with the given header text exists.
      Parameters:
      headerText - the header text to look for
    • assertFooterCellContents

      public void assertFooterCellContents(String... expected)
      Assert that the visible footer cells have exactly the given text contents, in order.
      Parameters:
      expected - the expected footer cell text contents
    • assertFooterCell

      public void assertFooterCell(int column, String expected)
      Assert that the footer cell at the given column has the given text content.
      Parameters:
      column - column index, starting from 0.
      expected - the expected footer cell text content
    • assertFooterPresent

      public void assertFooterPresent(String footerText)
      Assert that a footer cell with the given text exists.
      Parameters:
      footerText - the footer text to look for
    • assertFooterNotPresent

      public void assertFooterNotPresent(String footerText)
      Assert that no footer cell with the given text exists.
      Parameters:
      footerText - the footer text to look for
    • assertRowPresent

      public void assertRowPresent(int rowIndex)
      Assert that a row exists at the given index (auto-scrolling if necessary).
      Parameters:
      rowIndex - row index, starting from 0.
    • assertRowNotPresent

      public void assertRowNotPresent(int rowIndex)
      Assert that no row exists at the given index.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertRowInView

      public void assertRowInView(int rowIndex)
      Assert that the row with the given index is currently scrolled into view.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertRowNotInView

      public void assertRowNotInView(int rowIndex)
      Assert that the row with the given index is not currently scrolled into view.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertRowIndexesWithColumnText

      public void assertRowIndexesWithColumnText(int column, String text, Integer... expected)
      Assert that the cells in the given column with the given text appear at exactly the given row indexes.
      Parameters:
      column - column index, starting from 0.
      text - the text to match in the cell content.
      expected - the expected row indexes (in order)
    • assertSelectedItemCount

      public void assertSelectedItemCount(int expected)
      Assert that the given number of items are currently selected.
      Parameters:
      expected - the expected selected item count
    • assertRowSelected

      public void assertRowSelected(int rowIndex)
      Assert that the row at the given index is selected.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertRowNotSelected

      public void assertRowNotSelected(int rowIndex)
      Assert that the row at the given index is not selected.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertSelectAllChecked

      public void assertSelectAllChecked()
      Assert that the select-all checkbox is checked.
    • assertSelectAllUnchecked

      public void assertSelectAllUnchecked()
      Assert that the select-all checkbox is unchecked.
    • assertSelectAllIndeterminate

      public void assertSelectAllIndeterminate()
      Assert that the select-all checkbox is indeterminate.
    • assertDetailsOpen

      public void assertDetailsOpen(int rowIndex)
      Assert that the details panel of the row at the given index is open.
      Parameters:
      rowIndex - row index, starting from 0.
    • assertDetailsClosed

      public void assertDetailsClosed(int rowIndex)
      Assert that the details panel of the row at the given index is closed.
      Parameters:
      rowIndex - row index, starting from 0.
    • getById

      public static GridElement getById(com.microsoft.playwright.Page page, String id)
      Get a GridElement by its id, searching the entire page.

      A fallback for a component without a user-visible name: prefer the label or text lookups when there is one. The id must match in full; two components with that id fail with a strict-mode error.

      Parameters:
      page - the Playwright page
      id - the full id
      Returns:
      the matching GridElement
    • getById

      public static GridElement getById(com.microsoft.playwright.Locator locator, String id)
      Get a GridElement by its id, scoped to the given locator.

      A fallback for a component without a user-visible name. The id must match in full; two components with that id inside the scope fail with a strict-mode error.

      Parameters:
      locator - the locator whose subtree is searched
      id - the full id
      Returns:
      the matching GridElement
    • getByTestId

      public static GridElement getByTestId(com.microsoft.playwright.Page page, String testId)
      Get a GridElement by its test id, searching the entire page.

      The test id is Playwright's test id attribute, data-testid unless reconfigured — the attribute Flow's Component.setTestId(String) sets. A fallback for a component without a user-visible name; it must match in full, and two components with that test id fail with a strict-mode error.

      Parameters:
      page - the Playwright page
      testId - the full test id
      Returns:
      the matching GridElement
    • getByTestId

      public static GridElement getByTestId(com.microsoft.playwright.Locator locator, String testId)
      Get a GridElement by its test id, scoped to the given locator.

      See getByTestId(Page, String); only components inside the scope are considered.

      Parameters:
      locator - the locator whose subtree is searched
      testId - the full test id
      Returns:
      the matching GridElement