Skip to content

filter by table name to verify the headers names based on table row test ids <tr> instead of header id <th> test ids. #518

Closed as not planned
@InduKrish

Description

@InduKrish

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:

Screen Shot 2022-09-20 at 8 50 08 AM

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);
}

Screen Shot 2022-09-20 at 11 47 59 AM

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions