Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Condición de parada de bucle foreach de Cypress

Necesito ayuda con el siguiente bucle:

 localStorage.removeItem('DDFound'); cy.get(sel).each(($el, index, $list) => { if(localStorage.getItem('DDFound')!='1') { cy.log(localStorage.getItem('DDFound')); cy.wrap($el).click().then(()=> { cy.get(table).then(elx => { if(elx.find(tableitem).length > 0) { cy.get(tableitem).click(); cy.get(lable).should('contain.text',"Item") localStorage.setItem('DDFound','1'); } }) }); } });

Me gustaría romper justo después de encontrar el elemento correcto (tableitem) y para eso, estoy configurando un almacenamiento local (no encontré ninguna otra manera) pero parece que Cypress ejecuta todos los elementos en cada ciclo en paralelo y no llega a el if(localStorage.getItem('DDFound')!='1') después de cada elemento.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si tiene un código complejo dentro de .each() , debe envolverlo en una promesa

 let found = false; cy.get(sel).each(($el, index, $list) => { if (found) return false; // early exit return new Cypress.Promise(resolve => { cy.wrap($el).click().then(() => { cy.get(table).then(elx => { if (elx.find(tableitem).length > 0) { cy.get(tableitem).click(); cy.get(label).should('contain.text',"Item") found = true; } resolve() // wait for above to complete }) }) }) })

Ver .each() - Promesas

Se esperan promesas

Si su función de devolución de llamada devuelve una Promesa, se esperará antes de iterar sobre el siguiente elemento de la colección.

about 4 years ago · Juan Pablo Isaza Report

0

Puede detener el bucle .each() antes devolviendo falso en la función de devolución de llamada. En su caso, podemos devolver el valor si DDItem no es igual a uno.

 localStorage.removeItem('DDFound'); cy.get(sel).each(($el, index, $list) => { if(localStorage.getItem('DDFound')!='1') { cy.log(localStorage.getItem('DDFound')); cy.wrap($el).click().then(()=> { cy.get(table).then(elx => { if(elx.find(tableitem).length > 0) { cy.get(tableitem).click(); cy.get(lable).should('contain.text',"Item") localStorage.setItem('DDFound','1'); } }) }); } return localStorage.getItem('DDFound') !== 1 });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!