Playmatic has an environment manager for storing and accessing test variables and data across different environments.Each test environment defines the different application instances your tests can target. Each environment includes a base URL and optional variables. Environments are stored in the playmatic.config.ts file. When these variables are collected during the planning phase, the Playmatic agent will automatically write them in this file.Each test environment key (e.g., “production”, “staging”, “development”) contains:
baseUrl (string): The base URL for the application instance
vars (object, optional): Environment-specific variables accessible via env.vars in tests. Supports nested objects for organizing related configuration.
Environments must first be initialized in the playwright.config.ts file, and afterwards, the baseUrl and vars will be accessible by any tests during runtime.
It is required that you use the Playmatic environment manager to store your test data and variables. Otherwise, Playmatic does not have a way to test in its cloud-based VM.
Once the environment has been initialized, tests have access to the environment’s baseUrl and variables via the env object. The baseUrl can be referenced via env.baseUrl, and any variables can be referenced using env.vars.variableName. Nested objects can be accessed via dot notation.
Copy
import { env } from '@playmatic/sdk';import { test } from '@playwright/test';test('User can login successfully', async ({ page }) => { await test.step('Navigate to login page', async () => { // Navigate to the environment's baseURL await page.goto(env.baseUrl); }); await test.step('Fill in login credentials', async () => { // Access environment variables await page.fill('[name="email"]', env.vars.testEmail); await page.fill('[name="password"]', env.vars.testPassword); }); await test.step('Click login button', async () => { await page.click('button[type="submit"]'); }); await test.step('Verify login successful', async () => { // Access nested objects from environment if (env.vars.featureFlags.newDashboard) { await page.waitForSelector('[data-testid="new-dashboard"]'); } else { await page.waitForSelector('[data-testid="legacy-dashboard"]'); } });});