Skip to content

Commit fb80b8e

Browse files
authored
Merge pull request #3793 from navikt/feature/playwright-report-on-fail
Feature/playwright report on fail
2 parents 1e8c71b + dac3a1c commit fb80b8e

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

.github/workflows/all.workflows.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ permissions:
4242
id-token: write
4343

4444
jobs:
45-
4645
backend:
4746
if: inputs.workflow == 'backend'
4847
uses: ./.github/workflows/common.workflow.backend.yml
@@ -59,6 +58,9 @@ jobs:
5958
frontend:
6059
if: inputs.workflow == 'frontend'
6160
uses: ./.github/workflows/common.workflow.frontend.yml
61+
permissions:
62+
packages: write
63+
6264
with:
6365
cluster: ${{ inputs.cluster }}
6466
working-directory: "${{ inputs.type }}/${{ inputs.name }}"

.github/workflows/app.dolly-frontend.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@ on:
1919
jobs:
2020
playwright:
2121
uses: ./.github/workflows/common.playwright.yml
22+
permissions:
23+
packages: write
24+
id-token: write
25+
contents: read
2226
with:
2327
working-directory: "apps/dolly-frontend"
2428
secrets:
2529
READER_TOKEN: ${{ secrets.READER_TOKEN }}
2630

2731
workflow:
2832
uses: ./.github/workflows/common.workflow.frontend.yml
33+
permissions:
34+
packages: write
35+
id-token: write
36+
contents: read
2937
with:
3038
working-directory: "apps/dolly-frontend"
3139
deploy-tag: "#deploy-frontend"
3240
deploy-tag-test: "#deploy-test-frontend"
3341
deploy-tag-idporten: "#deploy-idporten-frontend"
3442
deploy-tag-unstable: "#deploy-unstable-frontend"
35-
permissions:
36-
contents: read
37-
id-token: write
3843
secrets: inherit

.github/workflows/common.playwright.yml

+73-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ on:
99
secrets:
1010
READER_TOKEN:
1111
required: true
12+
1213
jobs:
1314
playwright-tests:
1415
timeout-minutes: 15
1516
runs-on: ubuntu-latest
1617
strategy:
1718
fail-fast: false
1819
matrix:
19-
shardIndex: [ 1, 2, 3, 4, 5 ]
20-
shardTotal: [ 5 ]
20+
shardIndex: [ 1, 2, 3 ]
21+
shardTotal: [ 3 ]
2122
env:
2223
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
2324
steps:
@@ -35,4 +36,73 @@ jobs:
3536
run: npx playwright install --with-deps
3637
- name: Run Playwright tests
3738
working-directory: ${{ inputs.working-directory }}/src/main/js
38-
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
39+
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
40+
- name: Upload blob report to GitHub Actions Artifacts
41+
if: ${{ !cancelled() }}
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: blob-report-${{ matrix.shardIndex }}
45+
path: ${{ inputs.working-directory }}/src/main/js/blob-report
46+
retention-days: 1
47+
48+
merge-reports:
49+
if: ${{ !cancelled() }}
50+
needs: [ playwright-tests ]
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: actions/setup-node@v4
55+
with:
56+
node-version: 22.x
57+
58+
- name: Download blob reports from GitHub Actions Artifacts
59+
uses: actions/download-artifact@v4
60+
with:
61+
path: ${{ inputs.working-directory }}/src/main/js/all-blob-reports
62+
pattern: blob-report-*
63+
merge-multiple: true
64+
65+
- name: Merge into HTML Report
66+
working-directory: ${{ inputs.working-directory }}/src/main/js
67+
run: npx playwright merge-reports --reporter html ./all-blob-reports
68+
69+
- name: Upload HTML report
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: html-report--attempt-${{ github.run_attempt }}
73+
path: ${{ inputs.working-directory }}/src/main/js/playwright-report
74+
retention-days: 14
75+
76+
- name: Upload HTML report to CDN
77+
uses: nais/deploy/actions/cdn-upload/v2@master
78+
with:
79+
team: dolly
80+
source: ${{ inputs.working-directory }}/src/main/js/playwright-report
81+
destination: /${{ github.repository }}/${{ github.run_number }}
82+
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
83+
# project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
84+
85+
- name: Merge to json report
86+
working-directory: ${{ inputs.working-directory }}/src/main/js
87+
run: npx playwright merge-reports --reporter json ./all-blob-reports > playwright-report/report.json
88+
89+
- name: Make fancy GHA Summary
90+
working-directory: ${{ inputs.working-directory }}/src/main/js
91+
run: |
92+
total_tests=$(jq '.stats.expected + .stats.unexpected' playwright-report/report.json)
93+
passed_tests=$(jq '.stats.expected' playwright-report/report.json)
94+
failed_tests=$(jq '.stats.unexpected' playwright-report/report.json)
95+
failed_test_info=$(jq -r '.suites[].specs[] | select(.ok == false) | "\(.title) (\(.file), \(.tests[].projectName))"' playwright-report/report.json)
96+
echo "## Playwright Test Report Summary" >> $GITHUB_STEP_SUMMARY
97+
echo "Total tests: $total_tests ✅" >> $GITHUB_STEP_SUMMARY
98+
echo "Passed tests: $passed_tests ✅" >> $GITHUB_STEP_SUMMARY
99+
if [ "$failed_tests" -gt 0 ]; then
100+
echo "Failed tests: $failed_tests ❌" >> $GITHUB_STEP_SUMMARY
101+
echo "### Failed Tests:" >> $GITHUB_STEP_SUMMARY
102+
while IFS= read -r test; do
103+
echo "- $test ❌" >> $GITHUB_STEP_SUMMARY
104+
done <<< "$failed_test_info"
105+
else
106+
echo "Failed tests: $failed_tests 🔹" >> $GITHUB_STEP_SUMMARY
107+
fi
108+
echo "Se hele rapporten [her](https://cdn.nav.no/dolly/${{ github.repository }}/${{ github.run_number }}/playwright-report/index.html)." >> $GITHUB_STEP_SUMMARY

apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public static void main(String[] args) {
1414
.initializers(new NaisEnvironmentApplicationContextInitializer())
1515
.run(args);
1616
}
17-
}
17+
}

apps/dolly-frontend/src/main/java/no/nav/dolly/web/DollyFrontendApplicationStarter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ private Function<PredicateSpec, Buildable<Route>> createRoute(String segment, St
148148
.filters(filter, removeCookiesFilter, addUserJwtHeaderFilter())
149149
).uri(host);
150150
}
151-
}
151+
}

apps/dolly-frontend/src/main/js/playwright.config.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ export default defineConfig({
1818
// One worker on CI to make tests more stable
1919
workers: process.env.CI ? 1 : 3,
2020

21-
reporter: 'html',
22-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
21+
reporter: [
22+
[
23+
process.env.CI ? 'blob' : 'html',
24+
{
25+
attachments: true,
26+
},
27+
],
28+
],
29+
2330
use: {
2431
baseURL: 'http://localhost:5678/',
2532
trace: 'on-first-retry',
33+
screenshot: {
34+
mode: 'on',
35+
fullPage: true,
36+
},
2637
},
2738

2839
/* Configure projects for major browsers */

0 commit comments

Comments
 (0)