Skip to content

02loveslollipop-14188188905-push-react-app-test-selenium-ci #3

02loveslollipop-14188188905-push-react-app-test-selenium-ci

02loveslollipop-14188188905-push-react-app-test-selenium-ci #3

#This workflow test the react app with selenium using python to run the selenium tests
name: React App Test with Selenium
description: This workflow tests the react app with selenium using python to run the selenium tests
run-name: "${{ github.actor }}-${{ github.run_id }}-${{ github.event_name }}-react-app-test-selenium-ci"
# concurrency:
# group: default #limit concurrency to one job at a time (priority to the latest job)
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
# sonarcloud:
# runs-on: ubuntu-latest
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# permissions:
# contents: read
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: SonarCloud Scan
# uses: sonarsource/sonarcloud-github-action@master
# with:
# args: sonar-scanner -Dsonar.projectKey=your_project_key -Dsonar.organization=your_organization_name -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
selenium:
runs-on: ubuntu-latest
env:
APP_URL: http://localhost:3000
DISPLAY: :99
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Xvfb
run: |
sudo apt-get update
sudo apt-get install -y xvfb
Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: react/package-lock.json
- name: Install React dependencies
run: |
cd react
npm ci
- name: Build React app
run: |
cd react
npm run build
- name: Start React server
run: |
cd react
npm run preview -- --port 3000 &
# Allow time for the server to start up
sleep 10
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
cache: 'pip'
- name: Install Chrome
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update
sudo apt-get install -y google-chrome-stable
- name: Install ChromeDriver
run: |
CHROME_VERSION=$(google-chrome --version | awk '{print $3}' | cut -d. -f1)
wget -N https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION -O - | xargs -I{} wget -N https://chromedriver.storage.googleapis.com/{}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv chromedriver /usr/local/bin/
chromedriver --version
- name: Install Python dependencies
run: |
# Check if tests directory exists, if not create it
mkdir -p tests
cd tests
python -m pip install --upgrade pip
# Check if requirements.txt exists, if not create one
if [ ! -f requirements.txt ]; then
echo "pytest\nselenium\nwebdriver-manager" > requirements.txt
fi
pip install -r requirements.txt
- name: Run Selenium tests
run: |
cd tests
pytest -v test_home_page.py
env:
APP_URL: http://localhost:3000
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: tests/screenshots/
retention-days: 5