11name : Playwright Test Framework
2+
3+ # ---- Global environment (available to every job & step) ----
24env :
35 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 }}
410
511on :
612 workflow_dispatch :
1521 schedule :
1622 - cron : ' 0 0 * * *'
1723
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
35+
1836jobs :
1937 build_and_test :
2038 name : Build and Test
2139 runs-on : ubuntu-latest
2240 strategy :
41+ fail-fast : true
2342 matrix :
2443 browser : [ chrome, firefox, msedge ]
2544 steps :
2645 - name : Checkout Repository
2746 uses : actions/checkout@v4
47+ with :
48+ fetch-depth : 1 # shallow clone for speed
2849
29- - name : Setup Java and Maven
50+ - name : Setup Java (Temurin) with Maven cache
3051 uses : actions/setup-java@v4
3152 with :
3253 java-version : ' 17'
33- distribution : ' adopt '
54+ distribution : ' temurin '
3455 cache : maven
3556
36- - name : Cache Maven
37- uses : actions/cache@v4
38- with :
39- path : |
40- ~/.m2/repository
41- target
42- key : maven-${{ hashFiles('**/pom.xml') }}
43- restore-keys : |
44- maven-
45-
46- - name : Build Project
47- run : |
48- mvn -B install -DskipTests --no-transfer-progress -T 4C
49-
57+ # Install only the browser needed for the current matrix job
5058 - name : Install Chrome
59+ if : matrix.browser == 'chrome'
5160 uses : browser-actions/setup-chrome@latest
61+
5262 - name : Install Firefox
63+ if : matrix.browser == 'firefox'
5364 uses : browser-actions/setup-firefox@latest
65+
5466 - name : Install Edge
67+ if : matrix.browser == 'msedge'
5568 uses : browser-actions/setup-edge@v1
5669
57- - name : Run Unit Tests
58- env :
59- # Inject secret as environment variable
60- SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
61- SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
62- SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
70+ - name : Build Project
6371 run : |
64- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
65- -Dgroups=SWAG_LABS_UNIT \
66- -Dthreads=3 -Ddataproviderthreadcount=3
72+ mvn -B -ntp install -DskipTests -T 4C
6773
68- - name : Generate Coverage Report
74+ # Combine test + coverage into a single Maven invocation (less JVM spin-up)
75+ - name : Run Unit Tests with Coverage
6976 run : |
70- mvn jacoco:report
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
7183
72- - name : Upload Coverage to Codecov
84+ # Upload coverage once (chrome) to avoid 3 identical uploads
85+ - name : Upload Coverage to CodeCov
86+ if : matrix.browser == 'chrome'
7387 uses : codecov/codecov-action@v4
7488 with :
7589 token : ${{ secrets.CODECOV_TOKEN }}
7690 slug : ${{ secrets.CODECOV_SLUG }}
7791 verbose : true
78-
7992 - name : Upload Artifacts
8093 uses : actions/upload-artifact@v4
8194 with :
82- name : target-${{ matrix.browser }} # Unique artifact name
95+ name : target-${{ matrix.browser }}
8396 path : |
8497 ${{ github.workspace }}/target
8598 ${{ github.workspace }}/reports
@@ -89,33 +102,34 @@ jobs:
89102 runs-on : ubuntu-latest
90103 needs : build_and_test
91104 strategy :
105+ fail-fast : true
92106 matrix :
93107 browser : [ chrome, firefox, msedge ]
94108 steps :
95109 - name : Checkout Repository
96110 uses : actions/checkout@v4
111+ with :
112+ fetch-depth : 1
97113
98- - name : Setup Java and Maven
114+ - name : Setup Java (Temurin) with Maven cache
99115 uses : actions/setup-java@v4
100116 with :
101117 java-version : ' 17'
102- distribution : ' adopt '
118+ distribution : ' temurin '
103119 cache : maven
104120
105121 - name : Download Artifacts
106122 uses : actions/download-artifact@v4
107123 with :
108- name : target-${{ matrix.browser }} # Match the unique artifact name
124+ name : target-${{ matrix.browser }}
109125
110- - name : Run Tests for ${{ matrix.browser }}
111- env :
112- SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
113- SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
114- SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
126+ - name : Run Smoke Tests for ${{ matrix.browser }}
115127 run : |
116- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
117- -Dgroups=SWAG_LABS_SMOKE \
118- -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
119133
120134 - name : Verify Report Directory
121135 run : ls target/surefire-reports || echo "Report directory not found"
@@ -128,10 +142,7 @@ jobs:
128142 if : always()
129143
130144 - name : Send Results to Discord
131- env :
132- DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
133145 run : |
134- # Gather metrics from test-summary output
135146 passed="${{ steps.summary.outputs.passed }}"
136147 failed="${{ steps.summary.outputs.failed }}"
137148 skipped="${{ steps.summary.outputs.skipped }}"
@@ -150,45 +161,47 @@ jobs:
150161 content+="✅ **Pass %**: ${pass_percentage}%\n"
151162 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
152163 content+="-----------------------------------\n\n"
164+
153165 curl --location "$DISCORD_WEBHOOK_URL" \
154166 --header 'Content-Type: application/json' \
155167 --data-raw "{
156- \"content\": \"$content\",
157- \"username\": \"TestBot\"
168+ \"content\": \"$content\",
169+ \"username\": \"TestBot\"
158170 }"
159171
160172 regression_tests :
161173 name : Run Regression Tests
162174 runs-on : ubuntu-latest
163175 needs : build_and_test
164176 strategy :
177+ fail-fast : true
165178 matrix :
166179 browser : [ chrome, firefox, msedge ]
167180 steps :
168181 - name : Checkout Repository
169182 uses : actions/checkout@v4
183+ with :
184+ fetch-depth : 1
170185
171- - name : Setup Java and Maven
186+ - name : Setup Java (Temurin) with Maven cache
172187 uses : actions/setup-java@v4
173188 with :
174189 java-version : ' 17'
175- distribution : ' adopt '
190+ distribution : ' temurin '
176191 cache : maven
177192
178193 - name : Download Artifacts
179194 uses : actions/download-artifact@v4
180195 with :
181- name : target-${{ matrix.browser }} # Match the unique artifact name
196+ name : target-${{ matrix.browser }}
182197
183- - name : Run Tests for ${{ matrix.browser }}
184- env :
185- SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
186- SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
187- SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
198+ - name : Run Regression Tests for ${{ matrix.browser }}
188199 run : |
189- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
190- -Dgroups=SWAG_LABS_REGRESSION \
191- -Dthreads=3 -Ddataproviderthreadcount=3
200+ mvn -B -ntp clean test \
201+ -Drunmode=headless \
202+ -Dbrowser=${{ matrix.browser }} \
203+ -Dgroups=SWAG_LABS_REGRESSION \
204+ -Dthreads=3 -Ddataproviderthreadcount=3
192205
193206 - name : Verify Report Directory
194207 run : ls target/surefire-reports || echo "Report directory not found"
@@ -201,16 +214,14 @@ jobs:
201214 if : always()
202215
203216 - name : Send Results to Discord
204- env :
205- DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
206217 run : |
207- # Gather metrics from test-summary output
208218 passed="${{ steps.summary.outputs.passed }}"
209219 failed="${{ steps.summary.outputs.failed }}"
210220 skipped="${{ steps.summary.outputs.skipped }}"
211221 total="${{ steps.summary.outputs.total }}"
212222 pass_percentage=$(awk "BEGIN {print ($passed/$total)*100}")
213223 fail_percentage=$(awk "BEGIN {print ($failed/$total)*100}")
224+
214225 content="-----------------------------------\n\n"
215226 content+="🛠️ **Job: ${{ github.job }}**\n"
216227 content+="👤 **User: ${{ github.actor }}**\n"
@@ -222,48 +233,51 @@ jobs:
222233 content+="✅ **Pass %**: ${pass_percentage}%\n"
223234 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
224235 content+="-----------------------------------\n\n"
236+
225237 curl --location "$DISCORD_WEBHOOK_URL" \
226238 --header 'Content-Type: application/json' \
227239 --data-raw "{
228- \"content\": \"$content\",
229- \"username\": \"TestBot\"
240+ \"content\": \"$content\",
241+ \"username\": \"TestBot\"
230242 }"
231243
232244 e2e_tests :
233- name : E2E Tests
245+ name : Run E2E Tests
234246 runs-on : ubuntu-latest
235247 needs :
236248 - build_and_test
237249 - smoke_tests
238250 - regression_tests
239251 strategy :
252+ fail-fast : true
240253 matrix :
241254 browser : [ chrome, firefox, msedge ]
255+
242256 steps :
243257 - name : Checkout Repository
244258 uses : actions/checkout@v4
259+ with :
260+ fetch-depth : 1
245261
246- - name : Setup Java and Maven
262+ - name : Setup Java (Temurin) with Maven cache
247263 uses : actions/setup-java@v4
248264 with :
249265 java-version : ' 17'
250- distribution : ' adopt '
266+ distribution : ' temurin '
251267 cache : maven
252268
253269 - name : Download Artifacts
254270 uses : actions/download-artifact@v4
255271 with :
256- name : target-${{ matrix.browser }} # Match the unique artifact name
272+ name : target-${{ matrix.browser }}
257273
258- - name : Run Tests for ${{ matrix.browser }}
259- env :
260- SWAGLABS_URL : ${{ secrets.SWAGLABS_URL }}
261- SWAGLABS_USERNAME : ${{ secrets.SWAGLABS_USERNAME }}
262- SWAGLABS_PASSWORD : ${{ secrets.SWAGLABS_PASSWORD }}
274+ - name : Run E2E Tests for ${{ matrix.browser }}
263275 run : |
264- mvn clean test -Drunmode=headless -Dbrowser=${{ matrix.browser }} \
265- -Dgroups=SWAG_LABS_E2E \
266- -Dthreads=3 -Ddataproviderthreadcount=3
276+ mvn -B -ntp clean test \
277+ -Drunmode=headless \
278+ -Dbrowser=${{ matrix.browser }} \
279+ -Dgroups=SWAG_LABS_E2E \
280+ -Dthreads=3 -Ddataproviderthreadcount=3
267281
268282 - name : Verify Report Directory
269283 run : ls target/surefire-reports || echo "Report directory not found"
@@ -276,16 +290,14 @@ jobs:
276290 if : always()
277291
278292 - name : Send Results to Discord
279- env :
280- DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
281293 run : |
282- # Gather metrics from test-summary output
283294 passed="${{ steps.summary.outputs.passed }}"
284295 failed="${{ steps.summary.outputs.failed }}"
285296 skipped="${{ steps.summary.outputs.skipped }}"
286297 total="${{ steps.summary.outputs.total }}"
287298 pass_percentage=$(awk "BEGIN {print ($passed/$total)*100}")
288299 fail_percentage=$(awk "BEGIN {print ($failed/$total)*100}")
300+
289301 content="-----------------------------------\n\n"
290302 content+="🛠️ **Job: ${{ github.job }}**\n"
291303 content+="👤 **User: ${{ github.actor }}**\n"
@@ -297,9 +309,10 @@ jobs:
297309 content+="✅ **Pass %**: ${pass_percentage}%\n"
298310 content+="❌ **Fail %**: ${fail_percentage}%\n\n"
299311 content+="-----------------------------------\n\n"
312+
300313 curl --location "$DISCORD_WEBHOOK_URL" \
301314 --header 'Content-Type: application/json' \
302315 --data-raw "{
303- \"content\": \"$content\",
304- \"username\": \"TestBot\"
316+ \"content\": \"$content\",
317+ \"username\": \"TestBot\"
305318 }"
0 commit comments