Run all tests #45
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 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: | |
setup-environments: | |
runs-on: ubuntu-latest | |
outputs: | |
artifact_path: latest_logs/ | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Set up virtual environment | |
run: | | |
python -m venv venv | |
# On Windows use `venv\Scripts\activate` | |
# On Linux/macOS use `source venv/bin/activate` | |
source venv/bin/activate | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest-html | |
- name: Install required dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get upgrade | |
# - name: Set up Chrome and ChromeDriver | |
# uses: browser-actions/setup-chrome@v1 | |
# with: | |
# chrome-version: 120 | |
# install-chromedriver: true | |
# install-dependencies: true | |
# Set up Firefox and GeckoDriver | |
- name: Set up Firefox and GeckoDriver | |
uses: browser-actions/setup-firefox@v1 | |
with: | |
firefox-version: 'latest' # You can specify a specific version or 'latest' | |
install-geckodriver: true | |
install-dependencies: true | |
# Optionally, set environment variables for Firefox | |
- name: Set Firefox environment variables | |
run: | | |
echo "GECKODRIVER_PATH=/usr/local/bin/geckodriver" >> $GITHUB_ENV | |
echo "BROWSER=firefox" >> $GITHUB_ENV | |
- name: Prepare logs directory | |
run: mkdir -p latest_logs | |
test-production: | |
needs: setup-environments | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
browser: [chrome, firefox] | |
environment: production | |
steps: | |
- name: Use shared setup | |
run: echo "Reusing setup from setup-environments job" | |
- name: Run tests for production | |
env: | |
BASE_URL: ${{ vars.PRODUCTION_URL }} | |
run: | | |
pytest --env=production --env_url=${{ vars.PRODUCTION_URL }} tests/test_login.py -sv --headless \ | |
--html=latest_logs/report_production_${{ matrix.browser }}.html \ | |
--self-contained-html --browser-name=${{ matrix.browser }} | |
- name: Upload test report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-report-production-${{ matrix.browser }} | |
path: latest_logs/ | |
test-sauce-labs: | |
needs: test-production | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
browser: [chrome, firefox] | |
environment: sauce-labs | |
steps: | |
- name: Use shared setup | |
run: echo "Reusing setup from setup-environments job" | |
- name: Run tests for Sauce Labs | |
env: | |
BASE_URL: ${{ vars.SAUCE_LABS_URL }} | |
SELENIUM_REMOTE_URL: https://ondemand.eu-central-1.saucelabs.com:443/wd/hub | |
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} | |
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} | |
run: | | |
pytest --env=sauce-labs --env_url=${{ vars.SAUCE_LABS_URL }} tests/test_login.py -sv --headless \ | |
--html=latest_logs/report_sauce_labs_${{ matrix.browser }}.html \ | |
--self-contained-html --sauce-labs --browser-name=${{ matrix.browser }} | |
- name: Upload Sauce Labs test report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-report-sauce-labs-${{ matrix.browser }} | |
path: latest_logs/ | |
test-staging: | |
needs: test-sauce-labs | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
browser: [chrome, firefox] | |
environment: staging | |
steps: | |
- name: Use shared setup | |
run: echo "Reusing setup from setup-environments job" | |
- name: Run tests for staging | |
env: | |
BASE_URL: ${{ vars.STAGING_URL }} | |
run: | | |
pytest --env=staging --env_url=${{ vars.STAGING_URL }} tests/test_login.py -sv --headless \ | |
--html=latest_logs/report_staging_${{ matrix.browser }}.html \ | |
--self-contained-html --browser-name=${{ matrix.browser }} | |
- name: Upload Staging test report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-report-staging-${{ matrix.browser }} | |
path: latest_logs/ | |
# - 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/ | |
# | |
# - 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 |