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

112
Views
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 answers
Answer question

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 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!