I am writing a Cypress test on a quiz page with a random # of pages. I am trying to write a condition in Cypress that will allow me to click on a "SUBMIT" page link if it is the last page, else it will click on a "NEXT" link if it is not the last page.
I have tried using cypress commands such as .contains() and .find() which does not seem to return a pass/fail response. I have also tried various if statements, but when I use these, I end up using cypress commands that either pass or fail, but do not route to any alternate conditional else.
//Clicks on submit successfully or fails the test. Never hits the else clause if not the last page.
if (cy.find("button[data-cy=submitBtn]").length > 0)
{
// SUBMIT button exists
cy.get('[data-cy=submitBtn]')
.click()
}
Expected result will hit the else if the condition is met and trigger the command.