This thread is trying to answer question "What is the best way to validate that a row in a table has cells of certain values from left to right?"
You can pass an array to the toContainText()
assertion. There's an explanation and examples here: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-contain-text
For table cells, I use a pattern like the following. You don't have to use fixtures and could use the relevant locator in the test.
// In the constructor for a fixture:
this.rows = this.tableContainer.locator('tbody').getByRole('row');
// A convenience method in the fixture:
getRowValues(rowIndex: number) {
return this.rows.nth(rowIndex).getByRole('cell');
}
// Assertion in a test:
expect(getRowValues(2)).toContainText(['value 1', 'value 2']);
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].