TOPIC 17/6022 MINNOT STARTED

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.

  1. Log in once
  2. Save the file
  3. Load it in tests
  4. Refresh when stale
One check, one wristband

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The ticket check at the gateThe authentication setup test
The wristbandThe storage state file
A ride that accepts the wristbandA test that loads the file
A wristband that has run outA 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.

What each part of the trick stands for
In the trickWhat it stands for
Log in onceone test that only logs in
Wristband filewhat 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
  1. 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.

    Describes a setup project that logs in once and saves browser state to a file under playwright/.auth, loading it as storageState in browser projects, adding the folder to .gitignore because the file can hold sensitive cookies, one file per role and a separate account per worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    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.

  2. Market practice

    Projects (Playwright documentation) ↗ — Microsoft (Playwright) · A project lists other projects in dependencies so they run first (search excerpt, page not opened)

    Describes projects as logical groups of tests that share a configuration, run in several browsers, with a dependencies list so setup projects run first, a teardown property and the --no-deps option. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    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.

  3. 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)

    Per the search excerpt, the session identifier must be renewed after any change in privilege such as sign-in, and the old one destroyed; this prevents session fixation. Practitioner guidance, not a standard. · Checked 2026-11-06

    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.

  4. 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.

    Describes offline emulation and what it covers. Vendor documentation, not a standard. · Checked 2026-11-06

    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
  1. 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.

    Describes a setup project that logs in once and saves browser state to a file under playwright/.auth, loading it as storageState in browser projects, adding the folder to .gitignore because the file can hold sensitive cookies, one file per role and a separate account per worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    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.

  2. Market practice

    Projects (Playwright documentation) ↗ — Microsoft (Playwright) · A project lists other projects in dependencies so they run first (search excerpt, page not opened)

    Describes projects as logical groups of tests that share a configuration, run in several browsers, with a dependencies list so setup projects run first, a teardown property and the --no-deps option. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    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.

  3. 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)

    Per the search excerpt, the session identifier must be renewed after any change in privilege such as sign-in, and the old one destroyed; this prevents session fixation. Practitioner guidance, not a standard. · Checked 2026-11-06

    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.

  4. 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.

    Describes offline emulation and what it covers. Vendor documentation, not a standard. · Checked 2026-11-06

    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.