Class GridElement

java.lang.Object
com.vaadin.testbench.TestBenchElement
com.vaadin.flow.component.grid.testbench.GridElement
All Implemented Interfaces:
com.vaadin.testbench.commands.CanCompareScreenshots, com.vaadin.testbench.HasCallFunction, com.vaadin.testbench.HasDriver, com.vaadin.testbench.HasElementQuery, com.vaadin.testbench.HasPropertySettersGetters, com.vaadin.testbench.HasSearchContext, com.vaadin.testbench.HasTestBenchCommandExecutor, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebElement, org.openqa.selenium.WrapsElement
Direct Known Subclasses:
TreeGridElement

public class GridElement extends com.vaadin.testbench.TestBenchElement
A TestBench element representing a <vaadin-grid> element.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Click select all check box
    void
    deselect(int rowIndex)
    Deselects the row with the given index.
    Gets the text content of all rows in the grid as a 2D list, ordered by row index.
    Gets all columns defined for the grid, including any selection checkbox column.
    getCell(int rowIndex, int colIndex)
    Gets the grid cell for the given row and column index.
    getCell(int rowIndex, GridColumnElement column)
    Gets the grid cell for the given row and column.
    getCell(String contents)
    Finds the first cell inside the rendered range with a text content matching the given string.
    getCellContents(int fromRow, int toRow)
    Gets the text content of the given row range as a 2D list, ordered by row index.
    getCells(int rowIndex)
    Gets the grid cells for the given row.
    getCells(int rowIndex, GridColumnElement... columnElements)
    Gets the grid cells for the given row and column elements.
    getColumn(String headerText)
    Gets the column with the given header text.
    com.vaadin.testbench.TestBenchElement
    Gets the empty state content.
    int
    Gets the index of the first row which is at least partially visible.
    getFooterCell(int columnIndex)
    Gets the footer cell for the given visible column index.
    getFooterCell(int rowIndex, int columnIndex)
    Finds the cell element for the given row and column in footer.
    com.vaadin.testbench.TestBenchElement
    getFooterCellContent(int rowIndex, int columnIndex)
    Finds the vaadin-grid-cell-content element for the given row and column in footer.
    getHeaderCell(int columnIndex)
    Gets the header cell for the given visible column index.
    getHeaderCell(int rowIndex, int columnIndex)
    Finds the cell element for the given row and column in header.
    com.vaadin.testbench.TestBenchElement
    getHeaderCellContent(int rowIndex, int columnIndex)
    Finds the vaadin-grid-cell-content element for the given row and column in header.
    int
    Gets the index of the last row which is at least partially visible.
    int
    Gets the page size used when fetching data.
    getRow(int rowIndex)
    Gets the tr element for the given row index.
    getRow(int rowIndex, boolean scroll)
    Gets the tr element for the given row index.
    int
    Gets the total number of rows.
    getRows(int firstRowIndex, int lastRowIndex)
    Gets the rows (present in the DOM) specified by the lower and upper row indexes.
    Gets the text content of the rows that are currently in the viewport as a 2D list, ordered by row index.
    Gets the currently visible columns in the grid, including any selection checkbox column.
    Gets all the currently visible rows.
    protected boolean
     
    void
    scrollToColumn(int columnIndex)
    Scrolls the grid horizontally to make the column with the given index visible.
    void
    Scrolls the grid horizontally to make the given column visible.
    void
    scrollToRow(int row)
    Scrolls to the row with the given index.
    void
    select(int rowIndex)
    Selects the row with the given index.
    protected void
     

    Methods inherited from class com.vaadin.testbench.TestBenchElement

    callFunction, clear, click, click, compareScreen, compareScreen, compareScreen, contextClick, dispatchEvent, dispatchEvent, doubleClick, equals, executeScript, findElement, findElements, focus, getAttribute, getCapabilities, getChildren, getClassNames, getCommandExecutor, getContext, getCssValue, getDomAttribute, getDomProperty, getDriver, getId, getLocation, getParent, getProperty, getPropertyBoolean, getPropertyDouble, getPropertyElement, getPropertyElements, getPropertyInteger, getPropertyString, getRect, getScreenshotAs, getShadowRoot, getSize, getTagName, getText, getWrappedElement, hasAttribute, hasClassName, hashCode, hover, init, init, isChrome, isDisplayed, isEnabled, isFirefox, isFocused, isReadOnly, isSelected, scroll, scrollIntoView, scrollIntoView, scrollLeft, sendKeys, setProperty, setProperty, setProperty, setProperty, submit, waitForVaadin, waitUntil, waitUntil, wrap, wrapElement, wrapElements

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.testbench.HasElementQuery

    $, $

    Methods inherited from interface org.openqa.selenium.WebElement

    getAccessibleName, getAriaRole
  • Constructor Details

    • GridElement

      public GridElement()
  • Method Details

    • waitUntilLoadingFinished

      protected void waitUntilLoadingFinished()
    • isLoading

      protected boolean isLoading()
    • scrollToRow

      public void scrollToRow(int row)
      Scrolls to the row with the given index.
      Parameters:
      row - the row to scroll to
    • scrollToColumn

      public void scrollToColumn(int columnIndex)
      Scrolls the grid horizontally to make the column with the given index visible. The index refers to visible columns, in their visual order.
      Parameters:
      columnIndex - the index of the column to scroll to
    • scrollToColumn

      public void scrollToColumn(GridColumnElement column)
      Scrolls the grid horizontally to make the given column visible.
      Parameters:
      column - the column to scroll to
    • getPageSize

      public int getPageSize()
      Gets the page size used when fetching data.
      Returns:
      the page size
    • getFirstVisibleRowIndex

      public int getFirstVisibleRowIndex()
      Gets the index of the first row which is at least partially visible.
      Returns:
      the index of the first visible row, -1 if Grid is empty
    • getRowCount

      public int getRowCount()
      Gets the total number of rows.
      Returns:
      the number of rows
    • getCell

      public GridTHTDElement getCell(int rowIndex, int colIndex)
      Gets the grid cell for the given row and column index.

      For the column index, only visible columns are taken into account.

      Automatically scrolls the given row into view

      Parameters:
      rowIndex - the row index
      colIndex - the column index
      Returns:
      the grid cell for the given coordinates
    • getCell

      public GridTHTDElement getCell(int rowIndex, GridColumnElement column)
      Gets the grid cell for the given row and column.

      Automatically scrolls the given row into view

      Parameters:
      rowIndex - the row index
      column - the column element for the column
      Returns:
      the grid cell for the given coordinates
    • getCell

      public GridTHTDElement getCell(String contents) throws org.openqa.selenium.NoSuchElementException
      Finds the first cell inside the rendered range with a text content matching the given string.
      Parameters:
      contents - the string to look for
      Returns:
      a grid cell containing the given string
      Throws:
      org.openqa.selenium.NoSuchElementException - if no cell with the given string was found
    • getLastVisibleRowIndex

      public int getLastVisibleRowIndex()
      Gets the index of the last row which is at least partially visible.
      Returns:
      the index of the last visible row, -1 if Grid is empty
    • getRows

      public List<GridTRElement> getRows(int firstRowIndex, int lastRowIndex) throws IndexOutOfBoundsException
      Gets the rows (present in the DOM) specified by the lower and upper row indexes.
      Parameters:
      firstRowIndex - the lower row index to be retrieved (inclusive)
      lastRowIndex - the upper row index to be retrieved (inclusive)
      Returns:
      a GridTRElement list with the rows contained between the given coordinates.
      Throws:
      IndexOutOfBoundsException - if either of the provided row indexes do not exist
    • getRow

      public GridTRElement getRow(int rowIndex) throws IndexOutOfBoundsException
      Gets the tr element for the given row index.
      Parameters:
      rowIndex - the row index
      Returns:
      the tr element for the row, or null if the row is not in viewport
      Throws:
      IndexOutOfBoundsException - if no row with given index exists
    • getRow

      public GridTRElement getRow(int rowIndex, boolean scroll) throws IndexOutOfBoundsException
      Gets the tr element for the given row index.

      Returns null if the row is not in viewport and the provided scroll parameter is false.

      Parameters:
      rowIndex - the row index
      scroll - whether to scroll to the row index
      Returns:
      the tr element for the row, or null if the row is not in viewport and the provided scroll parameter is false
      Throws:
      IndexOutOfBoundsException - if no row with given index exists
    • getAllColumns

      public List<GridColumnElement> getAllColumns()
      Gets all columns defined for the grid, including any selection checkbox column.
      Returns:
      a list of grid column elements which can be used to refer to the given column
    • getVisibleColumns

      public List<GridColumnElement> getVisibleColumns()
      Gets the currently visible columns in the grid, including any selection checkbox column.
      Returns:
      a list of grid column elements which can be used to refer to the given column
    • getColumn

      public GridColumnElement getColumn(String headerText) throws org.openqa.selenium.NoSuchElementException
      Gets the column with the given header text.

      If multiple columns are found with the same header text, returns the first column.

      Parameters:
      headerText - the text in the header
      Returns:
      the grid column element for the given column
      Throws:
      org.openqa.selenium.NoSuchElementException - if no column was found
    • getHeaderCell

      public GridTHTDElement getHeaderCell(int columnIndex)
      Gets the header cell for the given visible column index.
      Parameters:
      columnIndex - the index of the column
      Returns:
      a cell element for the header cell
    • getHeaderCellContent

      public com.vaadin.testbench.TestBenchElement getHeaderCellContent(int rowIndex, int columnIndex)
      Finds the vaadin-grid-cell-content element for the given row and column in header.
      Parameters:
      rowIndex - the index of the row in the header
      columnIndex - the index of the column in the header
      Returns:
      the vaadin-grid-cell-content element for the given row and column in header.
    • getHeaderCell

      public GridTHTDElement getHeaderCell(int rowIndex, int columnIndex)
      Finds the cell element for the given row and column in header.
      Parameters:
      rowIndex - the index of the row in the header
      columnIndex - the index of the column in the header
      Returns:
      the GridTHTDElement for the given row and column in header.
    • getFooterCell

      public GridTHTDElement getFooterCell(int columnIndex)
      Gets the footer cell for the given visible column index.
      Parameters:
      columnIndex - the index of the column
      Returns:
      a cell element for the footer cell
    • getFooterCellContent

      public com.vaadin.testbench.TestBenchElement getFooterCellContent(int rowIndex, int columnIndex)
      Finds the vaadin-grid-cell-content element for the given row and column in footer.
      Parameters:
      rowIndex - the index of the row in the footer
      columnIndex - the index of the column in the footer
      Returns:
      the vaadin-grid-cell-content element for the given row and column in footer.
    • getFooterCell

      public GridTHTDElement getFooterCell(int rowIndex, int columnIndex)
      Finds the cell element for the given row and column in footer.
      Parameters:
      rowIndex - the index of the row in the footer
      columnIndex - the index of the column in the footer
      Returns:
      the GridTHTDElement for the given row and column in footer.
    • select

      public void select(int rowIndex)
      Selects the row with the given index.

      Automatically scrolls the given row into view.

      Parameters:
      rowIndex - the row to select
    • deselect

      public void deselect(int rowIndex)
      Deselects the row with the given index.
      Parameters:
      rowIndex - the row to deselect
    • clickSelectAll

      public void clickSelectAll()
      Click select all check box
    • getVisibleRows

      public List<GridTRElement> getVisibleRows()
      Gets all the currently visible rows.
      Returns:
      a GridTRElement list representing the currently visible rows.
    • getCells

      public List<GridTHTDElement> getCells(int rowIndex, GridColumnElement... columnElements)
      Gets the grid cells for the given row and column elements.
      Parameters:
      rowIndex - the row index
      columnElements - the column elements
      Returns:
      a GridTHTDElement list with the cells for the given coordinates.
    • getCells

      public List<GridTHTDElement> getCells(int rowIndex)
      Gets the grid cells for the given row.
      Parameters:
      rowIndex - the row index
      Returns:
      a GridTHTDElement list with the cells for the given coordinates.
    • getVisibleCellContents

      public List<List<String>> getVisibleCellContents()
      Gets the text content of the rows that are currently in the viewport as a 2D list, ordered by row index. Only the rows are limited to the viewport, not the columns. This is a fast operation requiring only a single browser round-trip.

      Rows that are rendered but scrolled out of view are not included; use getAllCellContents() or getCellContents(int, int) to include rows outside the viewport.

      Each row holds one entry for each column in getVisibleColumns(), in the same order. This includes columns that are scrolled out of view horizontally or not rendered because of lazy column rendering. Hidden columns are not included. The text of each cell matches GridTHTDElement.getText().

      Returns:
      a list of rows, each holding the cell text for every column in getVisibleColumns()
    • getCellContents

      public List<List<String>> getCellContents(int fromRow, int toRow) throws IndexOutOfBoundsException
      Gets the text content of the given row range as a 2D list, ordered by row index. The grid is scrolled as needed to load the requested rows.

      Each row holds one entry for each column in getVisibleColumns(), in the same order. This includes columns that are scrolled out of view horizontally or not rendered because of lazy column rendering. Hidden columns are not included. The text of each cell matches GridTHTDElement.getText().

      Parameters:
      fromRow - starting row index (inclusive)
      toRow - ending row index (inclusive)
      Returns:
      a list of rows, each holding the cell text for every column in getVisibleColumns()
      Throws:
      IndexOutOfBoundsException - if the grid is empty, if the row indexes are out of bounds, or if fromRow is greater than toRow
    • getAllCellContents

      public List<List<String>> getAllCellContents()
      Gets the text content of all rows in the grid as a 2D list, ordered by row index. The grid is scrolled through all pages, so this may take a few seconds for large grids, but is much faster than calling GridTHTDElement.getText() on individual cells.

      Each row holds one entry for each column in getVisibleColumns(), in the same order. This includes columns that are scrolled out of view horizontally or not rendered because of lazy column rendering. Hidden columns are not included. The text of each cell matches GridTHTDElement.getText().

      Returns:
      a list of rows, each holding the cell text for every column in getVisibleColumns()
    • getEmptyStateContent

      public com.vaadin.testbench.TestBenchElement getEmptyStateContent()
      Gets the empty state content.
      Returns:
      the empty state content
      Throws:
      org.openqa.selenium.NoSuchElementException - if no empty state content was found