test.only(`Default page Group codes table `, async ({
page, screen, within
}) => {
const table = await screen.queryByTestId('nested-table-GroupCode')
const tableHeader = within(table).getAllByRole('columnheader')
expect(await tableHeader.nth(0).textContent()).toEqual("Active")
expect(await tableHeader.nth(1).textContent()).toEqual("Code")
expect(await tableHeader.nth(2).textContent()).toEqual("Description")
//using playwright locator to find the total no of rows /<tbody> </tbody> tag returns 1 when there are no rows.
let total;
total = await page.locator('table[data-testid=nested-table-GroupCode] tbody').count();
console.log("total" + total).
// letting the loop run only if total is not equal to 1
if(total != 1){
const rowgroup = within(table).getAllByRole('rowgroup')
let totalRows = await within(rowgroup.nth(1)).getAllByRole('row')
console.log("total Rows" + totalRows )
let noOfRows = await within(rowgroup.nth(1)).getAllByRole('row').count(). ---> This line is failing when there are no rows, as count returns nothing.
console.log("No of Rows " + noOfRows);
for (let i = 0; i < noOfRows; i++) {
let cellValues = await within(totalRows.nth(i)).getAllByRole('cell')
let noOfCells = await within(totalRows.nth(i)).getAllByRole('cell').count()
console.log("No of cells " + noOfCells);
for (let j = 0; j < noOfCells; j++) {
await expect(cellValues.nth(j)).not.toBeNull();
console.log("cellValue: " + await cellValues.nth(j).textContent());
}
}}
});
here is the code:
is there a direct way to verify using playwright testing library to verify if the table has no rows other than table header?