-
Notifications
You must be signed in to change notification settings - Fork 0
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
a1250fa
2b64dec
604c910
d79e0d1
9e53b89
a997c9d
665621d
71b1bd7
4b73234
cae21bd
ea3a3c9
a4f7e44
1112219
5fb96c4
885c2a2
ce3a723
1058081
60c4a67
7e79e00
d28270f
f288006
1fbba35
703ae3c
9b0c677
3e80998
c142a55
f15ccdf
7b368d6
a9e9b7b
c2c63dd
78451c8
814a444
9a0a04e
9fe732e
513d780
cecee7c
6300abb
951f3c3
4a156f4
c280405
8a62ff6
ab5879d
bcc44f4
1c1ea7c
db5ea38
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) | ||
|
Comment on lines
67
to
83
|
||
| 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.
This workflow is also triggered by
schedule, where theinputscontext is not available. Using${{ inputs.* }}inrun-namecan cause scheduled runs to fail with an expression-evaluation error. Use${{ github.event.inputs.* }}(with||defaults) or guard viagithub.event_name == 'workflow_dispatch'.