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

223
Vistas
Cypress rompe el foreach exterior desde el interior y luego

Quiero romper mi bucle más externo desde el interior de un bucle. Intenté devolver falso pero no funciona. El siguiente es mi fragmento de código:

 cy.get('abc').each(($elm) => { if ($elm.text() == 'xyz') { cy.get('pqr').click().then(() => { if (cy.get('dgf').text() == "sdasd") { expect(value1).to.be.equal(value2) return false // I want to stop the outermost for each loop //But even with return false it does not breaks the forEach } }) } })
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

En lugar de usar if (cy.get('dgf').text() == "sdasd") use if ($('selector').text() == 'sdasd')

 cy.get('abc').each(($elm) => { if ($elm.text() == 'xyz') { $('pqr').click() if ($('dgf').text() == 'sdasd') { expect(value1).to.be.equal(value2) } return false } })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Intente usar una bandera, vi en alguna parte que salir de .each() necesita un valor de return incondicional (es decir, no dentro de if() )

 cy.get('abc').each(($elm) => { let continue = true; if ($elm.text() == 'xyz') { cy.get('pqr').click() cy.get('dgf') // NO cy.get() in if() .invoke('text') .then(dgfText => { if (dgfText === "sdasd") { expect(value1).to.be.equal(value2) continue = false } }) }) } return continue; // true will keep going, false will break out })

Sospecho que eso no lo va a hacer aunque. Tal vez una reestructuración para eliminar el .each()

 cy.get('abc') .filter((index, el) => el.innerText === 'sdasd') // instead of each() and if() .then(() => { cy.get('pqr').click() cy.get('dgf') // NO cy.get() in if() .invoke('text') .then(dgfText => { if (dgfText === "sdasd") { expect(value1).to.be.equal(value2) } }) }) })
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