Logging in once: authentication and storage state
Log in once in a setup test, save the browser state to a file and load it in every test. Keep the file secret and refresh it when it goes stale.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a wristband that gets you into every ride after one check at the gate. You show a ticket once. The wristband does the rest. You do not queue at the gate before every ride.
Daily List is a to-do list app. Tom's tests all begin with a login. That is several seconds of typing in every test, and a changed login page breaks all of them at once.
What it is: Playwright is a library that drives a real browser. This slice is logging in once and reusing that browser state. An signs in and writes a . Later tests load the file and start already signed in. The nearest neighbour is typing the password in every test. Selenium suites often do that, or they share one logged-in browser and then leak the session.
Why it matters: Repeating the login burns minutes and adds a flaky type step to every test. One setup test means a login-page change is fixed in one file. The rest of the suite spends its time on the feature under test.
A wristband expires, and so does a saved session. A wristband can be copied, and so can the file. Treat the file as a secret.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)
PLAIN WORDS · 5 in this section
- wristband
- a band worn around the wrist
- playwright
- a free Microsoft tool that drives a browser for tests
- reusing
- using something again
- selenium
- A free tool that drives a web browser for checks.
- flaky
- passing sometimes and failing sometimes with no product change
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Logging in once, saving the proof to a file and reusing it, while keeping the file safe.
- Log in once
- Save the file
- Load it in tests
- Refresh when stale
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The ticket check at the gate | The authentication setup test |
| The wristband | The storage state file |
| A ride that accepts the wristband | A test that loads the file |
| A wristband that has run out | A stale saved session |
WHERE THIS PICTURE STOPS
- A wristband is cut off at the end of the day, but a saved log-in can end at any moment.
- A stolen wristband is one ride pass, but a stolen file is a whole account.
- The gate shows you are allowed in. It does not show you are the right person for each ride.
HOOK
One check, one wristband.
REMEMBER IT THIS WAY
A rule of thumb: if you see this, think that.
If every test starts with eight seconds of log-in, log in once and save the wristband file.
| In the trick | What it stands for |
|---|---|
| Log in once | one test that only logs in |
| Wristband file | what the browser holds after log-in, saved in a file |
A saved session can go stale, and the file holds log-in proof, so keep it safe.
TELL A FRIEND
A wristband that gets you into every ride after one check at the gate. Keep it safe, and expect it to run out.
OFTEN MIXED UP WITH Isolation: browser contexts and a fresh state for every test. Isolation gives each test a clean browser. Here the clean browser starts with a saved log-in.
Sources & standards — 4 sources
- Market practice
Authentication (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Projects (Playwright documentation) ↗ — Microsoft (Playwright) · A project lists other projects in dependencies so they run first (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Session management cheat sheet (Open Worldwide Application Security Project) ↗ — Open Worldwide Application Security Project (OWASP) · A session identifier must be renewed after sign-in and treated as a secret; practitioner guidance (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Verification supplement, 6 November 2026: Actual introduction/session-ID properties opened: authenticated session identifier is itself a secret capable of impersonation; opaque does not mean secret-free.
- Market practice
BrowserContext (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: clearPermissions, grantPermissions and storageState options. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: clearPermissions, grantPermissions and storageState options. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
PRACTISE AND KEEP
Sources for this topic — 4 sources
- Market practice
Authentication (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Projects (Playwright documentation) ↗ — Microsoft (Playwright) · A project lists other projects in dependencies so they run first (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Session management cheat sheet (Open Worldwide Application Security Project) ↗ — Open Worldwide Application Security Project (OWASP) · A session identifier must be renewed after sign-in and treated as a secret; practitioner guidance (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Verification supplement, 6 November 2026: Actual introduction/session-ID properties opened: authenticated session identifier is itself a secret capable of impersonation; opaque does not mean secret-free.
- Market practice
BrowserContext (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: clearPermissions, grantPermissions and storageState options. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: clearPermissions, grantPermissions and storageState options. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.