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

113
Visualizações
How to run same test for different URLs in Cypress

I have around 7 test files and in total 60 test cases that needs to be run for 2 URLs.

Way 1 is: loop on each test - so each test will run for 2 URLs and URL I am passing as argument. But that requires forEach in each test.

Way 2: I tried opening URL in beforeEach() like below:

describe('Your Finance Page tests', () => {
  beforeEach(() => {
    brands.forEach(function (brand) {
      openUrl(brand)
    });
  });

It is opening brand for each test but running test for 1 brand only. Like before each test it opens brand A, then brand B and run test on brand B only.

Is there any better way to do this other than writing forEach in each test?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The for-loop will probably work if it's external to the beforeEach() and the it() blocks.

This article Dynamic Tests From Cypress Fixture describes the pattern in detail.

const brandUrls = [...]

describe('Test each brand', () => {

  brandUrls.forEach(brandUrl => {

    beforeEach(() => {
      cy.visit(brandUrl)
    })

    it(`tests url ${brandUrl}`, () => {
      ...
    })
  })
})

Note, your brands must be either hard-coded or read from a fixture using require() or import at the top of the spec.

As for applying it to multiples specs, yes add it to each spec (for simplicity).


cypress-each package

The cypress-each package does something similar, but has expanded capabilities.

import 'cypress-each'

// create a separate test for each brand
const brands = [...]

it.each(brands)('test %s brand, (brand) => {
  cy.visit(brand)
  ...  // assertions
})
about 4 years ago · Juan Pablo Isaza 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