Log in once, and use fixtures

Knowledge Videos

Short animated explainers, organised by subject.

Log in once, and use fixtures

Stop logging in through the form in every test: save the session as storage state in a setup project, reuse it in the config, and share helpers with fixtures.

Transcript

Most tests need a logged in user. If every test logs in through the form, you waste seconds hundreds of times, and a bug in the login page breaks every single test.

Instead, log in once in a setup step, and save the session to a file. Playwright calls it storage state. It stores the cookies and local storage of the logged in browser.

In the config, point the browser project at that file, and make it depend on the setup. Now every test starts already logged in, and goes straight to the page it wants to test.

For anything else you repeat, like creating the login page object, use a fixture. A fixture is a ready made helper that Playwright hands to your test, when the test asks for it by name.

Remember: log in once, save the storage state, reuse it in every test, and share helpers with fixtures.

More in this series