0

Here is my scenario:

testfile1 containing some tests testfile2 containing some tests ... testfileN containing some tests

  1. I log into application in global-setup (using storageState as defined in docs - https://playwright.dev/docs/test-global-setup-teardown#example)
  2. Executing testfile1...testfileN with this logged session
  3. Now I would like to logout user from application after last executed test, however I have tests grouped into few test suites, so need some generic way to logout after last test, can't add logout method just after some specific test.

I tried to use globalTeardown, however I can't find a way to send open page to teardown and execute logout. Is it even possible or should I use some other method for this scenario?

KJ1
  • 13
  • 3

1 Answers1

0

I solved this issue, so in case someone will have similar case:

  • in global setup, I log user and save storage state in json file
  • after executing all tests, global-teardown creates new browser context and use browserContext.addCookies() to insert cookies from saved storage
  • then playwright can operate on given page, so it's possible to logout user via UI
KJ1
  • 13
  • 3