Playwright · Middle · Question 13 of 75
How do you test with two different roles in one test, e.g. admin and user?
- 1Log out and log in again on the same page halfway through
- 2Create two browser contexts, each with its own
storageState - 3Run the test twice in two separate projects at once
Show the answer
Correct answer: Create two browser contexts, each with its own storageState
Explanation
Each context is isolated, so browser.newContext({ storageState: 'admin.json' }) and a user context can act side by side, like two people in a chat.