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

Unexpected behaviour of shared context between suites with testIsolation: true #27331

Closed
Revadike opened this issue Jul 19, 2023 · 2 comments
Closed

Comments

@Revadike
Copy link

Revadike commented Jul 19, 2023

Current behavior

With test isolation enabled, the browser session is not cleared between it-tests.

Desired behavior

With test isolation enabled, clear the browser session between it-tests.

Test code to reproduce

This issue persists across devices (both used Ubuntu). So, I suspect this may be an OS or cypress version specific issue. If you want to try to reproduce on Windows, try WSL. That is what I used on my Windows machine to run Ubuntu. I also have a native Ubuntu OS machine, where this issue also persist. Sadly, I could not test it on Windows itself, because I had an unrelated issue there installing and setting up cypress.

I have a Nuxt2 website with a simple email/password login (auth via Firebase). I use the following config:
cypress.config.js

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    baseUrl: <hidden>,
    watchForFileChanges: false,
    testIsolation: true,
    defaultCommandTimeout: 12000,
  },
});

I have 2 simple test in a single file spec.cy.js:

describe('My test suite', () => {
  beforeEach(() => {
    cy.visit('/logout/') // <-- my workaround
    // cy.clearAllCookies() // <-- this does not work
    // cy.clearAllLocalStorage() // <-- this does not work
    // cy.clearAllSessionStorage() // <-- this does not work
    cy.contains('Welcome').should('be.visible') // <- wait for /logout visit to complete
  })

  it('tests email/pass login', () => {
    cy.visit('/login')
    cy.get('input[name=email]').type('example@domain.com')
    cy.get('input[name=password]').type('password')
    cy.get('button[type=submit]').click()
    cy.url().should('include', '/dashboard') // logged in
  })

  it('tests password forgot', () => {
    cy.visit('/login') // <-- ERROR redirects to /dashboard, still logged in!!! (when not using my workaround)
    cy.get('a[href="/forgot"]').click()
    cy.url().should('include', '/forgot')
  })
})

I've added comments to clarify some stuff. As you can see, the only workaround I found to work, is to manually logout... This is far from desirable, as I'd like my tests to run in isolation naturally.

Cypress Version

12.17.1

Node version

v18.16.1 (I also tried 16)

Operating System

Ubuntu 22.04.2 LTS (64 bit)

Debug Logs

No response

Other

I have also reported this in the Discord server with little help. But if you'd like to chat, I'm available there.

I copied the title of a different issue with 1 key difference, so hopefully it's easier for people to tell them apart.

@Revadike
Copy link
Author

@Revadike
Copy link
Author

Revadike commented Jul 24, 2023

OK, I figured out the underlying issue. Because my website uses Firebase auth, the session is stored in indexedDB, which for some odd reason is not cleared between tests...

There is a longstanding issue about this problem: #1208
Hopefully, this will be solved in the near future!

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

2 participants