This repository was archived by the owner on Sep 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +1023
-3271
lines changed Expand file tree Collapse file tree 3 files changed +1023
-3271
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,49 @@ If there is no defined browsers in config it will run tests for chromium browser
187
187
"test:parallel" : " jest-playwright --parallel"
188
188
```
189
189
190
+ ## Usage with [ jest-circus] ( https://github.com/facebook/jest/tree/master/packages/jest-circus )
191
+
192
+ You can use ** jest-playwright** with ** jest-circus** runner for taking screenshots during test failures for example:
193
+
194
+ ** jest.config.json**
195
+
196
+ ``` json
197
+ "testRunner" : " jest-circus/runner" ,
198
+ "testEnvironment" : " ./CustomEnvironment.js"
199
+ ```
200
+
201
+ ** CustomEnvironment.js**
202
+
203
+ ``` js
204
+ const PlaywrightEnvironment = require (' jest-playwright-preset/lib/PlaywrightEnvironment' )
205
+ .default
206
+
207
+ class CustomEnvironment extends PlaywrightEnvironment {
208
+ async setup () {
209
+ await super .setup ()
210
+ // Your setup
211
+ }
212
+
213
+ async teardown () {
214
+ // Your teardown
215
+ await super .teardown ()
216
+ }
217
+
218
+ async handleTestEvent (event ) {
219
+ if (event .name === ' test_done' && event .test .errors .length > 0 ) {
220
+ const parentName = event .test .parent .name .replace (/ \W / g , ' -' )
221
+ const specName = event .test .name .replace (/ \W / g , ' -' )
222
+
223
+ await this .global .page .screenshot ({
224
+ path: ` screenshots/${ parentName} _${ specName} .png` ,
225
+ })
226
+ }
227
+ }
228
+ }
229
+
230
+ module .exports = CustomEnvironment
231
+ ```
232
+
190
233
## Usage with Typescript
191
234
192
235
Example Jest configuration in combination with [ ts-jest] ( https://github.com/kulshekhar/ts-jest ) :
You can’t perform that action at this time.
0 commit comments