Q30 of 37 · Selenium

How would you integrate Selenium tests into a Jenkins pipeline with reporting?

SeleniumSeniorseleniumjenkinscireportingsenior

Short answer

Short answer: Declarative Jenkinsfile with stages: checkout → build → start Grid → run TestNG → publish results. Allure or Extent for reports, JUnit XML for trend tracking, screenshots/videos as build artifacts. Notify Slack/Teams on failure with a deep-link to the report.

Detail

The pipeline shape I'd write:

pipeline {
    agent any
    parameters {
        choice(name: 'BROWSER', choices: ['chrome', 'firefox'], description: '')
        choice(name: 'SUITE',   choices: ['smoke', 'regression'], description: '')
    }
    options {
        timeout(time: 60, unit: 'MINUTES')
        timestamps()
    }
    stages {
        stage('Checkout')      { steps { checkout scm } }
        stage('Build')         { steps { sh 'mvn clean compile -q' } }
        stage('Start Grid')    { steps { sh 'docker compose up -d' } }
        stage('Test') {
            steps {
                sh "mvn test -Dbrowser=${BROWSER} -DsuiteXmlFile=${SUITE}.xml"
            }
        }
    }
    post {
        always {
            sh 'docker compose down'
            junit 'target/surefire-reports/*.xml'
            allure includeProperties: false, results: [[path: 'target/allure-results']]
            archiveArtifacts artifacts: 'target/screenshots/**/*.png', allowEmptyArchive: true
        }
        failure {
            slackSend channel: '#qa-alerts',
                color: 'danger',
                message: "E2E failed on ${env.BUILD_URL}allure"
        }
    }
}

The reporting layers:

  • JUnit XML (Surefire emits this automatically) — feeds Jenkins' built-in test trend graph. Cheap, ubiquitous, gives you "tests added/removed/regressed" over time.
  • Allure — rich HTML report with screenshots, videos, history, and tags. Best for QA engineers and EM-level stakeholders.
  • Extent — Java-native alternative, also good. Pick one, not both.

Artifacts:

  • Screenshots on failure (always).
  • Videos for failed flows (optional — ffmpeg recording, or Grid 4's video container).
  • HAR files for failures involving network (Network.enable via CDP, dump on failure).

Notifications:

  • Failure → Slack or Teams with a deep-link to the Allure report.
  • First success after failure → "back to green" notice — disproportionately motivating.
  • Don't spam on every passing run; Jenkins' email-on-failure is enough.

Trends to track over time:

  • Pass rate per suite per branch.
  • Median + p95 runtime.
  • Top-10 flakiest tests (rerun-required count).

What I'd push back on: a single pipeline that runs the full regression on every PR. Smoke on PRs, regression on main / nightly is the standard split. Long PR pipelines kill developer velocity faster than any test ever catches a regression.

// WHAT INTERVIEWERS LOOK FOR

Pipeline-as-code, both JUnit (trends) + Allure (rich report), screenshots-as-artifacts, and the wisdom of running smoke-on-PR / regression-on-main rather than full suite every PR.

// COMMON PITFALL

Running the full regression suite on every PR. The 30-minute pipeline becomes culturally 'optional,' devs merge around it, and the value collapses. Tier the pipelines by trigger.