Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda