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
@@ -29,7 +31,7 @@ where by default it looks for any files in the format of `test_*.py` or `*_test.
29
31
functions in the file starting with `test_` and if found, will execute that function as a test and collect the result.
30
32
31
33
pytest will spin up any utilities it needs to execute tests (including any we choose to define), which for this framework includes a number of
32
-
Playwright-based objects we would likely want to utilise, including:
34
+
Playwright-specific objects we would likely want to utilise, including:
33
35
34
36
-`page`: The Playwright page object, which we use to interact with a browser page during tests. You'll likely use this object for every test.
35
37
-`browser`: The Playwright browser object, which we use to create and manage the browser directly and create new pages if required. It's unlikely you'll need to include this unless you have a very specific browser test.
@@ -67,10 +69,35 @@ arguments for the test like so:
This allows for easy reuse of steps and reducing overall test maintenance going forward. Fixtures can play a powerful part in how you design
92
+
your tests, including creating utilities available for global use, or just adding repeatable actions in a way that can overall reduce the
93
+
maintenance effort of your tests going forward.
94
+
95
+
Further reading on fixtures can be found in the [Playwright documentation](https://playwright.dev/python/docs/test-runners#fixtures).
70
96
71
97
## Utilising Playwright `codegen`
72
98
73
-
If you're new to Playwright, Python or automating tests generally, then Playwright provides a code generation tool that allows you to manually navigate
99
+
If you're new to Playwright, Python or automating tests generally, then
100
+
[Playwright provides a code generation tool](https://playwright.dev/python/docs/codegen#recording-a-test) that allows you to manually navigate
74
101
through a browser to generate the code for a test. You can access the `codegen` tool by using the following command:
75
102
76
103
# Load a empty browser window
@@ -104,6 +131,44 @@ Whilst the `codegen` tool will provide you with the basic code to get started, i
104
131
code that has been provided and refine as needed. Having the ability to generate the code in this fashion allows you to create tests quickly and build up
105
132
understanding of how to construct tests using Playwright Python, but you will soon discover that they may not be the most efficient in their raw state!
106
133
134
+
## Utilising Playwright `show-trace`
135
+
136
+
If you encounter issues when trying to execute your newly created tests,
137
+
[Playwright also provides a trace functionality](https://playwright.dev/python/docs/trace-viewer-intro) that records each action a test
138
+
undertakes and outlines where any issues or errors have occurred. This can be useful for a number of reasons, including:
139
+
140
+
- Easily pinpointing problems within a test, including functional and performance concerns
141
+
- Generating evidence to show stakeholders what a test actually does during execution
142
+
- The ZIP file generated can be opened on any machine, or via a [browser utility provided by Playwright](https://trace.playwright.dev/)
143
+
144
+
To open a trace file, use the following command (replacing `<path-to-file>` with the actual path to the trace.zip file generated):
145
+
146
+
# Opens a trace file
147
+
playwright show-trace <path-to-file>
148
+
149
+
A trace file when opened looks like this:
150
+
151
+
<!-- vale off -->
152
+

153
+
<!-- vale on -->
154
+
155
+
The primary information provided within the trace is:
156
+
157
+
- A timeline of events with screenshots (at the top of the report)
158
+
- A summary of each action undertaken (on the left side of the report)
159
+
- A screenshot of the selected action (on the right side of the report)
160
+
- The network and test activity (at the bottom of the report)
161
+
162
+
As you can see, it provides a lot of information to work with to help demonstrate what a test is doing, and diagnosing
163
+
any issues when something goes wrong.
164
+
165
+
## Further Reading
166
+
167
+
Here are some useful links for further reading beyond these guides:
Copy file name to clipboardExpand all lines: docs/getting-started/2_Blueprint_File_Breakdown.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,11 @@ This file outlines the packages required from the Python Package Index (PyPI) to
27
27
This file outlines the configuration of pytest, and ultimately how Playwright also executes. A couple of things to note:
28
28
29
29
- The `log_cli` section covers default logging provided by pytest - we have defaulted this to on at INFO level, but this can be amended as needed.
30
-
- The `addopts` section will run any commands you want to run by default for each execution and can be overwritten using the appropriate options via the command line. For example, you can override the `--tracing` level to on by executing pytest using: `pytest --tracing=on`.
30
+
- The `addopts` section will run any commands you want to run by default for each execution and can be overwritten using the appropriate options via the command line. For example, you can override the `--tracing` level to on by executing pytest using: `pytest --tracing=on`. The options we have turned on by default are:
31
+
- Do not run the tests marked utils by default (these are the unit tests for this project and do not use Playwright)
32
+
- Generate a HTML report in a single file, and output it in the `test-results` directory with the name `report.html`
33
+
- Generate a JSON report, omitting some collection data and then output it in the `test-results` directory with the name `results.json`
34
+
- Only generate Playwright stack-trace files when a test fails
31
35
- The `markers` section is for organizing any marks (or tags) you want to apply to your tests, for example by a business area or a testing type. If you don't include your marks in this list, pytest will give you a warning until they have either been added here or programmatically within the code.
32
36
33
37
Any configuration you want to apply to all of your test executions should be placed in this file where possible, to ensure easy maintenance.
0 commit comments