QA AND TEST AUTOMATION · PART 5 · UI WEB AUTOMATION · TECHNIQUE · 60 OF 112

Testing Passkeys (WebAuthn) and Login Flows

Testing sign-in thoroughly: password login cases checked on ShopRung (same message for unknown email and wrong password, case-insensitive email, length rules, and no lockout after 8 failed attempts), MFA and one-time codes, and passkeys with WebAuthn, automated with a virtual authenticator in Playwright on a small demo page: register, sign in, and a failed sign-in when user verification is off.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Generic errors
  • rate limiting
  • MFA via test secrets
  • WebAuthn virtual authenticator
  • SSO via test tenants

Notes

Password logins

Every login form needs these cases. A valid login lands the right user on the right page. A wrong password and an unknown email give the same generic message, so attackers cannot discover which emails have accounts. Email case, spaces and unusual characters. Empty and very long input. Pasting into the password field. Rate limiting or lockout after repeated failures. Logout that really ends the session. And redirecting back to the page you came from.

Login test ideas
  • valid login → right user, page
  • wrong password / unknown email → SAME generic message
  • email case, spaces, Unicode
  • empty fields, very long input
  • show/hide password, paste
  • lockout or rate limit after repeated failures
  • logout really ends session
  • redirect back after login

ShopRung, checked

We checked ShopRung's login API. Wrong password and unknown email both return four oh one with the same message, email or password is wrong. Good. Alice's email in capitals logs in, so emails are not case sensitive. A short password at signup gets four hundred, password must be eight to sixty four characters. But eight failed logins in a row all returned four oh one, with no lockout or slow down. In a real product, that gap would be worth raising.

What ShopRung does
wrong password  401
  "Email or password is wrong"
unknown email   401
  "Email or password is wrong"
  → same message: good
ALICE@shoprung.test → 200
  (email not case sensitive)
signup "short" → 400
  "Password must be 8 to 64 ..."
8 failed logins in a row:
  401 × 8, no lockout

MFA and codes

Multi factor authentication adds a second step: a code from an authenticator app, a text message or an email. Test expired codes, reused codes and wrong codes. To automate app codes, give the test account a known test secret and generate the current code in the test with a TOTP library. For text and email codes, use test inboxes or the provider's test API, never personal phones. Also test recovery codes and remember this device.

Multi-factor tests
  • codes by app (TOTP), SMS or email; expired, reused, wrong
  • automating TOTP: generate the code from a TEST secret
  • SMS/email: test inboxes or APIs, never real phones
  • recovery codes, "remember this device"
  • never: disable MFA in prod to make tests pass

Passkeys

Passkeys use public key cryptography through a web standard called WebAuthn. At registration, the authenticator, such as a phone, a laptop or a security key, creates a key pair just for that site, and the server stores only the public key. At sign in, the server sends a random challenge, and the device signs it after a fingerprint, face or PIN check. There is nothing to type and nothing to phish, because the key only works on the real domain.

How passkeys work
  • register: the authenticator makes a key pair for THIS site; server stores the public key
  • sign in: server sends a challenge; device signs it after fingerprint, face or PIN
  • nothing secret to type or phish; bound to the domain
  • standard: WebAuthn (FIDO2)

Virtual authenticator

An automated test cannot press a fingerprint reader. Browsers support a virtual authenticator instead. In Playwright with Chromium, open a Chrome DevTools protocol session, enable WebAuthn, and add a virtual authenticator: CTAP two, an internal platform authenticator like a laptop's, able to store passkeys, with user verification that succeeds. Selenium offers the same idea through its virtual authenticator API.

Chromium via CDP (Playwright)
const cdp = await page.context()
  .newCDPSession(page);
await cdp.send("WebAuthn.enable");
const r = await cdp.send(
  "WebAuthn.addVirtualAuthenticator",
  { options: {
    protocol: "ctap2",
    transport: "internal",
    hasResidentKey: true,
    hasUserVerification: true,
    isUserVerified: true } });

Run for real

ShopRung has no passkeys, so we built a tiny demo page on localhost and tested it. Clicking create passkey registered a credential, and the virtual authenticator showed one stored passkey for localhost. Signing in worked. Then we switched user verification off, as if the fingerprint check failed, and the sign in attempt failed with a not allowed error. All in one test, passing in one second.

Demo page results
click "Create passkey"
  → "registered public-key"
WebAuthn.getCredentials
  → 1 credential, resident,
    rpId "localhost"
click "Sign in with passkey"
  → "signed in public-key"
setUserVerified(false), retry
  → "error NotAllowedError"
1 passed (1.0s)

Passkey cases

Passkey test ideas. Register, sign in and sign out. Verification failing or the user cancelling, which should give a clear message, not a frozen page. Several passkeys on one account, and removing one. Fallbacks to a password or account recovery. A subdomain or wrong domain, where the passkey must not work. An account with no passkey. And signing in on a laptop with a phone by scanning a QR code, which is best tested manually on real devices.

Passkey test ideas
  • register, sign in, sign out verification fails or is cancelled → clear message
  • several passkeys per account; remove one fallback: password, recovery
  • wrong domain / subdomain
  • account with no passkey
  • cross-device: phone QR flow (manual)

Third-party sign-in

Sign in with Google or a company's single sign on is common. Do not automate the real provider's login page: it has bot detection and CAPTCHAs, changes without notice, and its terms often forbid it. Instead, use test accounts in a test tenant, a mock identity provider, or tokens obtained through an API and loaded as storage state, as in the fixtures episode. Then test your own callback handling directly.

Social and SSO logins
  • do not automate the real provider's page (bot checks, CAPTCHAs, flaky, terms)
  • instead: test accounts in a test tenant, or mock the identity provider
  • or get tokens via the API and load storageState
  • test the callback page itself

Common mistakes

Login testing mistakes. Testing only the happy path. Personal phones for text message codes. Automating real Google or Microsoft login pages. Turning multi factor off in every test environment, so it is never tested at all. Passwords in code, logs or screenshots. And never testing rate limits or lockouts, the gap we just saw on ShopRung.

Avoid these
  • only testing the happy path
  • real personal phones for SMS codes
  • automating real Google/ Microsoft login pages
  • MFA turned off in test envs forever (untested)
  • passwords in code or logs
  • no lockout/rate-limit tests

Say it like this

In the interview: I use a virtual authenticator, through the WebAuthn domain of the Chrome DevTools protocol in Playwright, or Selenium's virtual authenticator support. I test registration, sign in, failed or cancelled verification, multiple and removed passkeys, password and recovery fallbacks, and that passkeys only work on the right domain. Cross device QR flows I check manually on real phones.

In the interview
  • "With a virtual authenticator: CDP WebAuthn in Playwright or Selenium's virtual
  • authenticator. I test
  • registration, sign-in, failed
  • or cancelled verification, multiple and removed passkeys, fallback and recovery, and the domain binding. Cross-device
  • QR flows I check manually."

Interview questions

Q1Why should login errors be generic?

So attackers cannot tell whether an email has an account (user enumeration); wrong password and unknown email should get the same message.

Q2What is a passkey?

A WebAuthn/FIDO2 credential: a key pair created per site on an authenticator; the server stores the public key and verifies signed challenges, so there is no password to steal or phish.

Q3How do you automate passkey tests?

With a virtual authenticator: the Chrome DevTools Protocol WebAuthn domain (used from Playwright with Chromium) or Selenium's virtual authenticator API.

Q4How do you automate TOTP-based MFA?

Give the test account a known test secret and generate the current code in the test with a TOTP library.

Q5Should you automate "Sign in with Google" pages?

No; use test tenants, a mock identity provider or API-obtained tokens, and test your own callback handling.

Q6What login security cases should a tester check?

Generic errors, rate limiting or lockout, session expiry and real logout, secure cookies, password rules and no credentials in URLs or logs.

Q7What is user verification in WebAuthn?

The authenticator confirming the user locally with biometrics or a PIN before signing; tests can simulate success or failure.

Q8What passkey cases are hard to automate?

Cross-device sign-in with a phone via QR code and platform-specific prompts; these are usually checked manually on real devices.