CI/CD Integration
Integrate the Playwright Java Framework into your CI/CD pipeline with GitHub Actions.
GitHub Actions
The framework includes a ready-to-use GitHub Actions workflow. The workflow file is located at:
.github/workflows/ci.yml
Workflow Features
The GitHub Actions workflow:
- Sets up Java environment
- Installs Playwright browsers
- Runs the test suite
- Publishes test reports
Example Workflow
Here's an example GitHub Actions workflow configuration:
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install Playwright browsers
run: |
mvn exec:java \
-Dexec.mainClass="com.microsoft.playwright.CLI" \
-Dexec.args="install --with-deps"
- name: Run tests
env:
DOMTREE_USER: ${{ secrets.DOMTREE_USER }}
DOMTREE_PASS: ${{ secrets.DOMTREE_PASS }}
DOMTREE_API_BASE: ${{ secrets.DOMTREE_API_BASE }}
run: mvn test
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: target/cucumber-reports/junit.xml
Setting Up Secrets
To use environment variables in CI/CD, add them as secrets in your repository:
- Go to your GitHub repository
- Navigate to Settings → Secrets → Actions
- Click New repository secret
- Add the following secrets:
DOMTREE_USER- Your test user emailDOMTREE_PASS- Your test user passwordDOMTREE_API_BASE- Your API base URL
Running Tests in CI/CD
The workflow automatically runs tests on:
- Push to main or develop branches
- Pull requests to main or develop branches
You can customise the trigger conditions in the workflow file.
Test Reports in CI/CD
Test reports are generated and can be:
- Published as artifacts
- Uploaded to test result dashboards
- Used for pull request status checks
Publishing Reports as Artifacts
Add this step to your workflow to publish HTML reports:
- name: Upload test reports
uses: actions/upload-artifact@v3
if: always()
with:
name: test-reports
path: target/cucumber-reports/
Other CI/CD Platforms
The framework can be integrated with other CI/CD platforms:
Jenkins
Use the Maven plugin and configure environment variables in Jenkins:
pipeline {
agent any
environment {
DOMTREE_USER = credentials('domtree-user')
DOMTREE_PASS = credentials('domtree-pass')
DOMTREE_API_BASE = 'https://api.domtree.com'
}
stages {
stage('Test') {
steps {
sh 'mvn clean test'
}
}
}
post {
always {
junit 'target/cucumber-reports/junit.xml'
}
}
}
Azure DevOps
Use the Maven task and configure variables:
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'test'
env:
DOMTREE_USER: $(domtree-user)
DOMTREE_PASS: $(domtree-pass)
DOMTREE_API_BASE: $(domtree-api-base)
- task: PublishTestResults@2
inputs:
testResultsFiles: 'target/cucumber-reports/junit.xml'
Best Practices
- Always use secrets for sensitive credentials
- Cache Maven dependencies to speed up builds
- Run tests in parallel when possible
- Publish test reports for visibility
- Set up notifications for test failures