localhost. On Checkly, they hit a deployed URL.
While you could maintain separate Playwright config files for each environment, you can also rely on environment variables to handle the entire Checkly workflow from a single playwright.config.ts. Run npx playwright test locally, npx checkly test against a staging URL, and npx checkly deploy for scheduled production monitoring.
What Checkly sets for you
When your Playwright tests run as a Playwright Check Suite, Checkly sets environment variables into your test process:| Variable | Value | Use case |
|---|---|---|
CHECKLY | "1" | Detect that you’re running on Checkly at all |
CHECKLY_RUN_SOURCE | "SCHEDULER", "TEST_NO_RECORD", "TEST_RECORD", "TRIGGER_API", "CLI_DEPLOY", "DEPLOYMENT", etc. | Distinguish how the check was triggered |
CHECKLY_REGION | "eu-west-1", "us-east-1", etc. | Know which data center is running the check |
CHECK_NAME | String | The name of the check |
CHECKLY_CHECK_ID | UUID | The UUID of the check |
CHECKLY is the simplest variable. It’s a boolean flag.
CHECKLY_RUN_SOURCE gives you more granularity: was this a scheduled production run, a test from the CLI, or a deployment trigger?
The basic pattern: a simple toggle
If you only need two modes (local development and Checkly monitoring), a single boolean defined in yourplaywright.config does the job.
playwright.config.ts
isCheckly toggles four things at once:
baseURL:localhostfor local dev, your deployed URL on Checklyretries: no retries locally (fast feedback), 2 retries on Checkly (resilience against transient network issues and test flakiness)trace: always captured on Checkly for debugging, only on failure locally to save disk space (see Reading traces)webServer: starts your dev server locally, skipped on Checkly (the deployed site is already running)
baseURL only takes effect when your tests use relative URLs in page.goto() calls, e.g. page.goto('/'), not page.goto('https://example.com').The advanced pattern: environment-aware configuration
Some projects need more than two modes. Maybe your CI runs tests against a preview deployment, while Checkly monitors production. Or you want different behavior depending on whether a Checkly run was triggered by a schedule, a deployment, or a manual test. This pattern also works well with CI/CD integrations wherenpx checkly test runs against preview deployments before promoting to production.
Instead of a boolean, you can use CHECKLY_RUN_SOURCE to determine which environment your tests are running in and map that to a specific URL. Sometimes it’s not just about whether you’re running on Checkly or not, but also where your tests run. CHECKLY_REGION lets you adapt test behavior based on the data center location, for example to validate geo-specific content.
Step 1: Create an environment helper
checkly-env.ts
npx checkly test (what you run in CI pipelines) triggers a TEST_* source that maps to your preview/staging URL. Scheduled runs and deployments are production monitoring and point to the live site. Everything else is local dev.
Once you know the environment, you can set different baseURL values, adjust retry and trace settings, or add other environment-specific logic.
Step 2: Use the helper in your Playwright config
playwright.config.ts
Going further: per-environment behavior in tests
If you need per-test access to environment values, you can take the setup from Step 2 further by wiring your helpers into Playwright test fixtures. This keeps environment logic out of individual test files.Create a custom test fixture
Create abase.ts file that extends Playwright’s test object with custom fixture values. All your test files import test and expect from here instead of @playwright/test:
tests/base.ts
environment and locationCountry should be accessible in your Playwright tests. Their default values can be overwritten via the use option in your Playwright config.
Wire it all up in the Playwright config
Pass the helper values into your custom fixtures via theuse option:
playwright.config.ts
Use fixtures in your tests
Your tests stay clean because the environment logic is handled by the fixtures:tests/geo-location.spec.ts
locationCountry fixture is automatically populated based on which Checkly region runs the check. There’s no need for environment logic in the test itself.
Wrapping up
Start with the simpleisCheckly toggle. It handles most cases. When you need more than two environments or per-environment behavior beyond baseURL, extract the logic into a dedicated helper file.
The pattern scales: add a new environment by adding a case to getEnvironment() and a URL to getBaseUrl(). Your tests and Playwright config stay the same.
For the full reference on available environment variables, check the Playwright Check Suite environment variables docs.