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

128
Vistas
Login with multiple users in same test using json

I want to test the login using multiple users in a single test rather than logging in with one then logging out and then moving to a duplicate test and using different users.

This is the JSON i will be using to fetch data

[
    {
      "id": "standard User",
      "username": "standard_user",
      "password": "secret_sauce"
    },
    {
      "id": "locked out user",
      "username": "locked_out_user",
      "isComplete": "secret_sauce"
    },
    {
      "id": "Problem user",
      "username": "problem_user",
      "password": "secret_sauce"
    },
    {
      "id": "perfromance glitch user",
      "username": "performance_glitch_user",
      "password": "secret_sauce"
    },
    {
        "id": "Invalid User",
        "username": "perform",
        "password": "secret12"
      }
]

And below is the script

it('Login with multple users', () => {
        
        //Logging in with the first User.
        cy.visit('/')
        cy.get('[data-test="username"]').type(user[0].username)
        cy.get('[data-test="password"]').type(user[0].password)
        cy.get('[data-test="login-button"]').click()
        cy.url('https://www.saucedemo.com/inventory.html')
        // Logging in with the second User.
        cy.visit('/')
        cy.get('[data-test="username"]').type(user[1].username)
        cy.get('[data-test="password"]').type(user[1].password)
        cy.get('[data-test="login-button"]').click()
        cy.get('[data-test="error"]').should('have.text', 'Epic sadface: Sorry, this user has been locked out.')
    });
    
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do something like this:

it('Login with multiple users', () => {
  cy.readFile('cypress/fixtures/users.json').then((users) => {
    users.forEach((user) => {
      cy.visit('/')
      cy.get('[data-test="username"]').type(user.username)
      cy.get('[data-test="password"]').type(user.password)
      cy.get('[data-test="login-button"]').click()
      cy.url('https://www.saucedemo.com/inventory.html')
      cy.get('[data-test="error"]').should(
        'have.text',
        'Epic sadface: Sorry, this user has been locked out.'
      )
    })
  })
})

Also in your JSON, in the second entry there is no password field instead there is isComplete.

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