← Back to Discord Forum

Python Documentation For Advanced Scenarios: Multiple Signed in Roles

melon_myceliaposted in #help-playwright
Open in Discord

Hello Playwright Discord! I am testing an application that has several roles all with different access levels. There's great documentation for the Node.js on how to handle multiple roles, but the equivalent documentation is not present for Python. (Here's the Node.js documentation: https://playwright.dev/docs/auth#multiple-signed-in-roles)

I would love some help on how to handle this in Python? I have figured out how to save the logon state/cookies for one Role and reuse it, but I'm not sure what the best way is to store multiple roles. Currently our solution is to have multiple nested conftest.py files that override the default login if we want to test other roles. Ideally I'd like to have fixtures in one main conftest that login and store the auth cookies for each role, and then we can call the various roles in each test. I've been doing a lot of trial and error to try to figure this out on my own, but so far I haven't reached a solution. Any pointers would be very appreciated!

This thread is trying to answer question "How to handle multiple signed-in roles in Python similar to the Node.js documentation provided by Playwright?"

7 replies

I don't use Playwright for Python, but would it not be pretty similar to how it's done in Node?


Yes, I'm trying to figure that out but am not sure exactly how to translate into Python. I worked on this most of yesterday and I figured out that I think I need to add @pytest.mark.browser_context_args(storage_state="storage_state.json") to each test. Now I'm trying to figure out the best way to call the fixture in the conftest that sets each storage state - I don't want the fixtures to run automatically before all tests because we have a lot of roles to login, and most of the time we will likely only need one or two.


In case anyone in the future needs this info, I ended up asking this question in the Playwright GitHub, and the solution they helped me come up with can be viewed here: https://github.com/microsoft/playwright-python/issues/2151

@melon_mycelia: this is possiible

this is possiible

you need fixture closures

this way they will run when called,not before the test

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.