Hey guys i have a table that consist of some rows and columns where one of the columns can be empty so i want to exclude it somehow.
Currently i am checking like this which looks like there is to much not needed writings
cy.get('tr td.cdk-cell.amount.cdk-column-Amount').each(($column) => {
expect($column).to.not.be.empty
})
cy.get('tr td.cdk-cell.cryptocurrency.cdk-column-BTC').each(($column) => {
expect($column).to.not.be.empty
})
cy.get('tr td.cdk-cell.status.cdk-column-Status').each(($column) => {
expect($column).to.not.be.empty
})
I cannot do the following since one of the columns always empty
cy.get('tbody[role="rowgroup"] tr td').each(($ele) => {
expect($ele.text().trim().length).to.be.at.least(1)
})
So my question is how to ignore 1 column and check if all others have value present
Break down the selectors a bit, use .each() over the rows because it's per-row test (I presume that is correct?).
Inside the row, get the isEmpty result of all the columns you are interested in.
Them combine the isEmpty variables into one result you can test.
cy.get('tbody[role="rowgroup"] tr').each(($tr, rowIndex) => {
const amountCol = $tr.find('td.cdk-cell.amount.cdk-column-Amount');
const cryptoCol = $tr.find('td.cdk-cell.cryptocurrency.cdk-column-BTC');
const statusCol = $tr.find('td.cdk-cell.status.cdk-column-Status');
const amountIsEmpty = amountCol.is(':empty') // result is true/false
const cryptoIsEmpty = cryptoCol.is(':empty')
const statusIsEmpty = statusCol.is(':empty')
const allAreEmpty = amountIsEmpty && cryptoIsEmpty && statusIsEmpty;
if (allAreEmpty) {
throw new Error(`Row ${rowIndex} has all three columns empty`)
}
// or
expect(allAreEmpty).to.eq(false);
})