Skip to main content

Running Tests in CI/CD Pipelines

Running your SHAFT tests in a CI/CD pipeline is straightforward. SHAFT's property system lets you override configuration from the command line.


Basic Pipeline Command

The simplest way to run SHAFT tests in any CI/CD system is with Maven:

Pipeline command
mvn -e test \
-DheadlessExecution=true \
-Dallure.automaticallyOpen=false \
-Dallure.generateArchive=true
PropertyWhy
headlessExecution=trueNo display available in CI — run the browser without a GUI
allure.automaticallyOpen=falseDo not try to open a browser to show the report
allure.generateArchive=trueGenerate a portable ZIP of the Allure report for artifact publishing

Create a custom.properties file with sensible defaults for CI, then override individual values from the CLI as needed:

src/main/resources/properties/custom.properties
# CI/CD defaults
headlessExecution=true
allure.automaticallyOpen=false
allure.generateArchive=true
retryMaximumNumberOfAttempts=2
createAnimatedGif=false
videoParams_recordVideo=false
info

Remember the property priority hierarchy: Code-based > CLI-based > File-based > Defaults.


GitHub Actions Example

.github/workflows/tests.yml
name: Run Tests
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Run tests
run: |
mvn -e test \
-DheadlessExecution=true \
-Dallure.automaticallyOpen=false \
-Dallure.generateArchive=true

- name: Upload Allure report
if: always()
uses: actions/upload-artifact@v4
with:
name: allure-report
path: allure-report-archive/

Jenkins Pipeline Example

Jenkinsfile
pipeline {
agent any
tools {
maven 'Maven-3.9'
jdk 'JDK-21'
}
stages {
stage('Test') {
steps {
sh '''
mvn -e test \
-DheadlessExecution=true \
-Dallure.automaticallyOpen=false \
-Dallure.generateArchive=true
'''
}
}
}
post {
always {
archiveArtifacts artifacts: 'allure-report-archive/**', allowEmptyArchive: true
}
}
}

Running Specific Tests

Use Maven Surefire parameters to control which tests run:

Run a specific test class
mvn test -Dtest=LoginTest
Run a specific method
mvn test -Dtest=LoginTest#testValidLogin
Run all tests in a package
mvn test -Dtest="com.example.tests.**"

Parameterizing for Multiple Environments

Use CI/CD pipeline variables to switch between environments:

Parameterized execution
mvn test \
-DbaseURL=${TARGET_URL} \
-DtargetBrowserName=${BROWSER} \
-DexecutionAddress=${GRID_URL} \
-DtargetOperatingSystem=${OS}

This lets you run the same test suite against staging, production, or different browser/OS combinations by changing pipeline variables.


Best Practices

  1. Always use headless mode in pipelines — there is no display server.
  2. Disable auto-opening reports — set allure.automaticallyOpen=false.
  3. Generate report archives — use allure.generateArchive=true and publish them as pipeline artifacts.
  4. Set retry attemptsretryMaximumNumberOfAttempts=2 helps with flaky tests in CI environments.
  5. Parameterize everything — use CLI properties so the same test suite works across environments.
  6. Archive test artifacts — always upload reports and logs, even on failure (use if: always() in GitHub Actions or post { always { } } in Jenkins).