I'm doing a test and I put a value in a texfield. If I get some data I want it to be found, otherwise I want "no data" to be found. This code doesn't work... Why? And how can I do it?
it('Test on filter', function () {
const valueInserted = 'VALUE';
cy.get('#autorouter-patname').type(valueInserted);
cy.get('button[type="submit"]'.click();
cy.get('tbody>tr>td')
.then(($el) => {
if (cy.get($el).contains('No data available')) {
return cy.contains('No data available')
} else {
return cy.get($el).eq(2).contains(valueInserted);
}
})
})
.contains
doesn't return a boolean, if no element is found an error is thrown. Try getting the text as shown in e.g. docs.cypress.io/faq/questions/….