Skip to content

Add automated test coverage for newly added development and CDS Add Model flow #24

Add automated test coverage for newly added development and CDS Add Model flow

Add automated test coverage for newly added development and CDS Add Model flow #24

Workflow file for this run

name: Parakh Test Suite — CI
on:
push:
branches: [main, dev, develop]
pull_request:
branches: [main]
workflow_dispatch:
env:
# ── Platform URLs (configure as repo variables: Settings → Variables → Actions) ──
# Default targets the dev environment; override via vars.BASE_URL /
# vars.GRAPHQL_URL / vars.ENVIRONMENT to point at staging or prod.
BASE_URL: ${{ vars.BASE_URL || 'https://dev.parakh.civicdataspace.in' }}
GRAPHQL_URL: ${{ vars.GRAPHQL_URL || 'https://dev.api.parakh.civicdataspace.in/graphql/' }}
ENVIRONMENT: ${{ vars.ENVIRONMENT || 'development' }}
BROWSER: chromium
HEADLESS: "true"
SLOW_MO: "0"
VIEWPORT_WIDTH: "1440"
VIEWPORT_HEIGHT: "900"
SCREENSHOT_ON_FAILURE: "true"
VISUAL_THRESHOLD: "0.2"
PYTHON_VERSION: "3.11"
# ── Auth secrets (add these in GitHub → Settings → Secrets → Actions) ────────
# Tests using the `authenticated_page` fixture skip gracefully when unset.
# Set TEST_USER_INDEX=2 in the second parallel job to use a separate account.
TEST_EMAIL_1: ${{ secrets.TEST_EMAIL_1 }}
TEST_PASSWORD_1: ${{ secrets.TEST_PASSWORD_1 }}
TEST_EMAIL_2: ${{ secrets.TEST_EMAIL_2 }}
TEST_PASSWORD_2: ${{ secrets.TEST_PASSWORD_2 }}
TEST_USER_INDEX: "1"
SANDBOX_ORG_SLUG: ${{ secrets.SANDBOX_ORG_SLUG }}
jobs:
# ────────────────────────────────────────────── Lint
lint:
name: Lint (ruff)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install ruff
run: pip install ruff
- name: Run ruff linter
run: ruff check locators/ pages/ utils/ tests/ --output-format=github
# ────────────────────────────────────────────── API tests (no browser)
api-tests:
name: API Tests
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run API tests
continue-on-error: true
run: |
pytest tests/api/ \
-v \
--tb=short \
--html=reports/api_report.html \
--self-contained-html \
-m api
- name: Upload API test report
if: always()
uses: actions/upload-artifact@v7
with:
name: api-test-report
path: reports/api_report.html
retention-days: 30
# ────────────────────────────────────────────── E2E tests (3-shard matrix)
e2e-tests:
name: E2E Tests (shard ${{ matrix.shard }}/${{ strategy.job-total }})
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Install Playwright browsers
run: playwright install --with-deps chromium
- name: Run E2E tests (shard ${{ matrix.shard }}/3)
continue-on-error: true
run: |
pytest tests/e2e/ \
-n 2 \
-v \
--tb=short \
--json-report \
--json-report-file=reports/e2e_shard_${{ matrix.shard }}.json \
--html=reports/e2e_report_shard_${{ matrix.shard }}.html \
--self-contained-html \
-m e2e \
--reruns 2 \
--reruns-delay 3 \
--splits 3 \
--group ${{ matrix.shard }}
- name: Upload E2E shard report
if: always()
uses: actions/upload-artifact@v7
with:
name: e2e-shard-${{ matrix.shard }}
path: |
reports/e2e_report_shard_${{ matrix.shard }}.html
reports/e2e_shard_${{ matrix.shard }}.json
screenshots/
retention-days: 30
# ────────────────────────────────────────────── Accessibility tests
accessibility-tests:
name: Accessibility Tests (axe)
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Install Playwright browsers
run: playwright install --with-deps chromium
- name: Run accessibility tests
continue-on-error: true
run: |
pytest tests/accessibility/ \
-v \
--tb=short \
--html=reports/a11y_report.html \
--self-contained-html \
-m accessibility
- name: Upload accessibility reports
if: always()
uses: actions/upload-artifact@v7
with:
name: accessibility-report
path: |
reports/a11y_report.html
reports/accessibility_report.json
reports/accessibility_login_report.json
retention-days: 30
# ────────────────────────────────────────────── Visual regression tests
visual-tests:
name: Visual Regression Tests
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Install Playwright browsers
run: playwright install --with-deps chromium
# Restore cached baselines so we compare against a known good state
- name: Restore visual baselines cache
uses: actions/cache@v5
with:
path: snapshots/
key: visual-baselines-${{ runner.os }}-${{ hashFiles('tests/visual/**') }}
restore-keys: |
visual-baselines-${{ runner.os }}-
- name: Run visual regression tests
continue-on-error: true
run: |
pytest tests/visual/ \
-v \
--tb=short \
--html=reports/visual_report.html \
--self-contained-html \
-m visual
# Save updated baselines back to cache
- name: Save visual baselines cache
if: always()
uses: actions/cache@v5
with:
path: snapshots/
key: visual-baselines-${{ runner.os }}-${{ hashFiles('tests/visual/**') }}
- name: Upload visual regression report and diffs
if: always()
uses: actions/upload-artifact@v7
with:
name: visual-regression-report
path: |
reports/visual_report.html
screenshots/DIFF_*
snapshots/
retention-days: 30
# ────────────────────────────────────────────── Summary
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [api-tests, e2e-tests, accessibility-tests, visual-tests]
if: always()
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install report dependencies
run: pip install pytest-json-report
- name: Download E2E shard reports
uses: actions/download-artifact@v4
with:
pattern: e2e-shard-*
path: shard-artifacts/
merge-multiple: false
- name: Merge shard JSON reports
run: |
python scripts/merge_test_reports.py \
shard-artifacts/e2e-shard-1/reports/e2e_shard_1.json \
shard-artifacts/e2e-shard-2/reports/e2e_shard_2.json \
shard-artifacts/e2e-shard-3/reports/e2e_shard_3.json \
--output reports/e2e_combined.json \
--markdown reports/e2e_summary.md
- name: Post E2E summary to job summary
run: cat reports/e2e_summary.md >> $GITHUB_STEP_SUMMARY
- name: Print suite status table
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Suite | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| API Tests | ${{ needs.api-tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| E2E Tests | ${{ needs.e2e-tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Accessibility | ${{ needs.accessibility-tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Visual Regression | ${{ needs.visual-tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Platform:** ${{ env.BASE_URL }}" >> $GITHUB_STEP_SUMMARY
- name: Upload combined E2E report
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-combined-report
path: |
reports/e2e_combined.json
reports/e2e_summary.md
retention-days: 30