TOPIC 46/6018 MINNOT STARTED

Email, one-time codes and multi-factor sign-in flows

Test a sign-in that sends a code by email or needs an authenticator app code: catch the mail, make the code at run time, and know when a test-only bypass is fair.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: catching a letter the app posts to itself. Imagine a clubhouse that only opens when you read out a secret word. The word is posted to you on a card. A visitor would need to open the mailbox, read the card and say the word. A robot visitor needs a way to do the same.

Daily List is a to-do list app. Its sign-in now sends a six-digit code to the user's email. Tom, the tester, writes a test for sign-in. The test can type an email and a password, but then the page waits for a code that only the mail holds.

What it is: Playwright is a free tool, made by Microsoft, that drives real web browsers from test code. It clicks and types well, but it cannot read an email inbox or an authenticator app by itself. This topic covers the three ways around that. A one-time code is a short number that works once, such as the six digits in an email. Multi-factor sign-in asks for a password and then a second proof, such as that code. A is an inbox that code can read. A time-based code comes from an authenticator app, and a small library can make the same code inside a test. Do not mix up the email code, which the server sends, with the authenticator code, which the test makes itself.

Why it matters: sign-in with a one-time code is a real path users take. Without a mailbox the test can read, Tom cannot finish the flow, and a broken email step ships unnoticed. Every test behind sign-in is also stuck until this works.

The picture has a limit. A real post takes days, but email takes seconds, and a test must wait for it with care.

Kept simple: this lesson names the main ways. Some services also send codes by text message. The same ideas apply.

(SYNTHETIC / TRAINING ONLY: Daily List, its test site and every person named here are made up.)

PLAIN WORDS · 2 in this section
playwright
a free Microsoft tool that drives a browser for tests
authenticator
an app or device that proves who you are

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 Letting a test pass a sign-in that needs a code from an inbox or an authenticator, without real people's data.

  1. Make a fresh address
  2. Start sign-in
  3. Catch the code
  4. Type it in
Own mailbox, fresh address, clock in step

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The clubhouse doorThe extra sign-in step
The card posted to youThe emailed code
Your own mailboxThe test mailbox
The secret handshake that changes with the clockThe time-based code made from the secret

WHERE THIS PICTURE STOPS

  • A real post takes days, and email takes seconds, so the test must wait with care.
  • A secret word stays the same, but a time-based code changes, so a recorded one is useless.
  • A clubhouse has one door. A test site may have a bypass, which is a side door for tests only.

HOOK

Own mailbox, fresh address, clock in step.

REMEMBER IT THIS WAY

A sequence: the real steps, in order.

Three things catch the code: an own mailbox, a fresh address per run, and a clock in step for time-based codes.

What each part of the trick stands for
In the trickWhat it stands for
mailboxthe test mailbox
addressfresh for each run
clockthe time-based code made from the secret

TELL A FRIEND

A robot opens its own mailbox, reads the card the app posted and says the secret word.

OFTEN MIXED UP WITH Logging in once: authentication and storage state. The authentication lesson saves a login for reuse. This lesson shows how to pass the extra step on the way.

Sources & standards — 6 sources
  1. Market practice

    Automate two-factor and multi-factor authentication testing with Playwright (Mailosaur blog) ↗ — Mailosaur · Read the email through a mailbox service's API and match the six-digit code in the body with a pattern; generate time-based codes at run time from the stored secret (search excerpt, page not opened)

    A vendor tutorial on reading email codes and making time-based codes in Playwright tests. A vendor page, 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; read at the time of writing. 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.

  2. Market practice

    RFC 6238: TOTP: Time-Based One-Time Password Algorithm ↗ — Internet Engineering Task Force · A time-based one-time password is made from a shared secret and the current time, in short time steps (search excerpt, page not opened)

    Defines time-based one-time password (TOTP) as HMAC-based one-time password (HOTP) with a time-based value in place of the counter. · Checked 2026-11-08

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: May 2011. 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.

    8 November2026 bounded primary update: RFC6238 May2011 Informational: selected5.2validation/time-step,6resynchronisation and AppendixB selectedSHA1vector read8November2026. Window/clock policy and successful-use replay state differ;30s defaultrecommendation, not universalexpiry. Earlier000000zero-padding history retained.

  3. Market practice

    III. Config (The Twelve-Factor App) ↗ — Adam Wiggins · Keep config, including credentials, in the environment and not in the code (search excerpt, page not opened)

    Says config is whatever changes between deploys and should be kept in the environment, not in the code. 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.

  4. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · 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. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  5. Market practice

    totp-rfc6238 ↗ — www.rfc-editor.org · Reviewed 6 November 2026: RFC 6238 sections 4–6. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    RFC 6238 sections 4–6 · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: RFC 6238 sections 4–6. 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.

  6. Market practice

    Authenticators ↗ — pages.nist.gov · Reviewed 6 November 2026: SP 800-63B current sections 3.1.3–3.1.5. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    SP 800-63B current sections 3.1.3–3.1.5 · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: SP 800-63B current sections 3.1.3–3.1.5. 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 — 6 sources
  1. Market practice

    Automate two-factor and multi-factor authentication testing with Playwright (Mailosaur blog) ↗ — Mailosaur · Read the email through a mailbox service's API and match the six-digit code in the body with a pattern; generate time-based codes at run time from the stored secret (search excerpt, page not opened)

    A vendor tutorial on reading email codes and making time-based codes in Playwright tests. A vendor page, 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; read at the time of writing. 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.

  2. Market practice

    RFC 6238: TOTP: Time-Based One-Time Password Algorithm ↗ — Internet Engineering Task Force · A time-based one-time password is made from a shared secret and the current time, in short time steps (search excerpt, page not opened)

    Defines time-based one-time password (TOTP) as HMAC-based one-time password (HOTP) with a time-based value in place of the counter. · Checked 2026-11-08

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: May 2011. 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.

    8 November2026 bounded primary update: RFC6238 May2011 Informational: selected5.2validation/time-step,6resynchronisation and AppendixB selectedSHA1vector read8November2026. Window/clock policy and successful-use replay state differ;30s defaultrecommendation, not universalexpiry. Earlier000000zero-padding history retained.

  3. Market practice

    III. Config (The Twelve-Factor App) ↗ — Adam Wiggins · Keep config, including credentials, in the environment and not in the code (search excerpt, page not opened)

    Says config is whatever changes between deploys and should be kept in the environment, not in the code. 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.

  4. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test user-visible behaviour, keep tests isolated, and prefer web-first assertions (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · 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. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  5. Market practice

    totp-rfc6238 ↗ — www.rfc-editor.org · Reviewed 6 November 2026: RFC 6238 sections 4–6. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    RFC 6238 sections 4–6 · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: RFC 6238 sections 4–6. 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.

  6. Market practice

    Authenticators ↗ — pages.nist.gov · Reviewed 6 November 2026: SP 800-63B current sections 3.1.3–3.1.5. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    SP 800-63B current sections 3.1.3–3.1.5 · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: SP 800-63B current sections 3.1.3–3.1.5. 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.