Selenium · Browser automation foundations
How do you run Selenium suites reliably in CI?
Short answer
Run headless or against a Grid, pin browser and driver versions, publish reports and screenshots as artifacts, and keep secrets in CI variables. Fail the job on test failures and cap runtime with timeouts.
CI is a different environment from a developer laptop: no display, fresh filesystem, limited CPU and network latency to the application. The pipeline must supply a browser, a target URL and credentials, then preserve enough evidence to debug failures after the runner is gone.
name: e2e
on: [push]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
- run: mvn -B test
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports
path: target/surefire-reports- Use headless browsers or a Grid rather than expecting a display server
- Pin browser and driver versions so CI does not change underneath the suite
- Provide the application URL and credentials through environment variables or secrets
- Always upload reports and screenshots, including on failure
- Set a job timeout so a hung browser cannot block the queue indefinitely
- Shard or parallelise only after the suite is stable
A common CI failure is a test that assumes a local service or a developer's data. Start the application or point at a dedicated test environment explicitly, and wait for its health check before running tests. Network latency in CI is often higher than locally, so timeouts must reflect that environment.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why do artifacts need to upload even when tests fail?
- 2How do you handle secrets in a Selenium pipeline?
- 3Why pin browser versions in CI?
- 4When would you shard a Selenium suite?
Say it in the interview
I run headless or against Grid, pin browser and driver versions, and pass the environment and credentials through CI variables. Reports, screenshots and logs upload even on failure so the run can be triaged after the runner is gone. I set a job timeout and wait for an application health check before starting tests. Sharding comes only after the suite is stable, because parallelism amplifies existing flakiness.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Selenium mock interview and get scored feedback on depth, clarity and confidence.