Repository navigation
[test-helpers] Add EuiTableObject #10213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steliosmavro
merged 4 commits into
elastic:main
from
steliosmavro:stelios/eui-table-object
Oct 20, 2026
+203
−16
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c4e3a8
[test-helpers] Add EuiTableObject
steliosmavro c31f17c
Add changelog
steliosmavro 664ae7d
Address review: header cells include the checkbox cell, colspan filte…
steliosmavro 951a302
Merge branch 'main' into stelios/eui-table-object
steliosmavro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added `EuiTableObject` for `EuiTable`, with `rows`, `headerCells`, `column(index)` and `cell(row, column)`. `EuiBasicTableObject` now extends it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # EuiTableObject | ||
|
|
||
| Playwright Component Object for [EuiTable](https://eui.elastic.co/docs/components/tabular-content/tables/), the low level table built from `EuiTableHeader`, `EuiTableRow` and `EuiTableRowCell`. `EuiBasicTableObject` extends it for `EuiBasicTable` and `EuiInMemoryTable`, use that one when the table has field based columns. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```ts | ||
| import { EuiTableObject } from '@elastic/eui-test-helpers'; | ||
|
|
||
| const table = new EuiTableObject(page, 'myTable'); | ||
| await expect(table.rows).toHaveCount(3); | ||
| await expect(table.column(1)).toHaveText(['Running', 'Finished', 'Archived']); | ||
| await expect(table.cell(0, 1)).toHaveText('Running'); | ||
| ``` | ||
|
|
||
| Set `data-test-subj` on `<EuiTable>`. EUI spreads it onto the `<table>`, which the component-type guard verifies. | ||
|
|
||
| ## API | ||
|
|
||
| | Member | Description | | ||
| |---|---| | ||
| | `rows` | `Locator` for the body rows. | | ||
| | `headerCells` | `Locator` for the header cells, in column order, including a selection checkbox cell. | | ||
| | `column(index)` | `Locator` for one column's cells across all body rows, by 0-based position. | | ||
| | `cell(row, column)` | `Locator` for one body cell, by 0-based row and column position. | | ||
|
|
||
| Columns are addressed by position because a plain `EuiTable` has no field names. `column` and `cell` match direct children of a row only, both `<td>` and `<th>` since EUI renders a row header cell as `<th scope="row">`. | ||
|
|
||
| ## Deliberately excluded | ||
|
|
||
| Sorting, selection and pagination are not covered. Sorting and selection are consumer wiring on a plain table, and pagination is a separate component. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| /** | ||
| * Stable selectors for | ||
| * {@link https://eui.elastic.co/docs/components/tabular-content/tables/|EuiTable}. | ||
| * `*_SELECTOR` values are CSS. | ||
| */ | ||
| export const EuiTableSelectors = { | ||
| /** The `<table>` element carrying the consumer's `data-test-subj`. */ | ||
| ROOT_SELECTOR: '.euiTable', | ||
|
|
||
| /** A body row. Also matches EUI's own empty/error message row, callers must exclude those. */ | ||
| ROW_SELECTOR: '.euiTableRow', | ||
|
|
||
| /** A body cell. */ | ||
| ROW_CELL_SELECTOR: '.euiTableRowCell', | ||
|
|
||
| /** A header cell, including the selection checkbox cell which has its own class. */ | ||
| HEADER_CELL_SELECTOR: 'thead > tr > :is(th, td)', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/test-helpers/src/playwright/components/table/object.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| import { EuiTableObject } from './object'; | ||
| import { storyUrl } from '../../../storybook'; | ||
|
|
||
| /** | ||
| * Validates `EuiTableObject` against the live component in EUI Storybook. | ||
| * The Playground story renders 3 header cells, 20 body rows and a footer row. | ||
| * `data-test-subj` is injected via Storybook's `args` URL parameter onto | ||
| * the `<table>`. | ||
| */ | ||
|
|
||
| const TEST_SUBJ = 'testTable'; | ||
|
|
||
| const PLAYGROUND_URL = storyUrl( | ||
| 'tabular-content-euitable-euitable--playground', | ||
| `data-test-subj:${TEST_SUBJ}` | ||
| ); | ||
|
|
||
| test.describe('EuiTableObject', () => { | ||
| let table: EuiTableObject; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(PLAYGROUND_URL); | ||
| table = new EuiTableObject(page, TEST_SUBJ); | ||
| await table.locator.waitFor({ state: 'visible' }); | ||
| }); | ||
|
|
||
| test.describe('rows', () => { | ||
| test('exposes the body rows only, not the header or footer row', async () => { | ||
| await expect(table.rows).toHaveCount(20); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('headerCells', () => { | ||
| test('exposes the header cells in column order', async () => { | ||
| await expect(table.headerCells).toHaveCount(3); | ||
| await expect(table.headerCells.first()).toHaveText('Column 1'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('column', () => { | ||
| test('reads one column across every row', async () => { | ||
| const column = table.column(1); | ||
|
|
||
| await expect(column).toHaveCount(20); | ||
| await expect(column.first()).toHaveText('Row 1, Cell 2'); | ||
| await expect(column.last()).toHaveText('Row 20, Cell 2'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('cell', () => { | ||
| test('reads one cell by row and column position', async () => { | ||
| await expect(table.cell(2, 0)).toHaveText('Row 3, Cell 1'); | ||
| }); | ||
| }); | ||
| }); |
57 changes: 57 additions & 0 deletions
57
packages/test-helpers/src/playwright/components/table/object.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import type { Locator } from '@playwright/test'; | ||
|
|
||
| import { BaseObject, type ObjectScope } from '../../base_object'; | ||
| import { EuiTableSelectors } from '../../../components/table/selectors'; | ||
|
|
||
| /** | ||
| * Playwright Component Object for {@link | ||
| * https://eui.elastic.co/docs/components/tabular-content/tables/ EuiTable}, | ||
| * the low level table built from `EuiTableHeader`, `EuiTableRow` and | ||
| * `EuiTableRowCell`. `EuiBasicTableObject` extends this for the | ||
| * `EuiBasicTable` and `EuiInMemoryTable` wrappers. | ||
| * | ||
| * `testSubj` must be set on `EuiTable` itself, EUI spreads it onto the | ||
| * `<table>`. Columns are addressed by position since a plain table has no | ||
| * field names. | ||
| */ | ||
| export class EuiTableObject extends BaseObject { | ||
| constructor( | ||
| scope: ObjectScope, | ||
| testSubj: string, | ||
| componentSelector = EuiTableSelectors.ROOT_SELECTOR | ||
| ) { | ||
| super(scope, testSubj, componentSelector); | ||
| } | ||
|
|
||
| /** The body rows. */ | ||
| public get rows(): Locator { | ||
| return this.root.locator(EuiTableSelectors.ROW_SELECTOR); | ||
| } | ||
|
|
||
| /** The header cells, in column order. */ | ||
| public get headerCells(): Locator { | ||
| return this.root.locator(EuiTableSelectors.HEADER_CELL_SELECTOR); | ||
| } | ||
|
|
||
| /** | ||
| * The cells of one column across all body rows, by 0-based position. | ||
| * Direct children only, so a table nested in a cell is not matched. Matches | ||
| * both `<td>` and `<th>`, EUI renders a row header cell as `<th scope="row">`. | ||
| */ | ||
| public column(index: number): Locator { | ||
| return this.rows.locator(`> :is(td, th):nth-child(${index + 1})`); | ||
| } | ||
|
|
||
| /** One body cell by 0-based row and column position. */ | ||
| public cell(row: number, column: number): Locator { | ||
| return this.rows.nth(row).locator(`> :is(td, th):nth-child(${column + 1})`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.