Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
How to check many urls in one test?

I have a list of urls and need to check the same element on every of them. But there are 2 conditions:

  1. all must be done in 1 it()
  2. test must not fail after the first wrong url, but must check all of them and show result only after list finishing

I tried to do it by loop and try-catch (because there is not soft asserting by default), but then the test always was passed, even when text from element was wrong (as I undestand it's because of asynchronicing).

    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

How can I do this?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can do something like this:

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 Relatório

0

If you don't want to fail, don't use the expect() in the loop.

Note, all URL's must be same-origin.

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda