Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Login() a second time does not work #74

Open
Mushoz opened this issue Dec 12, 2022 · 1 comment
Open

Calling Login() a second time does not work #74

Mushoz opened this issue Dec 12, 2022 · 1 comment

Comments

@Mushoz
Copy link

Mushoz commented Dec 12, 2022

Whenever I call Login() a second time on a different user, it does not login as expected. Calling login() a second time on the same user works just as expected. Why is this small test case not logging in as expected?

describe('empty spec', () => {

  beforeEach(function () {

    cy.create({model: 'App\\Models\\User', state: {'representative':[],}}).as('regularUser1')
    cy.create({model: 'App\\Models\\User', state: {'representative':[],}}).as('regularUser2')

  });

  it('Example Test Case', function () {
    cy.visit('/')
    cy.login({id:this.regularUser1.id})
    cy.visit('/')
    cy.url().should('contain', '/dashboard') // this works
    cy.logout()
    cy.visit('/')
    cy.login({id:this.regularUser2.id})
    cy.visit('/')
    cy.url().should('contain', '/dashboard') // this fails, will be redirected to the login page instead
  })
})
@Mushoz
Copy link
Author

Mushoz commented Dec 12, 2022

Okay, so clearing cookies between the login calls seem to work, but this is pretty cumbersome having to do this every time. Is there any way around this? Working example below:

describe('empty spec', () => {

  beforeEach(function () {

    cy.create({model: 'App\\Models\\User', state: {'representative':[],}}).as('regularUser1')
    cy.create({model: 'App\\Models\\User', state: {'representative':[],}}).as('regularUser2')

  });

  it('Example Test Case', function () {
    cy.visit('/')
    cy.log(this.regularUser1.id)
    cy.login({id:this.regularUser1.id})
    cy.visit('/')
    cy.url().should('contain', '/dashboard') // this works
    cy.logout()
    cy.visit('/')
    cy.clearCookies().then(function () {
        cy.login({id:this.regularUser2.id})
        cy.visit('/')
        cy.url().should('contain', '/dashboard') // This works as well now!
    })
    
  })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant