-2

I have the code below. I want to set a flag on true when it passes throw if block (see screenshot). However, in the end, it is false. I see in the log, that found = true is executed before cy.log("FOUND = " + found). What is wrong?

it('Check shopping', function() {        
    cy.visit(Cypress.env('url') + first_product_end_point)
    let found = false
    cy.get('tbody tr').each(($el, index, $list) => { 
        cy.log("INDEX = " + index)
        this.sum = 0;
        if(index > 0 && index < $list.length - 1){
            cy.wrap($el).find("td:nth-child(3)").then(function(data) {
                if(data.text().includes("Female Puppy")){
                    cy.wrap($el).find("td:nth-child(4)").then(function(data) {
                        this.sum = this.sum + parseFloat(data.text())
                        cy.log("SUM = " + this.sum)
                    })
                    cy.wrap($el).find("td:nth-child(5)").find('.Button').click()
                    found = true
                    cy.log("Found inside = " + found)
                }
            })
        }
        cy.log("FOUND = " + found)
    })

Code

This is a log:

enter image description here

0 Answers0