Advanced
Chapter 19 · 12 min read
CI/CD Integration
Integrate Selenium tests into GitHub Actions, Jenkins, and GitLab CI pipelines. Run headless tests in Docker containers.
CI/CD Integration
Automated tests only deliver value when they run automatically. CI/CD integration triggers your Selenium suite on every code change, catches regressions early, and blocks broken code from reaching production.
.github/workflows/selenium.yml
# GitHub Actions — Java Selenium Tests
name: Selenium Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Install Chrome
uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
- name: Run Tests (headless)
run: |
mvn clean test \
-Dheadless=true \
-Dbrowser=chrome
- name: Generate Allure Report
if: always()
run: mvn allure:report
- name: Upload Report
uses: actions/upload-artifact@v4
if: always()
with:
name: allure-report
path: target/site/allure-maven-plugin/
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Selenium Results
path: target/surefire-reports/*.xml
reporter: java-junit
Jenkinsfile
pipeline {
agent any
tools {
maven 'Maven-3.9'
jdk 'JDK-17'
}
stages {
stage('Test') {
steps {
sh 'mvn clean test -Dheadless=true'
}
}
stage('Report') {
steps {
allure includeProperties: false,
results: [[path: 'target/allure-results']]
junit 'target/surefire-reports/*.xml'
}
}
}
post {
failure {
archiveArtifacts artifacts: 'screenshots/**',
allowEmptyArchive: true
}
}
}
.github/workflows/selenium.yml
# GitHub Actions — Python Selenium Tests
name: Selenium Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Chrome
uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Tests (headless)
run: |
pytest tests/ \
--headless \
--browser=chrome \
-n auto \
--html=reports/report.html \
--self-contained-html \
--junitxml=reports/junit.xml \
-v
- name: Upload Report
uses: actions/upload-artifact@v4
if: always()
with:
name: test-report-${{ matrix.python-version }}
path: reports/
- name: Publish Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Selenium (Python ${{ matrix.python-version }})
path: reports/junit.xml
reporter: java-junit
Dockerfile
# Dockerfile for running Selenium tests
FROM python:3.12-slim
# Install Chrome
RUN apt-get update && apt-get install -y \
wget gnupg2 \
&& wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/chrome.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["pytest", "tests/", "--headless", "--browser=chrome", "-n", "auto", "-v"]
Selenium
Advanced
CI/CD Integration
Written by PV
© 2026 All Rights Reserved