Run UI Tests with WebDriverManager #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run UI Tests with WebDriverManager | |
on: | |
# Trigger the workflow manually with custom inputs | |
workflow_dispatch: | |
inputs: | |
browser: | |
description: "Select the browser to run the tests on" | |
required: true | |
default: "chrome" # Default browser | |
type: string | |
options: | |
- chrome | |
- firefox | |
- edge | |
environment: | |
description: "Select the environment to run tests on" | |
required: true | |
default: "test" # Default environment | |
type: string | |
options: | |
- test | |
- stage | |
- prod | |
jobs: | |
ui-tests: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Install Chrome and dependencies | |
- name: Install Chrome | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y google-chrome-stable | |
sudo apt-get install -y xvfb | |
# Step 3: Start Xvfb (Virtual Display for GUI Testing) | |
- name: Start Xvfb | |
run: | | |
export DISPLAY=:99 | |
Xvfb :99 -screen 0 1920x1080x16 & | |
sleep 3 | |
# Step 4: Set up Java | |
- name: Set up Java 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'maven' | |
# Step 5: Cache Maven dependencies | |
- name: Cache Maven dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-maven | |
# Step 6: Debug Chrome Environment | |
- name: Debug Chrome Environment | |
run: | | |
google-chrome --version | |
chromedriver --version | |
echo $DISPLAY | |
# Step 7: Set Environment Variables from Inputs | |
- name: Set Environment Variables | |
run: | | |
echo "BROWSER=${{ github.event.inputs.browser }}" >> $GITHUB_ENV | |
echo "ENVIRONMENT=${{ github.event.inputs.environment }}" >> $GITHUB_ENV | |
# Step 8: Install Maven dependencies | |
- name: Install Maven dependencies | |
run: mvn install -DskipTests=true | |
# Step 9: Run Selenium UI Tests | |
- name: Run UI Tests | |
run: mvn test -Dbrowser=$BROWSER -Denvironment=$ENVIRONMENT | |
# Step 10: Upload Test Reports (Optional) | |
- name: Upload Test Reports | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-reports | |
path: target/surefire-reports/ |