You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c68a632
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+69-23Lines changed: 69 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,12 @@
18
18
<li><a href="#installation">Installation</a>
19
19
</ul>
20
20
</li>
21
-
<li><a href="#usage">Usage</a></li>
21
+
<li>
22
+
<a href="#usage">Usage</a>
23
+
<ul>
24
+
<li><a href="#sharding">Sharding</a></li>
25
+
</ul>
26
+
</li>
22
27
<li><a href="#reports">Reports</a></li>
23
28
<li><a href="#sonarqube">SonarQube</a></li>
24
29
<li><a href="#docker">Docker</a></li>
@@ -197,7 +202,48 @@ $env:ENV="qa"; npm run test:serial
197
202
ENV=qa npm run test:serial
198
203
```
199
204
200
-
6. For executing API test cases, please provide "ENV" value as "qaApi" or "devApi". ReqRes API tests also require `REQRES_API_KEY`, because ReqRes expects the `x-api-key` request header:
205
+
### Sharding
206
+
207
+
Sharding is supported in this project for faster execution in CI by splitting the suite into smaller chunks and then merging the reports into a single HTML report.
208
+
209
+
6. Run a single shard locally:
210
+
211
+
**Windows CMD:**
212
+
```batch
213
+
set ENV=qa && set SHARD_INDEX=1 && set SHARD_TOTAL=4 && npm run test:shard
214
+
```
215
+
216
+
**Windows PowerShell:**
217
+
```powershell
218
+
$env:ENV="qa"; $env:SHARD_INDEX="1"; $env:SHARD_TOTAL="4"; npm run test:shard
219
+
```
220
+
221
+
**Mac/Linux/WSL:**
222
+
```bash
223
+
ENV=qa SHARD_INDEX=1 SHARD_TOTAL=4 npm run test:shard
224
+
```
225
+
226
+
Playwright uses `--shard=current/total` to split your suite. For example, the project is configured to run 4 shards using the GitHub Actions matrix:
227
+
228
+
```yaml
229
+
strategy:
230
+
fail-fast: false
231
+
matrix:
232
+
shardIndex: [1, 2, 3, 4]
233
+
shardTotal: [4]
234
+
```
235
+
236
+
Each shard writes a `blob` report and then the final job downloads all blob reports and merges them using:
237
+
238
+
```bash
239
+
npx playwright merge-reports --reporter html ./all-blob-reports
240
+
```
241
+
242
+
This produces a single HTML report in the `playwright-report` folder.
243
+
244
+
The CI workflow also keeps custom reporting enabled with the existing custom reporter and Allure reports while using blob reports only for the sharded run. This ensures you can still maintain your custom output while supporting sharding in GitHub Actions.
245
+
246
+
7. For executing API test cases, please provide "ENV" value as "qaApi" or "devApi". ReqRes API tests also require `REQRES_API_KEY`, because ReqRes expects the `x-api-key` request header:
201
247
202
248
**Windows CMD:**
203
249
```batch
@@ -214,13 +260,13 @@ $env:ENV="qaApi"; $env:REQRES_API_KEY="your_reqres_key"; npm run test:api
214
260
ENV=qaApi REQRES_API_KEY=your_reqres_key npm run test:api
215
261
```
216
262
217
-
7. For recording test scripts :
263
+
8. For recording test scripts :
218
264
219
265
```JS
220
266
npm run test:record
221
267
```
222
268
223
-
8. To produce and visually compare screenshots execute below command. On first execution reference screenshot will be generated for comparision with subsequent runs.
269
+
9. To produce and visually compare screenshots execute below command. On first execution reference screenshot will be generated for comparision with subsequent runs.
224
270
225
271
**Windows CMD:**
226
272
```batch
@@ -237,7 +283,7 @@ $env:ENV="qa"; npm run test:visual
237
283
ENV=qa npm run test:visual
238
284
```
239
285
240
-
9. For emulating test cases on any device, in `playwright.config.ts`, under device section provide desired device name and execute :
286
+
10. For emulating test cases on any device, in `playwright.config.ts`, under device section provide desired device name and execute :
241
287
242
288
**Windows CMD:**
243
289
```batch
@@ -254,28 +300,28 @@ $env:ENV="qa"; npm run test:device
254
300
ENV=qa npm run test:device
255
301
```
256
302
257
-
10. For Allure Report generation execute :
303
+
11. For Allure Report generation execute :
258
304
259
305
```JS
260
306
npm run allureReport
261
307
```
262
-
11. For HTML Report generation execute below command , single static HTML report(index.html) which can be sent via email is generated in "html-report" folder:
263
-
12. For debugging test cases add debug points, the press CNTRL+SHIFT+P and type "debug:debug npm script", on the edit box select desired script.
264
-
13. Screenshots, Videos and Trace files will be generated in test-results folder.
265
-
14. To change your username go to `testConfig.ts` and provide value against `username`
266
-
15. To change password, go to `lib/WebActions` in `decipherPassword()` uncomment `ENCRYPT` code block and replace `password` with your password, execute the test case, Encrypted password will be printed on your console . Copy Encrypted password in `testConfig.ts` against `password` field. You can comment Encrypt bloack ater this.
267
-
16. For executing Postgres DB test case, navigate to `testConfig.ts` and provide values for `dbUsername, dbPassword, dbServerName, dbPort, dbName`. Refer to `tests/DB.test.ts` for connecting to DB and Firing a Query.
268
-
17. For viewing trace files, go to folder where `trace.zip` is generated and execute :
308
+
12. For HTML Report generation execute below command , single static HTML report(index.html) which can be sent via email is generated in "html-report" folder:
309
+
13. For debugging test cases add debug points, the press CNTRL+SHIFT+P and type "debug:debug npm script", on the edit box select desired script.
310
+
14. Screenshots, Videos and Trace files will be generated in test-results folder.
311
+
15. To change your username go to `testConfig.ts` and provide value against `username`
312
+
16. To change password, go to `lib/WebActions` in `decipherPassword()` uncomment `ENCRYPT` code block and replace `password` with your password, execute the test case, Encrypted password will be printed on your console . Copy Encrypted password in `testConfig.ts` against `password` field. You can comment Encrypt bloack ater this.
313
+
17. For executing Postgres DB test case, navigate to `testConfig.ts` and provide values for `dbUsername, dbPassword, dbServerName, dbPort, dbName`. Refer to `tests/DB.test.ts` for connecting to DB and Firing a Query.
314
+
18. For viewing trace files, go to folder where `trace.zip` is generated and execute :
269
315
```JS
270
316
npx playwright show-trace trace.zip
271
317
```
272
-
18. You can change the Logging Message at Test Case/Test Step Level in CustomReporterConfig.ts file
273
-
19. In `tsconfig.json` file in `paths` section we can re-assign the long path imports like '../../' to a variable which starts with '@' and then we can use it to shorten our import statements in respective file.
318
+
19. You can change the Logging Message at Test Case/Test Step Level in CustomReporterConfig.ts file
319
+
20. In `tsconfig.json` file in `paths` section we can re-assign the long path imports like '../../' to a variable which starts with '@' and then we can use it to shorten our import statements in respective file.
274
320
In the below example wherever '../../pageFactory/pageRepository/' import statement is used we can replace it with '@pages'
275
321
```JS
276
322
"@pages/*":["pageFactory/pageRepository/*"]
277
323
```
278
-
20. Network Replay :
324
+
21. Network Replay :
279
325
For using this featre in Playwright we use HAR file.
280
326
HAR (HTTP Archive) is a file format used by several HTTP session tools to export the captured data. This can be highly useful in troubleshooting complex issues by obtaining additional information about the network requests that are generated in the browser while an issue occurs.
where `update:false` means to use the existing HAR from from the path given in first paraeter `har/personalInfo.har`, to see this in action you can turn off your internet and run the script, complete webpage is mocked up along with assertions on the browser of your choice this is done using the Network Replay feature and by using our recorded HAR file.
293
339
We can use this feature when webpage is down for some reason and we want to test some scenarios.
294
340
295
-
21. Logging is implemented in `CustomReporterConfig.ts` using winston logger.
341
+
22. Logging is implemented in `CustomReporterConfig.ts` using winston logger.
296
342
297
343
First we have to create a logger object using winston.createLogger and then provid the configuration you need.
298
344
First argument is "level" for which i have provided value as "info", in winston logger every logging level is provided with a numeric value, for info the numeric value is 2, so if we provide level as info then all the logs which are equal to or less than info level will be displayed. In our case logs with error(0) and warn(1) wil also be logged. For more info on logging refer below link
@@ -307,7 +353,7 @@ Once logger object is created I have provided `logger.add(console);` which instr
307
353
308
354
Once logger object is created you can use this instead of console.log in your framework and these logs will be written both in your console and log file.
309
355
310
-
22. UI mode in Playwright is lets you explore, run and debug tests, it comes with a built-in watch mode. It opens like Traceviewer where you can use the window to find selectors, its directly integrated to VS Code, all the browsers definned in playwright config will be automatically picked up and you can chosse to run individual test cases in browser of choice and also we can run tests directly from UI mode instead of IDE. I have used the tag `@Smoke` in `test:ui` section of package.json, because all my UI test cases are tagged with `@Smoke` tag and we want to run only Web based test cases. To use UI mode use below command with `ENV` value of your choice
356
+
23. UI mode in Playwright is lets you explore, run and debug tests, it comes with a built-in watch mode. It opens like Traceviewer where you can use the window to find selectors, its directly integrated to VS Code, all the browsers definned in playwright config will be automatically picked up and you can chosse to run individual test cases in browser of choice and also we can run tests directly from UI mode instead of IDE. I have used the tag `@Smoke` in `test:ui` section of package.json, because all my UI test cases are tagged with `@Smoke` tag and we want to run only Web based test cases. To use UI mode use below command with `ENV` value of your choice
311
357
312
358
**Windows CMD:**
313
359
```batch
@@ -324,9 +370,9 @@ $env:ENV="qa"; npm run test:ui
324
370
ENV=qa npm run test:ui
325
371
```
326
372
327
-
23. For Extracting text from PDF we are using `pdfjs-dist-es5` library. You can run the test case `PdfToText.test.ts` to verify contents of PDF file. `getPDFText()` method in `lib/WebActions.ts` class is used for extracting text from PDF file.
373
+
24. For Extracting text from PDF we are using `pdfjs-dist-es5` library. You can run the test case `PdfToText.test.ts` to verify contents of PDF file. `getPDFText()` method in `lib/WebActions.ts` class is used for extracting text from PDF file.
328
374
329
-
24. Accessibility test case is written in `tests/accessibility/Axe.test.ts`, to run this test use the command
375
+
25. Accessibility test case is written in `tests/accessibility/Axe.test.ts`, to run this test use the command
330
376
331
377
**Windows CMD:**
332
378
```batch
@@ -343,10 +389,10 @@ $env:ENV="qa"; npm run test:accessibility
343
389
ENV=qa npm run test:accessibility
344
390
```
345
391
346
-
25. GitHub Actions is configured in `.github/workflows/playwright.yml` file and events(trigger points) are set to pus/pull actions on master branch. Changes in command to run test cases can be made in "Run tests" section in this file.
347
-
26. Once GitHub Actions job is completed Slack notification is triggered to the assigned channel with build status and html-report link. For enabling Slack you have to configure Incoming Webhooks for your repo, below is the great tutorial on that.
392
+
26. GitHub Actions is configured in `.github/workflows/playwright.yml` file and events(trigger points) are set to pus/pull actions on master branch. Changes in command to run test cases can be made in "Run tests" section in this file.
393
+
27. Once GitHub Actions job is completed Slack notification is triggered to the assigned channel with build status and html-report link. For enabling Slack you have to configure Incoming Webhooks for your repo, below is the great tutorial on that.
27. For Configuring Ortoni HTML Report, navigate to "playwright.config.ts" and provide desired changes "reportConfig" variable, then pass this variable in reporter section as ,['ortoni-report', reportConfig]. For more details on this please refer below video
395
+
28. For Configuring Ortoni HTML Report, navigate to "playwright.config.ts" and provide desired changes "reportConfig" variable, then pass this variable in reporter section as ,['ortoni-report', reportConfig]. For more details on this please refer below video
0 commit comments