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

307
Views
How to add query param in Cypress (JS)

I have to ask for help here. I'm still learning Cypress and trying to add query param to each URL and validate that some modal appears on the page when query param is added. So the way it looks:

urls = [ "/en/link1/", "/en/link2/", "/en/link3/", ]

queryParam = [ "?param1", "?param2", "?param3", ]

I need to write code that would do for me

  • /en/link1/?param1
  • /en/link2/?param1
  • /en/link3/?param1
  • checkCondition()
  • /en/link1/?param2
  • /en/link2/?param2
  • /en/link3/?param2
  • checkCondition()

and so on...

Could you please advise me how to do this? I'd rly appreciate any advice/link to material. Thanks a lot and happy coding!

SOLUTION (kudos to @Alapan Das)

describe("My test", () => {
  urls.forEach(url => {
    params.forEach(param => {
      it(`should check smthng`, () => {
        cy.visit(url + param)
        cy.checkCondition()
      })
    })
  })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use cy.request version taking options as argument: https://docs.cypress.io/api/commands/request#Options

cy.request({
  url: "/en/link1",
  qs: {
    "param2": "test"
 }
})
about 4 years ago · Juan Pablo Isaza Report

0

You can use nested ForEach Loops to iterate over both arrays and make the combinations like this:

const urls = ['/en/link1/', '/en/link2/', '/en/link3/']

const params = ['?param1', '?param2', '?param3']

urls.forEach((url) => {
  params.forEach((param) => {
    console.log(url + param)
  })
  checkCondition()
})

Upon execution:

Console Execution of js snippet

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!