+
+ Platforms like Vercel and Netlify expose preview deployment URLs via environment variables (e.g. `VERCEL_URL`). You can pass these to your Checkly test runs using the `-e` flag: `npx checkly test -e ENVIRONMENT_URL=https://preview-abc.vercel.app`.
+
+
+ Your `getBaseUrl` function can then read `process.env.ENVIRONMENT_URL` instead of hardcoding a preview URL. See the [CI/CD integration docs](/integrations/ci-cd/overview) and the [`npx checkly test` reference](/cli/checkly-test) for more details.
+
+
+
+### Step 2: Use the helper in your Playwright config
+
+```typescript playwright.config.ts highlight={4-5, 10}
+import { defineConfig, devices } from "@playwright/test";
+import { getBaseUrl, getEnvironment } from "./tests/checkly-env";
+
+const environment = getEnvironment(); // "DEV" | "CI" | "PROD"
+const baseURL = getBaseUrl(environment); // "http://localhost:3000" | "https://preview.example.com" | "https://www.example.com"
+
+export default defineConfig({
+ retries: environment === "DEV" ? 0 : 2,
+ use: {
+ baseURL,
+ trace: environment === "DEV" ? "retain-on-failure" : "on",
+ },
+ projects: [
+ {
+ name: "Critical",
+ use: { ...devices["Desktop Chrome"] },
+ grep: /@critical/,
+ },
+ ],
+});
+```
+
+With this approach, you have one config file that targets three environments with different base URLs and no duplication.
+
+### 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](https://playwright.dev/docs/test-fixtures). This keeps environment logic out of individual test files.
+
+