Selenium · Browser automation foundations

How do you run Selenium suites reliably in CI?

MediumciheadlessartifactsUpdated Oct 2026
Quiz this track

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.

yaml
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
Artifacts are uploaded even when tests fail, which is when they matter.
  • 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.

Do not print secrets in logs or bake them into test artifacts. Mask CI variables and keep credentials out of screenshots and request dumps.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why do artifacts need to upload even when tests fail?
  2. 2How do you handle secrets in a Selenium pipeline?
  3. 3Why pin browser versions in CI?
  4. 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.