GitHub Actions configuration in Selenium Java - Build an Automation Script
name: Selenium Java Tests
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- 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 Maven tests
run: mvn clean test
This GitHub Actions workflow is named 'Selenium Java Tests'. It triggers on any push to the 'main' branch.
The job named 'build' runs on the latest Ubuntu runner.
First, it checks out the repository code using the official actions/checkout@v3 action.
Then, it sets up JDK 17 using actions/setup-java@v3 with the Temurin distribution, ensuring the correct Java version for the Selenium tests.
Next, it caches Maven dependencies located in ~/.m2/repository to speed up future builds, using the hash of the pom.xml file as the cache key.
Finally, it runs the Maven command mvn clean test to compile and execute the Selenium tests.
If the tests pass, the workflow completes successfully and the test results are visible in the GitHub Actions interface.
Now add data-driven testing with 3 different login credentials in your Selenium Java tests and ensure the GitHub Actions workflow runs all test cases