Description
This is related to issue --> how to read table header and do assertion? #511
I have few other tables on the UI to verify the headers, all th rows data test id starts with cl-table-header-column , which means when i run my tests the test assertion will fail as it will locate multiple tables, which is why i want to filter by table name await this.screen.findAllByTestId('table-header-GroupCode') and verify the header. Please let me know if there is a way.
Can you please advise me if there is any other way to verify the headers of all the tables without erroring out? as cl-table-header-column is the start of the test id in all the tables.
Attached is the screenshot.
Code that is suggested in the ticket #511
This is for Group code table:
test('should handle the findAllBy* methods with test ID RegExp', async ({screen}) => {
const header = await screen.findAllByTestId(/cl-table-header-column.*/, undefined, {
timeout: 3000,
})
await expect(header.nth(0)).toHaveText('Active')
})
Schedule period table is attached below:
Playwright test code that i have currently working:
SchedulePeriodHeader : 'tr[data-testid='table-header-SchedulePeriod'] th span',
async VerifySchedulePeriodHeader(index, text) {
return await this.verifyElementContainsText(SchedulePeriodHeader, index, text)
}
async verifyElementContainsText(selector, index, text) {
await this.page.waitForSelector(selector);
return await expect(this.page.locator(selector).nth(index)).toContainText(text);
}
How the same can be achieved using playwright testing library with the tr[data-testid='table-header-GroupCode'] th span?
After finding using findByTestId--> [data-testid='table-header-GroupCode'] , Can we traverse to "th" or "span" element using playwright testing library? Can you please advise?