A part of my test includes a table where user's can add or delete rows.
I cannot control if the table will be empty or not, so I need to have conditionals if
to find out if the table is empty or not.
I try to check if the first row of the table exists. If it does, do some tests and proceed, or if it doesn't just skip the table and proceed.
Of course, I can't just try to do a cy.get on the first row, because if it doesn't find the element it will fail the test.
Instead I tried this:
cy.get('body').then(($body) => {
if ($body.find('firstRowElement').length > 0, {timeout: 60000}) {
cy.log("Im Inside")
cy.get('firstRowElement').then(($grid) => {
//Do all the tests I need if the first row exists..
)}
}
)}
But it does not work.
When the table is empty it still enters the if statement.
Then the test fails on the next line because of the cy.get()
on an element that does not exist. It seems that the if
statement is not working.
Timeout
I need the timeout because the table takes a few seconds to load.
I tried moving the timeout to inside the $body.find()
but it simply doesn't wait and skips everything because the table wasn't loaded yet.
I also don't want to use cy.wait()
.
I believe that there is some sort of conflict between .find()
and timeout.