11name : Playwright Test Framework
22
3+ # ---- Global environment (available to every job & step) ----
4+ env :
5+ TZ : Asia/Kolkata
6+ SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
7+ SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
8+ SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
9+ DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
10+
311on :
412 workflow_dispatch :
513 pull_request :
1321 schedule :
1422 - cron : ' 0 0 * * *'
1523
16- env :
17- TZ : Asia/Kolkata
18- SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
19- SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
20- SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
21- DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
22- CODECOV_TOKEN : ${{ secrets.CODECOV_TOKEN }}
23- CODECOV_SLUG : ${{ secrets.CODECOV_SLUG }}
24+ # Cancel older in-progress runs of the same ref to free runners sooner
25+ concurrency :
26+ group : ${{ github.workflow }}-${{ github.ref }}
27+ cancel-in-progress : true
28+
29+ permissions :
30+ contents : read
31+
32+ defaults :
33+ run :
34+ shell : bash
2435
2536jobs :
2637 build_and_test :
2738 name : Build and Test
2839 runs-on : ubuntu-latest
2940 strategy :
41+ fail-fast : true
3042 matrix :
3143 browser : [ chrome, firefox, msedge ]
3244 steps :
3345 - name : Checkout Repository
3446 uses : actions/checkout@v4
47+ with :
48+ fetch-depth : 1 # shallow clone for speed
3549
36- - name : Setup Java and Maven
50+ - name : Setup Java (Temurin) with Maven cache
3751 uses : actions/setup-java@v4
3852 with :
3953 java-version : ' 17'
40- distribution : ' adopt '
54+ distribution : ' temurin '
4155 cache : maven
4256
43- - name : Cache Maven
44- uses : actions/cache@v4
45- with :
46- path : |
47- ~/.m2/repository
48- target
49- key : maven-${{ hashFiles('**/pom.xml') }}
50- restore-keys : |
51- maven-
52-
53- - name : Build Project
54- run : |
55- mvn -B install -DskipTests --no-transfer-progress -T 4C
56-
57+ # Install only the browser needed for the current matrix job
5758 - name : Install Chrome
59+ if : matrix.browser == 'chrome'
5860 uses : browser-actions/setup-chrome@latest
61+
5962 - name : Install Firefox
63+ if : matrix.browser == 'firefox'
6064 uses : browser-actions/setup-firefox@latest
65+
6166 - name : Install Edge
67+ if : matrix.browser == 'msedge'
6268 uses : browser-actions/setup-edge@v1
6369
64- - name : Run Unit Tests
70+ - name : Build Project
6571 run : |
66- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
67- -Dgroups=SWAG_LABS_UNIT \
68- -Dthreads=3 -Ddataproviderthreadcount=3
72+ mvn -B -ntp install -DskipTests -T 4C
6973
70- - name : Generate Coverage Report
74+ # Combine test + coverage into a single Maven invocation (less JVM spin-up)
75+ - name : Run Unit Tests with Coverage
7176 run : |
72- mvn jacoco:report
73-
74- - name : Upload Coverage to Codecov
77+ mvn -B -ntp clean verify \
78+ -Drunmode=headless \
79+ -Dbrowser=${{ matrix.browser }} \
80+ -Dgroups=SWAG_LABS_UNIT \
81+ -Dthreads=3 -Ddataproviderthreadcount=3 \
82+ jacoco:report
83+
84+ # Upload coverage once (chrome) to avoid 3 identical uploads
85+ - name : Upload Coverage to CodeCov
86+ if : matrix.browser == 'chrome'
7587 uses : codecov/codecov-action@v4
7688 with :
77- token : $CODECOV_TOKEN
78- slug : $CODECOV_SLUG
89+ token : ${{ secrets. CODECOV_TOKEN }}
90+ slug : ${{ secrets. CODECOV_SLUG }}
7991 verbose : true
80-
8192 - name : Upload Artifacts
8293 uses : actions/upload-artifact@v4
8394 with :
84- name : target-${{ matrix.browser }} # Unique artifact name
95+ name : target-${{ matrix.browser }}
8596 path : |
8697 ${{ github.workspace }}/target
8798 ${{ github.workspace }}/reports
@@ -91,29 +102,34 @@ jobs:
91102 runs-on : ubuntu-latest
92103 needs : build_and_test
93104 strategy :
105+ fail-fast : true
94106 matrix :
95107 browser : [ chrome, firefox, msedge ]
96108 steps :
97109 - name : Checkout Repository
98110 uses : actions/checkout@v4
111+ with :
112+ fetch-depth : 1
99113
100- - name : Setup Java and Maven
114+ - name : Setup Java (Temurin) with Maven cache
101115 uses : actions/setup-java@v4
102116 with :
103117 java-version : ' 17'
104- distribution : ' adopt '
118+ distribution : ' temurin '
105119 cache : maven
106120
107121 - name : Download Artifacts
108122 uses : actions/download-artifact@v4
109123 with :
110- name : target-${{ matrix.browser }} # Match the unique artifact name
124+ name : target-${{ matrix.browser }}
111125
112- - name : Run Tests for ${{ matrix.browser }}
126+ - name : Run Smoke Tests for ${{ matrix.browser }}
113127 run : |
114- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
115- -Dgroups=SWAG_LABS_SMOKE \
116- -Dthreads=3 -Ddataproviderthreadcount=3
128+ mvn -B -ntp clean test \
129+ -Drunmode=headless \
130+ -Dbrowser=${{ matrix.browser }} \
131+ -Dgroups=SWAG_LABS_SMOKE \
132+ -Dthreads=3 -Ddataproviderthreadcount=3
117133
118134 - name : Verify Report Directory
119135 run : ls target/surefire-reports || echo "Report directory not found"
@@ -127,7 +143,6 @@ jobs:
127143
128144 - name : Send Results to Discord
129145 run : |
130- # Gather metrics from test-summary output
131146 passed="${{ steps.summary.outputs.passed }}"
132147 failed="${{ steps.summary.outputs.failed }}"
133148 skipped="${{ steps.summary.outputs.skipped }}"
@@ -146,41 +161,46 @@ jobs:
146161 content+="✅ **Pass %**: ${pass_percentage}%\n"
147162 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
148163 content+="-----------------------------------\n\n"
164+
149165 curl --location "$DISCORD_WEBHOOK_URL" \
150166 --header 'Content-Type: application/json' \
151167 --data-raw "{
152- \"content\": \"$content\",
153- \"username\": \"TestBot\"
168+ \"content\": \"$content\",
169+ \"username\": \"TestBot\"
154170 }"
155-
156171 regression_tests :
157172 name : Run Regression Tests
158173 runs-on : ubuntu-latest
159174 needs : build_and_test
160175 strategy :
176+ fail-fast : true
161177 matrix :
162178 browser : [ chrome, firefox, msedge ]
163179 steps :
164180 - name : Checkout Repository
165181 uses : actions/checkout@v4
182+ with :
183+ fetch-depth : 1
166184
167- - name : Setup Java and Maven
185+ - name : Setup Java (Temurin) with Maven cache
168186 uses : actions/setup-java@v4
169187 with :
170188 java-version : ' 17'
171- distribution : ' adopt '
189+ distribution : ' temurin '
172190 cache : maven
173191
174192 - name : Download Artifacts
175193 uses : actions/download-artifact@v4
176194 with :
177- name : target-${{ matrix.browser }} # Match the unique artifact name
195+ name : target-${{ matrix.browser }}
178196
179- - name : Run Tests for ${{ matrix.browser }}
197+ - name : Run Regression Tests for ${{ matrix.browser }}
180198 run : |
181- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
182- -Dgroups=SWAG_LABS_REGRESSION \
183- -Dthreads=3 -Ddataproviderthreadcount=3
199+ mvn -B -ntp clean test \
200+ -Drunmode=headless \
201+ -Dbrowser=${{ matrix.browser }} \
202+ -Dgroups=SWAG_LABS_REGRESSION \
203+ -Dthreads=3 -Ddataproviderthreadcount=3
184204
185205 - name : Verify Report Directory
186206 run : ls target/surefire-reports || echo "Report directory not found"
@@ -194,13 +214,13 @@ jobs:
194214
195215 - name : Send Results to Discord
196216 run : |
197- # Gather metrics from test-summary output
198217 passed="${{ steps.summary.outputs.passed }}"
199218 failed="${{ steps.summary.outputs.failed }}"
200219 skipped="${{ steps.summary.outputs.skipped }}"
201220 total="${{ steps.summary.outputs.total }}"
202221 pass_percentage=$(awk "BEGIN {print ($passed/$total)*100}")
203222 fail_percentage=$(awk "BEGIN {print ($failed/$total)*100}")
223+
204224 content="-----------------------------------\n\n"
205225 content+="🛠️ **Job: ${{ github.job }}**\n"
206226 content+="👤 **User: ${{ github.actor }}**\n"
@@ -212,44 +232,51 @@ jobs:
212232 content+="✅ **Pass %**: ${pass_percentage}%\n"
213233 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
214234 content+="-----------------------------------\n\n"
235+
215236 curl --location "$DISCORD_WEBHOOK_URL" \
216237 --header 'Content-Type: application/json' \
217238 --data-raw "{
218- \"content\": \"$content\",
219- \"username\": \"TestBot\"
239+ \"content\": \"$content\",
240+ \"username\": \"TestBot\"
220241 }"
221242
222243 e2e_tests :
223- name : E2E Tests
244+ name : Run E2E Tests
224245 runs-on : ubuntu-latest
225246 needs :
226247 - build_and_test
227248 - smoke_tests
228249 - regression_tests
229250 strategy :
251+ fail-fast : true
230252 matrix :
231253 browser : [ chrome, firefox, msedge ]
254+
232255 steps :
233256 - name : Checkout Repository
234257 uses : actions/checkout@v4
258+ with :
259+ fetch-depth : 1
235260
236- - name : Setup Java and Maven
261+ - name : Setup Java (Temurin) with Maven cache
237262 uses : actions/setup-java@v4
238263 with :
239264 java-version : ' 17'
240- distribution : ' adopt '
265+ distribution : ' temurin '
241266 cache : maven
242267
243268 - name : Download Artifacts
244269 uses : actions/download-artifact@v4
245270 with :
246- name : target-${{ matrix.browser }} # Match the unique artifact name
271+ name : target-${{ matrix.browser }}
247272
248- - name : Run Tests for ${{ matrix.browser }}
273+ - name : Run E2E Tests for ${{ matrix.browser }}
249274 run : |
250- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
251- -Dgroups=SWAG_LABS_E2E \
252- -Dthreads=3 -Ddataproviderthreadcount=3
275+ mvn -B -ntp clean test \
276+ -Drunmode=headless \
277+ -Dbrowser=${{ matrix.browser }} \
278+ -Dgroups=SWAG_LABS_E2E \
279+ -Dthreads=3 -Ddataproviderthreadcount=3
253280
254281 - name : Verify Report Directory
255282 run : ls target/surefire-reports || echo "Report directory not found"
@@ -263,13 +290,13 @@ jobs:
263290
264291 - name : Send Results to Discord
265292 run : |
266- # Gather metrics from test-summary output
267293 passed="${{ steps.summary.outputs.passed }}"
268294 failed="${{ steps.summary.outputs.failed }}"
269295 skipped="${{ steps.summary.outputs.skipped }}"
270296 total="${{ steps.summary.outputs.total }}"
271297 pass_percentage=$(awk "BEGIN {print ($passed/$total)*100}")
272298 fail_percentage=$(awk "BEGIN {print ($failed/$total)*100}")
299+
273300 content="-----------------------------------\n\n"
274301 content+="🛠️ **Job: ${{ github.job }}**\n"
275302 content+="👤 **User: ${{ github.actor }}**\n"
@@ -281,9 +308,10 @@ jobs:
281308 content+="✅ **Pass %**: ${pass_percentage}%\n"
282309 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
283310 content+="-----------------------------------\n\n"
311+
284312 curl --location "$DISCORD_WEBHOOK_URL" \
285313 --header 'Content-Type: application/json' \
286314 --data-raw "{
287- \"content\": \"$content\",
288- \"username\": \"TestBot\"
315+ \"content\": \"$content\",
316+ \"username\": \"TestBot\"
289317 }"
0 commit comments