GitHub Actions CI/CD Pipeline for Java, Selenium Java, Python, and Playwright Projects
GitHub Actions is a CI/CD automation platform that allows you to build, test, validate, and deploy applications automatically whenever code is pushed to GitHub or a pull request is created.
This guide covers four different automation testing projects:
- Java Maven project (JUnit / TestNG).
- Selenium Java automation project.
- Python automation project (Pytest).
- Playwright automation project (JavaScript / TypeScript).
1. GitHub Actions Architecture
Typical CI/CD execution flow:
- Developer pushes code to GitHub.
- GitHub Actions detects the push or pull request.
- Workflow starts on a GitHub-hosted runner.
- Required dependencies are installed.
- Automated test cases are executed.
- Test reports are generated.
- Reports are uploaded as workflow artifacts.
- Workflow displays the execution status.
2. GitHub Actions Project Structure
You can maintain all four automation projects in a single GitHub repository or use separate repositories.
automation-frameworks/
│
├── .github/
│ └── workflows/
│ ├── java-ci.yml
│ ├── selenium-java-ci.yml
│ ├── python-ci.yml
│ └── playwright-ci.yml
│
├── java-project/
│ ├── pom.xml
│ └── src/
│
├── selenium-java/
│ ├── pom.xml
│ └── src/
│
├── python-project/
│ ├── requirements.txt
│ ├── pytest.ini
│ └── tests/
│
└── playwright-project/
├── package.json
├── package-lock.json
├── playwright.config.ts
└── tests/
3. Java Project GitHub Actions Pipeline
Prerequisites
- Java JDK.
- Maven.
- JUnit or TestNG.
- GitHub repository.
Create the following file: .github/workflows/java-ci.yml
name: Java CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
jobs:
java-build:
name: Java Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout Source Code
uses: actions/checkout@v7
- name: Set up JDK
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '21'
cache: maven
- name: Verify Java Version
run: java --version
- name: Verify Maven Version
run: mvn --version
- name: Build and Execute Tests
working-directory: java-project
run: mvn clean verify
- name: Upload Maven Reports
if: always()
uses: actions/upload-artifact@v5
with:
name: java-test-reports
path: java-project/target/surefire-reports/
if-no-files-found: ignore
retention-days: 7
Important Maven Commands
| Command | Description |
|---|---|
mvn clean | Removes previous build files. |
mvn compile | Compiles Java source. |
mvn test | Executes unit tests. |
mvn package | Creates JAR/WAR. |
mvn verify | Runs verification lifecycle. |
mvn clean verify | Cleans, builds and verifies. |
For TestNG projects, configure the Maven Surefire Plugin in pom.xml to execute your TestNG tests.
4. Selenium Java GitHub Actions Pipeline
Prerequisites
- Java JDK.
- Maven dependencies.
- Selenium WebDriver.
- Chrome browser.
- ChromeDriver or Selenium Manager.
- TestNG or JUnit.
Example Selenium Test
File: src/test/java/tests/GoogleTest.java
package tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class GoogleTest {
@Test
public void verifyGoogleTitle() {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://www.google.com");
String title = driver.getTitle();
System.out.println("Page Title: " + title);
Assert.assertTrue(title.contains("Google"));
} finally {
driver.quit();
}
}
}
GitHub Actions Workflow
Create .github/workflows/selenium-java-ci.yml.
name: Selenium Java CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
jobs:
selenium-tests:
name: Selenium Java Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v7
- name: Setup Java
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '21'
cache: maven
- name: Setup Chrome
uses: browser-actions/setup-chrome@v2
- name: Verify Browser
run: google-chrome --version
- name: Verify Java
run: java --version
- name: Run Selenium Tests
working-directory: selenium-java
run: mvn clean test
- name: Upload Selenium Test Reports
if: always()
uses: actions/upload-artifact@v5
with:
name: selenium-test-reports
path: |
selenium-java/target/surefire-reports/
selenium-java/test-output/
if-no-files-found: ignore
retention-days: 7
Headless Chrome Configuration
In CI environments, headless execution is generally preferred.
import org.openqa.selenium.chrome.ChromeOptions;
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--window-size=1920,1080");
WebDriver driver = new ChromeDriver(options);
Use ChromeDriver with Selenium Manager to manage the compatible driver automatically in supported environments.
5. Python Pytest GitHub Actions Pipeline
Prerequisites
- Python.
- Pytest.
- Required Python packages.
- Optional: pytest-html and pytest-cov.
Example Project Structure
python-project/
│
├── requirements.txt
├── pytest.ini
├── src/
│ └── calculator.py
└── tests/
└── test_calculator.py
requirements.txt
pytest
pytest-html
pytest-cov
requests
Example Test
File: tests/test_calculator.py
def add(a, b):
return a + b
def test_addition():
assert add(10, 20) == 30
def test_subtraction():
assert 20 - 10 == 10
def test_multiplication():
assert 5 * 5 == 25
GitHub Actions Workflow
Create .github/workflows/python-ci.yml.
name: Python Pytest CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
jobs:
python-tests:
name: Python Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12', '3.13']
steps:
- name: Checkout Code
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: python-project/requirements.txt
- name: Install Dependencies
working-directory: python-project
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Verify Python
run: python --version
- name: Create Reports Directory
working-directory: python-project
run: mkdir -p reports
- name: Execute Pytest
working-directory: python-project
run: |
pytest tests/ \
-v \
--junitxml=reports/junit.xml \
--html=reports/report.html \
--self-contained-html \
--cov=src \
--cov-report=xml:reports/coverage.xml
- name: Upload Pytest Reports
if: always()
uses: actions/upload-artifact@v5
with:
name: python-reports-${{ matrix.python-version }}
path: python-project/reports/
if-no-files-found: ignore
retention-days: 7
Pytest Commands Used in CI
| Command | Description |
|---|---|
pytest -v | Verbose execution. |
pytest -s | Display print statements. |
pytest -n 4 | Parallel execution using xdist. |
pytest -m smoke | Execute smoke tests. |
pytest --junitxml=report.xml | Generate JUnit XML. |
pytest --html=report.html | Generate HTML report. |
pytest --cov=src | Generate coverage information. |
6. Playwright JavaScript GitHub Actions Pipeline
Prerequisites
- Node.js.
- npm dependencies.
- Playwright test runner.
- Browser binaries.
- Operating system dependencies.
Example Project Structure
playwright-project/
│
├── package.json
├── package-lock.json
├── playwright.config.ts
│
└── tests/
├── login.spec.ts
├── home.spec.ts
└── api.spec.ts
package.json
{
"name": "playwright-automation",
"version": "1.0.0",
"scripts": {
"test": "npx playwright test",
"test:headed": "npx playwright test --headed",
"test:chromium": "npx playwright test --project=chromium",
"test:firefox": "npx playwright test --project=firefox",
"test:webkit": "npx playwright test --project=webkit",
"report": "npx playwright show-report"
},
"devDependencies": {
"@playwright/test": "^1.55.0"
}
}
Use a current, compatible Playwright version in your project and commit package-lock.json.
playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 4 : undefined,
reporter: [
['list'],
['html', { open: 'never' }],
['junit', { outputFile: 'test-results/junit.xml' }]
],
use: {
baseURL: 'https://www.google.com',
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'retain-on-failure'
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
}
]
});
Example Playwright Test
File: tests/home.spec.ts
import { test, expect } from '@playwright/test';
test('Verify Google homepage', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Google/);
await expect(
page.locator('body')
).toBeVisible();
});
GitHub Actions Workflow
Create .github/workflows/playwright-ci.yml.
name: Playwright JavaScript CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
jobs:
playwright-tests:
name: Playwright Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v7
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: playwright-project/package-lock.json
- name: Install Dependencies
working-directory: playwright-project
run: npm ci
- name: Install Playwright Browsers
working-directory: playwright-project
run: npx playwright install --with-deps
- name: Verify Playwright Version
working-directory: playwright-project
run: npx playwright --version
- name: Execute Playwright Tests
working-directory: playwright-project
run: npx playwright test
- name: Upload Playwright Reports
if: always()
uses: actions/upload-artifact@v5
with:
name: playwright-reports
path: |
playwright-project/playwright-report/
playwright-project/test-results/
if-no-files-found: ignore
retention-days: 7
The Playwright HTML report and test results are generated in the configured directories. The if: always() condition ensures artifacts can still be uploaded after a test failure.
Official reference: Playwright CI Documentation.
7. Run All Four Projects in Parallel
You can execute Java, Selenium Java, Python, and Playwright pipelines simultaneously instead of waiting for one project to finish before starting another.
Create .github/workflows/automation-suite.yml.
name: Complete Automation Test Suite
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
jobs:
java-tests:
name: Java Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '21'
cache: maven
- name: Execute Java Tests
working-directory: java-project
run: mvn clean verify
selenium-tests:
name: Selenium Java Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '21'
cache: maven
- uses: browser-actions/setup-chrome@v2
- name: Execute Selenium Tests
working-directory: selenium-java
run: mvn clean test
python-tests:
name: Python Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: Install Dependencies
working-directory: python-project
run: |
pip install -r requirements.txt
- name: Execute Python Tests
working-directory: python-project
run: pytest -v
playwright-tests:
name: Playwright Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: '22'
- name: Install Dependencies
working-directory: playwright-project
run: npm ci
- name: Install Browsers
working-directory: playwright-project
run: npx playwright install --with-deps
- name: Execute Playwright Tests
working-directory: playwright-project
run: npx playwright test
Parallel execution: All four jobs start independently. If one job fails, the other jobs can continue.
8. Execute Tests Using Matrix Strategy
A matrix strategy allows you to execute the same test suite using multiple versions of Java, Python, browsers, or operating systems.
Example 1: Java Version Matrix
jobs:
java-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java-version: ['17', '21', '25']
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: ${{ matrix.java-version }}
cache: maven
- name: Run Tests
run: mvn clean test
Example 2: Python Version Matrix
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12', '3.13']
Example 3: Playwright Browser Matrix
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: '22'
- run: npm ci
working-directory: playwright-project
- run: npx playwright install --with-deps ${{ matrix.browser }}
working-directory: playwright-project
- run: npx playwright test --project=${{ matrix.browser }}
working-directory: playwright-project
Browser Matrix Execution
| Job | Browser |
|---|---|
| Job 1 | Chromium |
| Job 2 | Firefox |
| Job 3 | WebKit |
This approach creates three separate jobs.
9. GitHub Actions Workflow Triggers
You can control when your automation pipeline should execute.
1. Push Trigger
on:
push:
branches:
- main
- develop
Executes whenever code is pushed to the specified branches.
2. Pull Request Trigger
on:
pull_request:
branches:
- main
Executes when a pull request targets the main branch.
3. Manual Execution
on:
workflow_dispatch:
Allows you to manually execute a workflow from GitHub Actions.
4. Scheduled Execution
on:
schedule:
- cron: '0 2 * * *'
Executes daily at 02:00 UTC.
5. Execute Only When Specific Files Change
on:
push:
paths:
- 'playwright-project/**'
- '.github/workflows/playwright-ci.yml'
This is useful in a monorepository because changes to one project do not need to trigger every project pipeline.
10. Store Credentials Using GitHub Secrets
Never hardcode usernames, passwords, API keys, access tokens, or database credentials in workflow files.
Navigate to:
GitHub Repository > Settings > Secrets and variables > Actions
Example Secrets
| Secret Name | Purpose |
|---|---|
TEST_USERNAME | Application login. |
TEST_PASSWORD | Application password. |
API_TOKEN | API authentication. |
BASE_URL | Test environment URL. |
Access Secrets Inside Workflows
- name: Execute Tests
run: mvn clean test
env:
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
BASE_URL: ${{ secrets.BASE_URL }}
Access Secrets from Java
String username = System.getenv("TEST_USERNAME");
String password = System.getenv("TEST_PASSWORD");
Access Secrets from Python
import os
username = os.getenv("TEST_USERNAME")
password = os.getenv("TEST_PASSWORD")
Access Secrets from Playwright
const username = process.env.TEST_USERNAME;
const password = process.env.TEST_PASSWORD;
11. Generate and Download Execution Reports
GitHub Actions supports uploading execution reports as artifacts.
Report Locations
| Framework | Report Location |
|---|---|
| Java JUnit | target/surefire-reports/ |
| Selenium TestNG | target/surefire-reports/ or test-output/ |
| Python Pytest | reports/ |
| Playwright | playwright-report/ |
| Playwright traces | test-results/ |
Upload an Artifact
- name: Upload Test Reports
if: always()
uses: actions/upload-artifact@v5
with:
name: automation-test-reports
path: |
java-project/target/surefire-reports/
selenium-java/target/surefire-reports/
python-project/reports/
playwright-project/playwright-report/
if-no-files-found: ignore
retention-days: 7
Download Reports
- Open your GitHub repository.
- Select the Actions tab.
- Open the workflow execution.
- Scroll to the Artifacts section.
- Download the required report.
12. Publish Test Reports Using GitHub Pages
You can also publish HTML reports using GitHub Pages.
- Generate the HTML report.
- Copy the report into a deployment directory.
- Upload the directory as a Pages artifact.
- Deploy it using the GitHub Pages deployment actions.
This requires configuring GitHub Pages and appropriate deployment permissions. Avoid publishing reports containing credentials, personal information, or confidential test data.
13. CI vs CD Pipeline
| Feature | Continuous Integration (CI) | Continuous Delivery / Deployment (CD) |
|---|---|---|
| Code checkout | Yes | Yes |
| Compile application | Yes | Yes |
| Execute unit tests | Yes | Yes |
| Execute automation tests | Yes | Yes |
| Generate reports | Yes | Yes |
| Build application package | Yes | Yes |
| Deploy application | Not necessarily | Yes |
| Production release | No | Depending on configuration |
Example CI/CD Execution Flow
- Developer pushes code to GitHub.
- GitHub Actions CI Pipeline starts.
- Java tests execute using Maven and TestNG.
- Selenium tests execute using Java and Chrome.
- Python tests execute using Pytest.
- Playwright tests execute using Node.js and browsers.
- Test reports and build artifacts are generated.
- Application is deployed to QA, staging, or production.
14. Best Practices for Automation CI/CD
- Use separate workflows for Java, Selenium, Python, and Playwright.
- Use dependency caching to reduce execution time.
- Use matrix strategies for cross-browser and multi-version testing.
- Store credentials in GitHub Secrets.
- Execute independent jobs in parallel.
- Generate JUnit XML and HTML reports.
- Upload reports even when tests fail.
- Use headless browser execution in CI.
- Configure retry mechanisms carefully to avoid hiding flaky tests.
- Use branch protection rules to require successful CI checks before merging.
- Pin third-party GitHub Actions to verified commit SHAs for stronger supply-chain security.
- Use separate workflows or deployment jobs for QA, staging, and production.
15. Common GitHub Actions Commands
| Command | Purpose |
|---|---|
actions/checkout | Checkout repository. |
actions/setup-java | Install Java. |
actions/setup-python | Install Python. |
actions/setup-node | Install Node.js. |
actions/upload-artifact | Upload reports and files. |
actions/download-artifact | Download artifacts. |
actions/cache | Cache dependencies. |
run | Execute shell commands. |
uses | Execute an action. |
needs | Define job dependencies. |
if: always() | Execute even after previous failure. |
strategy.matrix | Run multiple configurations. |
workflow_dispatch | Manually trigger a workflow. |
16. Official Documentation
17. Recommended Pipeline Structure
For a real-world automation testing framework, the following arrangement is recommended:
| Project | Build Tool | Test Framework | CI Execution |
|---|---|---|---|
| Java | Maven | TestNG / JUnit | mvn clean verify |
| Selenium Java | Maven | TestNG | mvn clean test |
| Python | pip | Pytest | pytest -v |
| Playwright | npm | Playwright Test | npx playwright test |
Recommendation: Start with four independent CI workflows. Once each workflow works reliably, create a master workflow that coordinates all four projects, collects reports, and deploys the application to the QA environment after successful execution.
One important distinction: the examples above are CI pipelines. To make them complete CD pipelines, add application build and deployment steps using your hosting platform or deployment environment.

No comments:
Post a Comment