Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
Break for loop inside promise Then in Cypress Typescript

How to Break 'for' loop inside promise 'Then' in Cypress Typescript as in below code:

for (let i = 2; i <= iterationspage; i++) {
    cy.wait(5000)
    cy.get(".page").contains(i).click()
    cy.log("clicked on page"+i)
    // let FlagFound='False'
    homePage.getProductNamesSearchResults().each(($el, index, $list)=> {
        const expProductName=$el.text()
        if(expProductName.includes(this.addtocart.ProductToBuy)){
            homePage.getAddToCartButton().eq(index).click()
            
            homePage.getPriceTagForSearchedProducts().eq(index).then(function(productPrice){
                cy.log(productPrice.text())
                cy.log(expProductName)
                
            }) 
        
            //break
        }
    })
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In fact you have two loops to break

  • the main for loop where break will stop it
  • the each loop where you can't use break because you are in a callback -> you can use every and return false to stop this loop when condition is meet

let iterationspage = 10;
let data = ['test1','test2','test3','test4']

for (let i = 2; i <= iterationspage; i++) {
      result = data.every(($el, index, $list) => {
        if ($el === 'test3') {
          return false;
        }
        console.log($el);
        return true;
      });
      if (!result) {
        break;
      }
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Cypress.env("lengthProd",12)//page count
    findItem(ProductToFind)
    

function findItem(value: any){
    const homePage= new HomePage()
    const viewCartPopUp= new ViewCartPopUp()
    const shoppingCartPage= new ShoppingCartPage()
    
    
    function findInPage(index1: any){
        
        
        let found=false
        cy.get("div.bottom div div div cx-pagination a.page").its("length").then(len=>{

            if(index1>Cypress.env("lengthProd")){
                return false
            }else{
                cy.wait(5000)
                
                cy.get(".page").contains(index1).click({force:true})
                cy.log("clicked on page"+index1)
                cy.wait(10000)
                homePage.getProductNamesSearchResults().each(($el, index, $list)=> {
                    
                    const expProductName=$el.text()
                   
                    if(expProductName===value){
                        found =true
                        homePage.getAddToCartButton().eq(index).click()
                        homePage.getPriceTagForSearchedProducts().eq(index).then(function(productPrice){
                            cy.log(productPrice.text())
                            cy.log(expProductName)
                        })
                        
                        return false
                    }
                }).then(()=>{
                    if(!found){
                        findInPage(++index1)
                    }
                })
            }
        })
    }
    findInPage(1)
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda