0
0
Selenium Javatesting~8 mins

GitHub Actions configuration in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - GitHub Actions configuration
Folder Structure
selenium-java-project/
├── src/
│   └── test/
│       └── java/
│           └── com/
│               └── example/
│                   ├── pages/
│                   │   └── LoginPage.java
│                   ├── tests/
│                   │   └── LoginTest.java
│                   └── utils/
│                       └── WebDriverFactory.java
├── testng.xml
├── pom.xml
├── .github/
│   └── workflows/
│       └── selenium-tests.yml
└── README.md
Test Framework Layers
  • Driver Layer: WebDriverFactory.java manages browser driver setup and teardown.
  • Page Objects: Classes in pages/ represent UI pages with locators and actions (e.g., LoginPage.java).
  • Test Layer: Test classes in tests/ contain test methods using TestNG annotations.
  • Utilities: Helper classes for common functions like waits, logging, or config reading.
  • Configuration: testng.xml defines test suites and groups.
  • CI/CD Integration: GitHub Actions workflow file triggers tests on code push or pull requests.
Configuration Patterns
  • Environment Variables: Use GitHub Actions secrets for sensitive data like credentials.
  • Browser Selection: Parameterize browser choice in WebDriverFactory using system properties or environment variables.
  • TestNG XML: Define test suites and parallel execution settings.
  • GitHub Actions Workflow: Use matrix strategy to run tests on multiple browsers or Java versions.
name: Selenium Java Tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        browser: [chrome, firefox]
        java-version: [17]
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java-version }}
      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: Run tests
        env:
          BROWSER: ${{ matrix.browser }}
          USERNAME: ${{ secrets.TEST_USERNAME }}
          PASSWORD: ${{ secrets.TEST_PASSWORD }}
        run: mvn clean test -Dbrowser=${{ matrix.browser }}
Test Reporting and CI/CD Integration
  • Use TestNG default reports and configure Maven Surefire plugin to generate XML reports.
  • Integrate Allure or ExtentReports for rich HTML reports (optional).
  • GitHub Actions uploads test results as artifacts or uses annotations to show failures inline.
  • Fail the workflow if tests fail to prevent merging broken code.
  • Schedule nightly runs or run on pull requests to ensure continuous quality.
Best Practices
  • Keep tests isolated and independent to run in any order.
  • Use explicit waits in page objects to handle dynamic elements.
  • Store sensitive data like credentials in GitHub Secrets, never in code.
  • Use matrix strategy in GitHub Actions to test multiple browsers and Java versions.
  • Keep workflow files simple and readable; document steps clearly.
Self Check

Where in this folder structure would you add a new page object class for a "Dashboard" page?

Key Result
Organize Selenium Java tests with clear layers and use GitHub Actions matrix to run cross-browser tests automatically.