Playwright Credential Management

Playwright tests need credentials, such as usernames and passwords, to log in to the system under test. This document describes how Playwright projects store, access and protect those credentials, both locally and in pipelines.

Standard Metadata

  • Area: Playwright
  • Owner: Technical Leadership group
  • Last reviewed: 2026-10-07
  • Next review due from: 2026-12-01
  • Enforcement: Code review
  • Status: Active

Store Playwright test credentials in the .env file · PW-03.1 · MUST · TEST

Store credentials, such as usernames and passwords, in a .env file in the root of the Playwright repo when running tests locally.

Document the credentials needed in the project’s README, as described in the README standards.

Do not commit or log Playwright test credentials · PW-03.2 · MUST · TEST

  • Add .env to the .gitignore file so that it is never committed.
  • In pipelines, store credentials as secret pipeline variables and pass them to the tests as environment variables.
  • Do not output credentials, for example with console.log(), or include them in test titles, annotations or custom expect messages.
- script: npx playwright test
  displayName: 'Run Playwright tests'
  env:
    ADMIN_PASSWORD: $(AdminPassword) # Secret pipeline variables must be mapped explicitly

NOTE: Playwright traces and videos can capture credentials as they are typed. Only publish them as pipeline artifacts, not to shared or public locations.

Only read process.env in the Playwright env.ts file · PW-03.3 · MUST · TEST

Only helpers/env.ts may read process.env. Every other file, including tests and page objects, must access credentials through the Env class it exports, for example:

export default class Env {
  static readonly BUSINESS_USER_CODE: string = process.env.BUSINESS_USER_CODE;
}

These credentials can then be accessed from a test or page file like so:

  await dealerPage.businessUserInput().fill(Env.BUSINESS_USER_CODE);