Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda