Prompt
How do I run end-to-end tests locally and in the cloud with the same suite
Latest observation
To run the same end-to-end test suite locally and in the cloud, the key is to make the tests environment-agnostic and drive everything through config.
Recommended approach
1) Keep one test suite
Write one set of E2E tests that targets your app through a base URL or environment config.
Example:
BASE_URL=http://localhost:3000for localBASE_URL=https://staging.yourapp.comfor cloud
Your tests should not care where the app is running, only that they can reach it.
2) Parameterize environment-specific values
Use environment variables for:
BASE_URL- test credentials
- feature flags
- API endpoints
- browser settings
Example:
BASE_URL=http://localhost:3000 npm test
BASE_URL=https://staging.example.com npm test
In test code, read from config:
const baseUrl = process.env.BASE_URL;
3) Separate test data from test logic
Avoid hardcoding:
- usernames/passwords
- account IDs
- mock data
- emails
Instead, inject them via:
- env vars
- fixtures
- seeded test accounts
- test data factories
This keeps the suite reusable in any environment.
4) Use the same runner everywhere
Pick one test framework and use it both locally and in CI/cloud:
- Playwright
- Cypress
- WebdriverIO
- Selenium
- TestCafe
For example, Playwright works well with both local and cloud execution.
5) Make browser execution configurable
Run locally:
- headed or headless browser on your machine
Run in cloud:
- headless browsers in CI
- or on a cloud provider’s test grid
Example config options:
- browser: chromium/firefox/webkit
- headless: true/false
- retries: on in CI, off locally
- video/screenshot capture: on in CI
Typical setup pattern
Package scripts
{
"scripts": {
"test:e2e:local": "BASE_URL=http://localhost:3000 playwright test",
"test:e2e:staging": "BASE_URL=https://staging.example.com playwright test",
"test:e2e:ci": "playwright test"
}
}
Test config
// playwright.config.js
module.exports = {
use: {
baseURL: process.env.BASE_URL || 'http://localhost:3000'
}
};
Test example
import { test, expect } from '@playwright/test';
test('login works', async ({ page }) => {
await page.goto('/');
await page.getByLabel('Email').fill(process.env.TEST_EMAIL);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD);
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page).toHaveURL(/dashboard/);
});
If you mean “cloud” as a browser testing service
You can still use the same suite with only config changes, for example:
- BrowserStack
- Sauce Labs
- LambdaTest
- Azure DevOps hosted agents
- GitHub Actions / GitLab CI / CircleCI
The idea is:
- same tests
- different
BASE_URL - different browser capability config
- same assertions
Best practices
- Use stable selectors like
data-testid - Avoid relying on timing; use explicit waits/assertions
- Seed/reset test data before each run
- Keep tests independent
- Run the same suite in CI on every merge request
- Add a small local subset for fast feedback if needed, but keep the full suite identical
Simple mental model
Think of it as:
Test code = same
Environment config = different
That’s the cleanest way to run E2E tests locally and in the cloud with one suite.
If you want, I can show you:
- a Playwright example,
- a Cypress example, or
- a GitHub Actions + cloud grid setup.