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

135
Views
Cypress function call with several options
Cypress.Commands.add('Login', (env,username) => {
        env(staging) = cy.visit('LINK') 
        env(live) = cy.visit('LINK') 
        username(practitioner1) = {
            cy.get('input[name="Parameter.UserName"]').type('practitioner1')
            cy.get('input[name="Parameter.Password"]').type('pass')
        }

    cy.contains('Login').click()
  })

I don't know why i have ',' expected ts(1005) error

I want to call from another file something like cy.Login(staging,practitioner1) , or cy.Login(live,practitioner2) so that I don't have to hard code the link, username and password every time. Here is a prinscreen with errors: pasteboard.co/0bYOL4Dx7mnE.png

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I would suggest the following:

Cypress.Commands.add('login', (env, user) => {
    const practitionerUser1 = { username: 'foo', password: 'myPasswordFoo#'};
    const practitionerUser2 = { username: 'zoo', password: 'myPasswordZoo#'};

    env = 'staging' ? cy.visit('staging_link') : cy.visit('production_link')


    user = 'practitionerUser1'
        ? (cy.get('input[name="email"]').type(practitionerUser1.username),
          cy.get('input[name="password"]').type(practitionerUser1.password))
        : (cy.get('input[name="email"]').type(practitionerUser2.username),
          cy.get('input[name="password"]').type(practitionerUser2.password));

    cy.contains('login').click()
});

and use it in your tests like:

cy.login('staging', 'practitionerUser1');

P.S. Because the above command interacts with the UI, for performance reasons I would suggest for actions like login to use api requests. It is more robust and reliable over time ;)

about 4 years ago · Juan Pablo Isaza Report

0

  1. Go to your cypress.json and add all your links there.
{
  //Other cypress.json elements
  "env": {
    "staging": "www.staging.com",
    "live": "www.live.com"
  }
}
  1. In your support/commands.js add the custom command
Cypress.Commands.add('Login', (environment, username, password) => {
  cy.visit(Cypress.env(environment))
  cy.get('input[name="Parameter.UserName"]').type(username)
  cy.get('input[name="Parameter.Password"]').type(password)
  cy.contains('Login').click()
})
  1. In your test write:
cy.Login('staging', 'username', 'password')
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!