How to Speed up your Playwright Tests with shared 'storageState'

preview_player
Показать описание
Join Stefan Judis, Playwright Ambassador, as he shows you how to speed up your Playwright test suite execution time for apps behind a login. Usually, login-walled products require you to log in for every test case. However, by implementing project dependencies, setting up a project, and pairing everything with the storage state, you can log into your app once and then reuse the browser and storage state. This setup equips your subsequent tests with essential cookies and browser state, saving time and effort by avoiding repetitive login actions.

0:00 Intro
0:35 Example project setup
2:03 Add a new Playwright project
4:24 Connect projects with project dependencies
5:09 Reuse storage state across projects
7:13 Run projects and their dependencies in UI mode
8:12 Outro

If you find this tutorial helpful, please like, subscribe, and leave your questions or feedback in the comments below!

#playwright #endtoendtesting #checkly #syntheticmonitoring
Рекомендации по теме
Комментарии
Автор

Quick comment after releasing this video: you can and should only reuse session / login data when your tests aren't modifying the existing user. Otherwise, your tests will conflict with each other. In these scenarios, it's better to create a new user for each tests.

ChecklyHQ
Автор

I cannot imagine that this amazing concept exists! Thanks sir.

phatle
Автор

Maybe it is wrong place to ask such question but maybe you can make a video about working with new windows and tabs. Especially I am puzzled how to implement test to check 'Remember me' functionality when the same page should be reopen in the same context.

ИльяПетров-ръ
Автор

I am working on an application where the login flow is not based on the user's input. Instead the user is redirected to an Okta auth page which internally uses kerberos and eventually redirects the user back to the application. The redirect logic and local storage update is handled by Okta auth js and okta react packages.

In this scenario, how can I stub my auth state to a temporary json file? When I try to run my tests, the auth flow breaks as Okta server doesn't recognize the user when the application is running via playwright's browser.

Wakkyguy
Автор

Is there a workaround if your app is integrated with OKTA authentication?

MrAnujbajaj
Автор

Your tips have everything I was looking for, thank you so much.
I wouldn't have started my test automation project without your channel.

suda-nz
Автор

Did someone try it with auth0, does it work fine? I loose login after a 2-4 tests... UPDATE: works fine, it's just logout of one of the tests cancelled the state (what a surprise) No logout - runs fine

iHorus
Автор

Спасибо за видео и время которое вы потратили на его создание. Вы очень помогли

vaveal
Автор

It' great. Could you make a video to guideline "Testing multiple roles with POM fixtures", please?

phamquynh
Автор

Neat way to reuse logged-in state, when you don't create unique users for each test and can't (or don't want to) auth via API calls!
Great content! Thanks 👍

dva_kompota
Автор

This is useful for login with MFA functionalities.

maniladevotee
Автор

Nice trick, now do it with session storage :3

DJ_Locks
Автор

Great video, everything worked like a charm! Quick question, could you theoretically use similar logic to store login state when running the scraper in a production environment with Playwright Library?

stephena
Автор

I have 7 tests to run, after using this, first, it's taking only 4 workers instead of 7 workers, and after that, the other 3 workers started. Do I need to change anything?

Uradha
Автор

It works until my session is active i .e.if the maximum time for a session is 15 mins . If I try to access my stored. Json file after 15 mins it would show session time out . How to resolve it

MuraliRajamanickam
Автор

I did the exact setup but on next load it again lands on login page.

abhishekshukla
Автор

Just worth to mention that this method is only viable when you do not change any data on a user or in the system that is shared between tests. In most cases you need to create new user and log in via api.

Dzidziolino
Автор

I can create the storage using setup, but it's not passing to next test. In the browser, it was showing" about:blank". But on your video pass to another test.

Uradha