Run Playwright Tests from a Separate Repository in CI
Run Playwright Tests from a Separate Repository in CI
The Problem link
You want to keep your Playwright tests in a separate repository from your application code, but you also want those tests to run automatically on every pull request.
Maybe your test suite has grown large enough to deserve its own repo. Maybe you're testing multiple applications with the same test suite. Or maybe you just want clean separation between test code and application code.
Whatever the reason, GitHub Actions doesn't make this obvious. Most examples assume tests live in the same repository.
The Solution link
The key insight: GitHub Actions can check out multiple repositories in a single workflow. This means your application's CI can:
- Check out the application code (the PR)
- Check out your test repository
- Start the application
- Run the tests
This is simpler than it sounds.
Prerequisites link
Before you start, you'll need:
- An application repository (where PRs happen)
- A test repository with Playwright tests
- A GitHub Personal Access Token with
reposcope
Step 1: Create a Personal Access Token link
The workflow needs permission to access your private test repository.
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Give it a descriptive name like
Playwright Tests Access - Select the
reposcope (full control of private repositories) - Generate and copy the token
Now add this to your application repository:
- Go to your app repo → Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name it
PLAYWRIGHT_TESTS_TOKEN - Paste the token value
Step 2: Create the Workflow link
In your application repository, create .github/workflows/playwright-tests.yml:
Replace your-org/your-test-repo-name with your actual test repository.
Step 3: Configure Playwright link
In your test repository, make sure your playwright.config.ts uses environment variables:
This allows the tests to run against different environments without code changes.
Step 4: Install wait-on link
The workflow uses wait-on to ensure the dev server is ready before running tests. Add it to your application repository:
Common Issues link
Tests can't find the application link
Problem: Tests fail with connection errors.
Solution: Check that:
- Your dev server actually starts on port 3000 (or update the port)
- The
wait-ontimeout is long enough (default: 60 seconds) - Your application doesn't require environment variables to start
Token authentication fails link
Problem: "fatal: could not read Username" or similar errors.
Solution: Make sure:
- The token has
reposcope - The secret name matches exactly (
PLAYWRIGHT_TESTS_TOKEN) - The token hasn't expired
Tests pass locally but fail in CI link
Problem: Tests work on your machine but fail in GitHub Actions.
Solution: Common causes:
- Different BASE_URL (check your local
.env) - Missing test dependencies (run
npx playwright install --with-deps) - Timing issues (add proper waits, not fixed sleeps)
When to Use This Pattern link
This setup makes sense when:
- Your test suite is large and deserves its own repository
- Multiple teams maintain tests vs. application
- You're testing multiple applications with shared tests
- You want independent release cycles for tests and code
Don't overcomplicate things. If your test suite is small, keeping it in the same repository is usually simpler.
Alternative: Git Submodules link
Some teams prefer Git submodules instead of checking out a separate repository in CI. The workflow is slightly different:
Submodules have their own complexity. The dual-checkout approach is usually cleaner.
Testing Against Deployed Environments link
This workflow tests against localhost. To test against deployed preview environments:
You'll need to integrate this with your deployment system (Vercel, Netlify, etc.) to get the preview URL.
The Bottom Line link
Separating test repositories from application code is straightforward with GitHub Actions' multi-repository checkout. The key is:
- Use a Personal Access Token for private repositories
- Check out both repos in the same workflow
- Install dependencies for both
- Use environment variables for configuration
This pattern scales well and keeps your test code organized separately without sacrificing CI integration.
More posts on Playwright patterns and CI/CD optimization coming soon.
Feel free to update this blog post on GitHub, thanks in advance!