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

126
Views
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 answers
Answer question

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 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!