Skip to content

Commit 5e2e825

Browse files
committed
frontends/web: add README.md on Playwright testing.
1 parent 15eef7f commit 5e2e825

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ To run all test suites, execute `make webtest`.
122122
Playwright is used to perform automatic test on some use cases on the webdev version.
123123

124124
Tests are located under [`frontends/web/tests`](/frontends/web/tests) and can be run with
125+
125126
`make webe2etest`
126127

128+
More info can be found [here](/frontends/web/tests/README.md)
129+
127130
#### Run the HTTP API
128131

129132
Run `make servewallet` to compile the code and run `servewallet`. `servewallet` is a devtool which

frontends/web/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineConfig({
1313
{
1414
command: `make -C ../.. buildweb && make -C ../.. webserve`,
1515
port: FRONTEND_PORT,
16-
reuseExistingServer: true,
16+
reuseExistingServer: true, // If a server is already listening on FRONTEND_PORT, use it. Useful for local development.
1717
timeout: 120_000,
1818
},
1919
],

frontends/web/tests/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# E2E Testing with Playwright
2+
3+
This directory contains tests that are run in Github's CI (and can also be run locally) to ensure that some basic use-cases are covered.
4+
5+
The following is a breakdown of the main components:
6+
7+
[playwright.config.ts](../playwright.config.ts) contains the test configuration: this is the entry point for all tests.
8+
It specifies how the webserver (i.e. the frontend) is built, what [projects](https://playwright.dev/docs/test-projects) are enabled, and some other configuration options. Of these, some interesting ones are:
9+
10+
``` typescript
11+
video: 'retain-on-failure'
12+
screenshot: 'only-on-failure',
13+
trace: 'retain-on-failure',
14+
```
15+
16+
These option specify that video of the execution, screenshot of the last state, and the trace, are only kept when a test fails.
17+
These can be used to debug failing tests (see [Debugging tests](#debugging-tests)).
18+
19+
``` typescript
20+
launchOptions: {
21+
// By default, tests are not run in slow motion.
22+
// Can be enabled by setting the PLAYWRIGHT_SLOW_MO environment variable to a value > 0.
23+
// This is useful for running tests locally.
24+
slowMo: PLAYWRIGHT_SLOW_MO,
25+
},
26+
```
27+
As explained in the comment, `slowMo` is an option that allows test to run at a slower pace. By default Playwright is very fast and hard to follow. By setting the env var `PLAYWRIGHT_SLOW_MO` to a value `N`, Playwright will wait `N` milliseconds between actions.
28+
29+
``` typescript
30+
headless: true
31+
```
32+
33+
If launching a test locally, and you want to see the browser in real time, you need to either change this value to `false`, or launch the test manually from the terminal with the `--headed` option, for example
34+
35+
`npx playwright test <path-to-test-file> --headed`
36+
37+
38+
## Debugging tests
39+
40+
When a test fails, Playwright will output elements useful for debugging; these are either in [test-results](./test-results), if running locally, or uploaded as artifact if running in CI.
41+
42+
The following four items will be uploaded for each failing tests:
43+
44+
* error-context.md - a yaml representation of the page at the moment of failure
45+
* screenshot.png - a screenshot of the webpage at the moment of failure
46+
* video.webm - a recording of the browser during the test execution
47+
* trace.zip - to be inspected with `playwright trace`
48+
49+
Note: video.webm can be hard to utilize as it maintains the speed of execution of the test; so for test ran on Github CI, it will be really quick.
50+
51+
Much more useful is `trace.zip`, that can be inspected with `npx playwright show-trace trace.zip`; this will open a window that can be used to navigate through all the steps of the test, with a corresponding screenshot of the webpage at each step.
52+
53+
Other options, when running locally, are to use the `--ui` or the `--debug` flags, as explained in the [official documentation](https://playwright.dev/docs/running-tests#debugging-tests).

0 commit comments

Comments
 (0)