Skip to main content

How do you handle authentication in automated tests efficiently?

  • authentication
  • test efficiency
  • storageState

Answer it first, then compare. Nothing here is saved or scored.

Model answer

Avoid logging in through the UI for every test, it's slow and fragile. Strategies: (1) API login - hit the auth endpoint, get a token, inject it. (2) Storage state - Playwright's `storageState` saves and reuses cookies/tokens across tests. (3) Bypass auth, use test-only auth shortcuts in lower environments. (4) Token factories - generate valid JWTs directly for test users. Always use dedicated test accounts with known credentials.

What interviewers listen for

  • Test architecture instincts
    You can defend why your suite is shaped like a pyramid, a trophy, or a honeycomb.
  • Locator discipline
    You rank selector strategies by stability and explain when to break the rule.
  • Flaky test ownership
    You debug to a structural fix instead of retry-until-green.
  • Parallelisation literacy
    You know how your framework isolates state, fixtures, and database access across workers.

See all 35 automation questions

Written by , Senior QA Automation Engineer, 50+ QA candidate interviews conductedLast updated July 2026