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

172
Views
¿Cómo verificar muchas URL en una prueba?

Tengo una lista de direcciones URL y necesito verificar el mismo elemento en cada una de ellas. Pero hay 2 condiciones:

  1. todo debe hacerse en 1 it()
  2. la prueba no debe fallar después de la primera URL incorrecta, pero debe verificarlas todas y mostrar el resultado solo después de que finalice la lista

Traté de hacerlo por loop y try-catch (porque no hay una afirmación suave por defecto), pero luego la prueba siempre se pasó, incluso cuando el texto del elemento era incorrecto (según entiendo, se debe a la asincronía).

 let errorUrls = [] for (let url in data.PRODUCTS_PAGES) { cy.visit(url) cy.get('div.configurator-controls span').invoke('text') .then(text => { try { expect(text).to.equal(data.PRODUCTS_PAGES[url]) } catch (e) { errorUrls.push(e.message) } }) } expect(errorUrls).to.be.empty

¿Cómo puedo hacer esto?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puedes hacer algo como esto:

 let errorUrls = [] for (let url in data.PRODUCTS_PAGES) { cy.visit(data.PRODUCTS_PAGES[url]) cy.get('div.configurator-controls span').then(($ele) => { if ($ele.text() == data.PRODUCTS_PAGES[url]) { expect($ele.text()).to.equal(data.PRODUCTS_PAGES[url]) } else { errorUrls.push(data.PRODUCTS_PAGES[url]) } }) } cy.then(() => { expect(errorUrls).to.be.empty })
about 4 years ago · Santiago Trujillo Report

0

Si no quiere fallar, no use expect() en el bucle.

Tenga en cuenta que todas las URL deben tener el mismo origen.

 let errorUrls = [] for (let url in data.PRODUCTS_PAGES) { cy.visit(data.PRODUCTS_PAGES[url]) cy.get('div.configurator-controls span').invoke('text') .then(text => { if (text !== data.PRODUCTS_PAGES[url]) { errorUrls.push(e.message) } }) } cy.then(() => { cy.log(errorUrls) expect(errorUrls).to.have.length(0) })
about 4 years ago · Santiago Trujillo 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!