-
Notifications
You must be signed in to change notification settings - Fork 1
WIP: test improvements #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6728acb
8367217
fc69fce
283a31a
7713c7d
a291da0
80b8afb
e07bcab
5e3267e
08fbb91
58672a8
6b5c044
44800d1
f030bc4
ff32def
294903f
5fd9e80
acfadf2
86ac943
0cb445c
030425d
f4c3395
5a70279
ae09c26
37c526a
844fd73
dec34f1
93923b2
fe8db7f
29b909c
e262896
284e2c2
23ff950
87cb58d
20c7ef6
ce16a15
c49dba0
7fb5e23
f706e78
8e469cc
263ec76
7740a91
58b7bae
fa4b765
070d1d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| --- | ||
| name: "Playwright E2E Tests" | ||
| run-name: "E2E Tests: env: ${{ inputs.environment || 'local' }}, browser: ${{ inputs.browser || 'chromium' }}, filter: ${{ inputs.test_filter && format(' - {0}', inputs.test_filter) || '' }}" | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 2 * * *' # Every day at 2am UTC | ||
| workflow_dispatch: | ||
| inputs: | ||
| environment: | ||
| description: "Target environment" | ||
| required: false | ||
| default: "local" | ||
| type: choice | ||
| options: | ||
| - local | ||
| - dev | ||
| browser: | ||
| description: "Browser to run tests on" | ||
| required: false | ||
|
|
@@ -27,15 +36,14 @@ jobs: | |
| name: "Playwright E2E tests" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| env: | ||
| TARGET_ENV: ${{ inputs.environment || 'local' }} | ||
| steps: | ||
| - name: "Checkout code" | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: "Install mise" | ||
| uses: jdx/mise-action@v3 | ||
| with: | ||
| install: true | ||
| cache: true | ||
| - name: Initialize mise | ||
| uses: ./.github/actions/init-mise | ||
|
|
||
| - name: "Install Playwright browsers" | ||
| working-directory: tests | ||
|
|
@@ -57,34 +65,50 @@ jobs: | |
| EOF | ||
|
|
||
| - name: "Start the application" | ||
| if: env.TARGET_ENV == 'local' || env.TARGET_ENV == 'dev' | ||
| run: | | ||
| npm run start | ||
|
|
||
| - name: "Show application status" | ||
| if: env.TARGET_ENV == 'local' || env.TARGET_ENV == 'dev' | ||
| run: | | ||
| docker compose -f local-environment/docker-compose.yml ps | ||
| docker logs ui | ||
|
|
||
| - name: "Get terraform outputs" | ||
| if: env.TARGET_ENV == 'local' || env.TARGET_ENV == 'dev' | ||
| id: terraform | ||
| run: | | ||
| UI_URL=$(terraform -chdir=local-environment/infra output -raw ui_url) | ||
| API_URL=$(terraform -chdir=local-environment/infra output -raw api_base_url) | ||
| echo "ui_url=$UI_URL" >> $GITHUB_OUTPUT | ||
| echo "api_base_url=$API_URL" >> $GITHUB_OUTPUT | ||
| echo "ui_url=$UI_URL" >> "$GITHUB_OUTPUT" | ||
| echo "api_base_url=$API_URL" >> "$GITHUB_OUTPUT" | ||
| echo "UI URL: $UI_URL" | ||
| echo "API URL: $API_URL" | ||
|
|
||
| - name: "Set environment URLs" | ||
| id: urls | ||
| run: | | ||
| if [ "$TARGET_ENV" == "dev" ]; then | ||
| echo "ui_url=https://dev.hometest.service.nhs.uk" >> "$GITHUB_OUTPUT" | ||
| echo "api_url=https://dev.hometest.service.nhs.uk/" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "ui_url=${{ steps.terraform.outputs.ui_url }}" >> "$GITHUB_OUTPUT" | ||
| echo "api_url=${{ steps.terraform.outputs.api_base_url }}" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
Comment on lines
+92
to
+98
|
||
|
|
||
| - name: "Wait for UI to be reachable" | ||
| run: | | ||
| UI_URL="${{ steps.terraform.outputs.ui_url }}" | ||
| UI_URL="${{ steps.urls.outputs.ui_url }}" | ||
| echo "Waiting for UI to be reachable at $UI_URL..." | ||
| timeout=120 | ||
| elapsed=0 | ||
| until curl -sf "$UI_URL" > /dev/null 2>&1; do | ||
| if [ $elapsed -ge $timeout ]; then | ||
| echo "Timeout: UI not reachable after ${timeout}s" | ||
| docker logs ui | ||
| if [ "$TARGET_ENV" == "local" ] || [ "$TARGET_ENV" == "dev" ]; then | ||
| docker logs ui | ||
| fi | ||
| exit 1 | ||
| fi | ||
| echo "Waiting... (${elapsed}s)" | ||
|
|
@@ -101,7 +125,7 @@ jobs: | |
| FILTER="${{ inputs.test_filter }}" | ||
|
|
||
| # Build the command | ||
| CMD="npx playwright test" | ||
| CMD="HEADLESS=true ENV=dev npx playwright test" | ||
|
|
||
| # Add browser project | ||
| if [ "$BROWSER" != "all" ]; then | ||
|
|
@@ -114,19 +138,19 @@ jobs: | |
| fi | ||
|
|
||
| echo "Running: $CMD" | ||
| eval $CMD | ||
| eval "$CMD" | ||
| env: | ||
| CI: true | ||
| FORCE_COLOR: true | ||
| UI_BASE_URL: ${{ steps.terraform.outputs.ui_url }} | ||
| API_BASE_URL: ${{ steps.terraform.outputs.api_base_url }} | ||
| UI_BASE_URL: ${{ steps.urls.outputs.ui_url }} | ||
| API_BASE_URL: ${{ steps.urls.outputs.api_url }} | ||
|
|
||
| - name: "Grab docker compose logs" | ||
| if: always() && (env.TARGET_ENV == 'local' || env.TARGET_ENV == 'dev') | ||
| run: | | ||
| for service in $(docker compose -f local-environment/docker-compose.yml ps --services); do | ||
| docker compose -f local-environment/docker-compose.yml logs "$service" > "tests/testResults/docker-compose-${service}.log" 2>&1 | ||
| done | ||
| if: always() | ||
|
|
||
| - name: "Publish Test Results" | ||
| uses: dorny/test-reporter@v2 | ||
|
|
@@ -140,24 +164,26 @@ jobs: | |
| - name: "Generate Job Summary" | ||
| if: always() | ||
| run: | | ||
| echo "## Playwright Test Results" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| if [ -f tests/testResults/junit-results.xml ]; then | ||
| TESTS=$(grep -oP 'tests="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| FAILURES=$(grep -oP 'failures="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| ERRORS=$(grep -oP 'errors="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| TIME=$(grep -oP 'time="\K[0-9.]+' tests/testResults/junit-results.xml | head -1) | ||
| PASSED=$((TESTS - FAILURES - ERRORS)) | ||
| echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY | ||
| echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY | ||
| echo "| Total Tests | $TESTS |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| :white_check_mark: Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| :x: Failed | $FAILURES |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| :warning: Errors | $ERRORS |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| :stopwatch: Duration | ${TIME}s |" >> $GITHUB_STEP_SUMMARY | ||
| else | ||
| echo ":warning: No test results found" >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| { | ||
| echo "## Playwright Test Results" | ||
| echo "" | ||
| if [ -f tests/testResults/junit-results.xml ]; then | ||
| TESTS=$(grep -oP 'tests="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| FAILURES=$(grep -oP 'failures="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| ERRORS=$(grep -oP 'errors="\K[0-9]+' tests/testResults/junit-results.xml | head -1) | ||
| TIME=$(grep -oP 'time="\K[0-9.]+' tests/testResults/junit-results.xml | head -1) | ||
| PASSED=$((TESTS - FAILURES - ERRORS)) | ||
| echo "| Metric | Value |" | ||
| echo "|--------|-------|" | ||
| echo "| Total Tests | $TESTS |" | ||
| echo "| :white_check_mark: Passed | $PASSED |" | ||
| echo "| :x: Failed | $FAILURES |" | ||
| echo "| :warning: Errors | $ERRORS |" | ||
| echo "| :stopwatch: Duration | ${TIME}s |" | ||
| else | ||
| echo ":warning: No test results found" | ||
| fi | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: "Upload test results" | ||
| uses: actions/upload-artifact@v7 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
TARGET_ENV=devthis job still starts the local application and fetches terraform outputs, but later overrides URLs to point at the remote dev environment. This adds unnecessary runtime and risk of failure. Consider making these steps conditional onTARGET_ENV == 'local'only (and skip terraform/docker when running against remote dev).