testing-library / playwright-testing-library

🔍 Find elements in Playwright with queries from Testing Library
MIT License
248 stars 9 forks source link

Even after using RegexParser, getByRole('row', {name: name }) still fails, #556

Closed InduKrish closed 2 years ago

InduKrish commented 2 years ago

Even after using RegexParser, it still fails, https://nesin.io/blog/convert-regex-string-javascript. -- followed the steps

Related to #552

groupCodes.json [ { "code":"03", "description" : "/NEW HIRE/" } ]

const groupCode =  JSON.parse(JSON.stringify(require("../../data/groupCodes.json")));

const RegexParser = require('regex-parser');

   groupCode.forEach(data =>
    {
        test.only(`Group codes table with ${data.description}`, async ({
                                                                          page, screen, within
                                                                      }) => {
            const table = await screen.findByTestId('nested-table-GroupCode')
            const row = within(table).getByRole('row', {name: /NEW HIRE/})
            const cell = within(row).getAllByRole('cell')
            const activeStatus = await cell.nth(0).textContent();

            console.log("Status is :" + activeStatus);

            console.log("DATA :" + data.description);

           //  const config = JSON.parse('{"description" : "/NEW HIRE/"}'); 
          //  await checkRow(screen, RegexParser(config.description));  --> --> 1.added json string manually and tried,

           console.log("Regexp" + RegexParser(data.description)) ===> this is the output /NEW HIRE/, screenshot attached, still fails. 

            await checkRow(screen, RegexParser(data.description));  ---> 2. tried calling the helper method and still fails as well.

            await page.waitForTimeout(3000);
            if (activeStatus == 'minus-circle') {
                expect(await cell.nth(0).textContent()).toEqual("success")
            } else {
                expect(await cell.nth(0).textContent()).toEqual("minus-circle")
            }

        });
    });
export async function checkRoow(screen, name) {

    const edit = await screen.findByTestId("Edit Aircraft Positions");
    await edit.click();
    // const editTable = await screen.findByTestId('editable-nested-table-AircraftPosition')
    // const editRow = within(editTable).getByRole('row', {name: /737/})
    // const checkbox = within(editRow).getByRole('cell', {name: /check/})

    const checkbox = await screen.queryByTestId('editable-nested-table-AircraftPosition')
        // .within().getByRole('row', {name: /NEW HIRE/}).
        .within().getByRole('row', {name: name }).
        within().getByRole('cell', {name: /check/});

    await checkbox.click();

    const save = await screen.findByTestId("button-text-save-AircraftPosition");
    await save.click();
}
Screen Shot 2022-10-06 at 11 13 44 PM Screen Shot 2022-10-07 at 9 24 25 AM
InduKrish commented 2 years ago

I've got this working. This can be closed. const checkbox = await screen.queryByTestId('editable-nested-table-GroupCode') .within().getByRole('row', {name: RegexParser(config.description) }). within().getByRole('cell', {name: /check/});