0
votes

I've been trying to break loop if my else condition runs but it kept running. I tried return false, and only return as well. I tried returning false at different position but it still kept running.

  cy.get('.product-col').each(
    $product=>
    {
    
    if (a){
        console.log("value  to break before everything starts loop "+a)
       return }
       cy.wrap($product).wait(2050).within(()=>{
        // if (a){
        //     console.log("value  to break before within "+a)
        //    return false}
        cy.contains('Coming Soon').each($visible=>{
           
            if ($visible.is(':visible')) {
                cy.contains('Coming Soon').should('be.visible')
                
            } else {
                console.log('else is running')
                cy.contains('Coming Soon').should('not.be.visible').parentsUntil('.col-md-4').last().click()
               a=true
               return
               
            //    console.log("value before loop "+a)
        
            }
            // if (a){
            //         console.log("value after visibility loop "+a)
            //        return }
        })
        //  console.log("value after visibility loop loop "+a)
        // if (a){
        //     console.log("value after within loop "+a)
        //    return }
    })
    if (a){
        console.log("value  to break loop after within "+a)
       return false;}
      
 
   })