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

198
Views
Cypress - calling a function with parameters

I want to create a function in cypress in which I can call as appropriate the environment on which to login and username. For example I want to append cy.login (live, username1)

I don't know exactly how to write to be correct in the code

 Cypress.Commands.add('Login', (env,username) => {
        env(staging) = cy.visit('https://staginglink') 
        env(live) = cy.visit('https://livelink') 
        username(username1) = {
            cy.get('input[name="Parameter.UserName"]').type('username1')
            cy.get('input[name="Parameter.Password"]').type('password1')
        }
            cy.contains('Login').click()
  })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So your custom command will be like:

Cypress.Commands.add('Login', (env, username) => {
  cy.visit(env)
  cy.get('input[name="Parameter.UserName"]').type(username)
  cy.get('input[name="Parameter.Password"]').type('password1')
  cy.contains('Login').click()
})

Then in your test you can just write:

cy.Login('https://staginglink','someusername1')
cy.Login('https://livelink','someusername2')
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!