Skip to content

Run all tests

Run all tests #33

name: Run all tests
on:
workflow_dispatch:
push:
branches:
- main
- feature2
pull_request:
branches:
- main
- test-branch
schedule:
- cron: "0 7 * * 2" # Every Tuesday at 7:00 AM UTC (8:00 AM Zurich time during CET)
- cron: "0 7 * * 5" # Every Friday at 7:00 AM UTC (8:00 AM Zurich time during CET)
jobs:
test:
runs-on: ubuntu-latest
services:
selenium:
image: selenium/standalone-firefox:latest
ports:
- 4444:4444
options: >-
--shm-size 2g
steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
# Step 3: Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-html
# Step 4: Run pytest tests
- name: Run Selenium tests
env:
SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub
OBI_USERNAME: ${{ secrets.OBI_USERNAME }}
OBI_PASSWORD: ${{ secrets.OBI_PASSWORD }}
BROWSER_NAME: firefox
run: |
mkdir -p latest_logs/errors
pytest tests/ -sv --headless --html=latest_logs/report.html --self-contained-html
# Step 5: Upload screenshots as artifacts
- name: Upload error screenshots
if: failure() # Only upload if the job fails
uses: actions/upload-artifact@v3
with:
name: error-screenshots
path: latest_logs/errors/
# Step 6: Upload HTML test report
- name: Upload test report
uses: actions/upload-artifact@v3
with:
name: test-report
path: latest_logs/report.html
# Step 7: Slack notification on success
- name: Notify Slack on Success
if: success()
env:
SLACK_WEBHOOK_URL_PASS: ${{ secrets.SLACK_WEBHOOK_URL_PASS }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\":white_check_mark: Test pipeline succeeded in *${{ github.repository }}*. Branch: *${{ github.ref_name }}*\", \"username\":\"GitHub Actions\", \"icon_emoji\":\":rocket:\"}" \
$SLACK_WEBHOOK_URL_PASS
# Step 8: Slack notification on failure
- name: Notify Slack on Failure
if: failure()
env:
SLACK_WEBHOOK_URL_FAIL: ${{ secrets.SLACK_WEBHOOK_URL_FAIL }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\":x: Test pipeline failed in *${{ github.repository }}*. Branch: *${{ github.ref_name }}*. Check the logs for details.\", \"username\":\"GitHub Actions\", \"icon_emoji\":\":warning:\"}" \
$SLACK_WEBHOOK_URL_FAIL