It’s 2 AM. The CI pipeline has just failed — again — because of E2E test timeouts. You open the Allure report and see that 47 out of 50 test cases were stuck on the login page for over 8 seconds. Your team is writing automated tests with Playwright, but every single test goes through the entire login flow from scratch: type username, type password, click the button, wait for the redirect. You think, “Isn’t this just burning time and money for nothing?” What’s even more absurd is that no one thought about saving and reusing the login state.

That’s what we’re covering today: using Playwright’s storageState together with pytest’s fixture mechanism to compress repeated logins into a single one, while extracting the assertion logic into reusable “memory modules” to make your test code shorter and more stable.

Breaking Down the Problem

The scenario is all too common: you have an admin system (like an operations panel or SaaS console) that requires login to access. You’ve written 50 P0-level functional tests. The simplest approach puts page.goto('/login') in every case, fills the form, logs in, and then tests the actual business logic. The results:

Execution time explodes: The average login takes 2.3 seconds (including page load, typing, clicking, waiting for the dashboard). 50 test cases devour 115 seconds just logging in, and with CI resource queuing, one run easily exceeds 8 minutes.