vendredi 21 février 2020

Why does control not move to the Else loop even though the If loop condition fails in the cypress automation testing tool?

I am starting out with cypress automation testing tool. What I am trying to accomplish:

if the page contains "there are no results" then "mark as certified" button should not exist. else if the page does not contain "there are no results" then click the select all button."mark as certified" button should exist.

here is the code that I have so far:

cy.get('body').then($body=> {
        if ($body.find('There are no results')) {
            //cy.get('.hZDZBR > .Typography__StyledTypography-sc-153d8g4-0');
            cy.get('Mark as Certified').should('not.exist');
        }
        else {
            cy.get('input[id="selectAll"]').click();
            cy.get('.hZDZBR > .Typography__StyledTypography-sc-153d8g4-0').contains('Mark as Certified');
            cy.get('.hZDZBR').click();

        }
    })

What cypress does right now is: It enters the if loop, executes it and says "mark as certified" not found. But my question is, if "there are no results" does not exist on the page, and it does not find it, then why does it even execute the if loop and go into the else loop? So it is executing the if loop as though it finds "mark as certified" but I can see that that doesnt exist on the page.

Help is appreciated thanks!

Aucun commentaire:

Enregistrer un commentaire