Saturday, November 28, 2026

GitHub Actions CI/CD Pipeline for Java, Selenium Java, Python, and Playwright Projects

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:

  1. Java Maven project (JUnit / TestNG).
  2. Selenium Java automation project.
  3. Python automation project (Pytest).
  4. Playwright automation project (JavaScript / TypeScript).
GitHub Actions CI/CD Pipeline for Java, Selenium Java, Python, and Playwright Projects



1. GitHub Actions Architecture

Typical CI/CD execution flow:

  1. Developer pushes code to GitHub.
  2. GitHub Actions detects the push or pull request.
  3. Workflow starts on a GitHub-hosted runner.
  4. Required dependencies are installed.
  5. Automated test cases are executed.
  6. Test reports are generated.
  7. Reports are uploaded as workflow artifacts.
  8. 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

CommandDescription
mvn cleanRemoves previous build files.
mvn compileCompiles Java source.
mvn testExecutes unit tests.
mvn packageCreates JAR/WAR.
mvn verifyRuns verification lifecycle.
mvn clean verifyCleans, 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

CommandDescription
pytest -vVerbose execution.
pytest -sDisplay print statements.
pytest -n 4Parallel execution using xdist.
pytest -m smokeExecute smoke tests.
pytest --junitxml=report.xmlGenerate JUnit XML.
pytest --html=report.htmlGenerate HTML report.
pytest --cov=srcGenerate 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

JobBrowser
Job 1Chromium
Job 2Firefox
Job 3WebKit

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 NamePurpose
TEST_USERNAMEApplication login.
TEST_PASSWORDApplication password.
API_TOKENAPI authentication.
BASE_URLTest 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

FrameworkReport Location
Java JUnittarget/surefire-reports/
Selenium TestNGtarget/surefire-reports/ or test-output/
Python Pytestreports/
Playwrightplaywright-report/
Playwright tracestest-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

  1. Open your GitHub repository.
  2. Select the Actions tab.
  3. Open the workflow execution.
  4. Scroll to the Artifacts section.
  5. Download the required report.

12. Publish Test Reports Using GitHub Pages

You can also publish HTML reports using GitHub Pages.

  1. Generate the HTML report.
  2. Copy the report into a deployment directory.
  3. Upload the directory as a Pages artifact.
  4. 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

FeatureContinuous Integration (CI)Continuous Delivery / Deployment (CD)
Code checkoutYesYes
Compile applicationYesYes
Execute unit testsYesYes
Execute automation testsYesYes
Generate reportsYesYes
Build application packageYesYes
Deploy applicationNot necessarilyYes
Production releaseNoDepending on configuration

Example CI/CD Execution Flow

  1. Developer pushes code to GitHub.
  2. GitHub Actions CI Pipeline starts.
  3. Java tests execute using Maven and TestNG.
  4. Selenium tests execute using Java and Chrome.
  5. Python tests execute using Pytest.
  6. Playwright tests execute using Node.js and browsers.
  7. Test reports and build artifacts are generated.
  8. Application is deployed to QA, staging, or production.

14. Best Practices for Automation CI/CD

  1. Use separate workflows for Java, Selenium, Python, and Playwright.
  2. Use dependency caching to reduce execution time.
  3. Use matrix strategies for cross-browser and multi-version testing.
  4. Store credentials in GitHub Secrets.
  5. Execute independent jobs in parallel.
  6. Generate JUnit XML and HTML reports.
  7. Upload reports even when tests fail.
  8. Use headless browser execution in CI.
  9. Configure retry mechanisms carefully to avoid hiding flaky tests.
  10. Use branch protection rules to require successful CI checks before merging.
  11. Pin third-party GitHub Actions to verified commit SHAs for stronger supply-chain security.
  12. Use separate workflows or deployment jobs for QA, staging, and production.

15. Common GitHub Actions Commands

CommandPurpose
actions/checkoutCheckout repository.
actions/setup-javaInstall Java.
actions/setup-pythonInstall Python.
actions/setup-nodeInstall Node.js.
actions/upload-artifactUpload reports and files.
actions/download-artifactDownload artifacts.
actions/cacheCache dependencies.
runExecute shell commands.
usesExecute an action.
needsDefine job dependencies.
if: always()Execute even after previous failure.
strategy.matrixRun multiple configurations.
workflow_dispatchManually trigger a workflow.

16. Official Documentation

17. Recommended Pipeline Structure

For a real-world automation testing framework, the following arrangement is recommended:

ProjectBuild ToolTest FrameworkCI Execution
JavaMavenTestNG / JUnitmvn clean verify
Selenium JavaMavenTestNGmvn clean test
PythonpipPytestpytest -v
PlaywrightnpmPlaywright Testnpx 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