Run E2E tests on every preview deployment
To run E2E tests on preview deployments, wait for the deploy, take its address and run your journeys there. Five traps, and what a preview can’t prove.
To run E2E tests on preview deployments you need three things: a signal that the preview is ready, its address, and tests that take their address from a variable. When the host says the deploy succeeded, a job runs your journeys against that address and reports on the pull request.
The set-up is the easy part. What takes longer is learning the five ways a preview differs from the app your users see, and remembering that a green preview says nothing about production’s settings.

The set-up: run tests against the preview deployment
Hosts that build a preview per pull request usually tell your repository when it is ready, as a deployment status with the preview’s address in it. In GitHub Actions that event starts a workflow:

on: deployment_status
jobs:
e2e:
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run test:e2e
env:
BASE_URL: ${{ github.event.deployment_status.environment_url }}
Two details make or break this.
The tests read BASE_URL. Every address in the suite is built from it. A single hard-coded production address in one test means that test silently checks production while the others check the preview, and it passes for the wrong reason.
Trigger on the deploy, not on the push. If the tests start when the code is pushed, they race the build. Either they run against the previous preview or they fail because nothing is there yet. If your host gives no ready signal, poll the address until it answers before you start.
Five things that trip preview environment testing
1. The preview is behind a wall. Many hosts protect previews with a password or a team sign-in. Your tests then meet the host’s login page on every address and fail, or worse, pass a “the page loads” check against the wall. Hosts that protect previews offer a way through for automation, usually a secret header or token. Use it, and add one check that the page you opened is your app.
2. Which database? This decides what you can test. If every preview shares one staging database, two pull requests’ tests run against the same rows, and a migration in one branch breaks the other. If each preview gets a fresh database, it is empty: no test accounts, nothing in any list. Either way, decide it on purpose. We’d take a fresh database with a small seed script that creates one account per kind of user.
3. Test accounts. The logins your tests use have to exist where the preview looks. On a fresh database, the seed makes them. On a shared one, they exist already and every test has to clean up what it made, or the next run finds leftovers. Either way they are accounts made for testing, one per kind of user.
4. Outside services only know your real address. Sign-in through another service usually allows a fixed list of return addresses, and a preview’s address changes with every branch. Payment callbacks and email links point wherever your settings say, often production. On a preview, expect these journeys to need a workaround (a stable alias for the preview, a test mode, an email-and-password login for tests) or to be left for staging.
5. It is ready before it is warm. The first request to a fresh preview can be slow: cold functions, an empty cache. A test with a tight timeout fails on its first page and passes when run again. Open one page and wait for it before the first test, so that a slow start isn’t reported as a broken journey. Retrying until it passes hides this, along with real bugs.
Which E2E tests to run on preview deployments
All of them that touch what the pull request can break, and especially the ones you can’t run on production.
A preview is the right place for tests that change data: create, edit and delete for real, upload files, go through sign-up with a new account. On a fresh database nothing they do can hurt. It is also where you can test the checkout one step further than on the live site, with the provider’s test keys and a test card.
Keep the run short enough that people wait for it. If the suite takes long, run the journeys the change touches first and the rest after. A check that arrives after the merge button was pressed protects nobody.
What a preview can’t tell you
A preview runs your new code with preview settings on preview data. Production differs in exactly the places where release-day bugs live:
- Settings. Environment variables, keys, product ids, feature switches. A preview can be perfect while production points at last year’s key.
- Data. A migration that takes a blink on a seed database and minutes on the real table. A list page that is fine with three rows and times out with years of them.
- The outside. The real domain, its certificate and cache, scheduled jobs, callbacks from other services.
- The other kinds of user. If the seed has only an admin, the preview never shows what a viewer sees.
So the preview check doesn’t replace a check after the production deploy. It moves failures earlier, to where they cost a comment on a pull request. The production run is smaller: the same journeys, without the tests that change data, on the address your users use. Each journey should still end on a real result. A production check that only confirms pages load is how you get tests that pass while the app is broken.
How EveryRole runs on a preview
EveryRole tests an app from the outside, so a preview is just another address. Each app can have a deploy hook: a secret link your pipeline calls when a deploy finishes. Its body can carry base_url, to test that address instead of the app’s own, and an environment (preview, staging or production). The commit and branch you send are shown with the run, so the result names the deploy it tested. The docs on deploy hooks have the snippets.
The environment matters for safety. Tests that really change data are added by name and run only in the environments you allowed for them, so they can run on previews and stay off production. A never-click word is refused everywhere.
If you’d rather not hand over test logins, the same tests can run in your own CI: the job reads BASE_URL, and each login stays in your pipeline’s masked variables.
One thing it does the way we’d advise anyone to: two previews are treated as two different apps. A test that fails on one branch’s preview says nothing about another’s.


