Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 4322680

Browse files
authored
Specific browser options (#454)
* Specific browser options * Debug helper functions * Add information about new options
1 parent ca21d26 commit 4322680

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

README.md

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ module.exports = {
119119
- `collectCoverage` <[boolean]>. Enables the coverage collection of the `saveCoverage(page)` calls to the `.nyc_output/coverage.json` file.
120120
- `serverOptions` <[object]>. [All `jest-process-manager` options](https://github.com/playwright-community/jest-process-manager#options).
121121
- `selectors` <[array]>. Define [selectors](https://github.com/microsoft/playwright/blob/v0.11.1/docs/api.md#class-selectors). Each selector must be an object with name and script properties.
122+
- `skipInitialization` <[boolean]>. Add you ability to skip first setup `playwright` process. Possible use cases can be found [here](https://github.com/playwright-community/jest-playwright/issues/424)
123+
- `useDefaultBrowserType` <[boolean]>. [Sometimes](https://github.com/microsoft/playwright/issues/2787) `browser` + `device` combinations don't have any sense. With this option tests will be run with [`defaultBrowserType`](https://github.com/microsoft/playwright/pull/3731) of device
124+
125+
### Specific browser options
126+
127+
For `launchOptions`, `connectOptions` and `contextOptions` you can define special browser options.
128+
129+
```js
130+
// jest-playwright.config.js
131+
module.exports = {
132+
connectOptions: {
133+
chromium: {
134+
wsEndpoint: 'ws://chrome.proxy.com:4444'
135+
},
136+
firefox: {
137+
wsEndpoint: 'ws://firefox.proxy.com:4444'
138+
}
139+
},
140+
...
141+
}
142+
```
122143

123144
### Device configuration
124145

@@ -166,7 +187,7 @@ module.exports = {
166187

167188
### Usage with [query-selector-shadow-dom](https://github.com/Georgegriff/query-selector-shadow-dom) in `jest-playwright.config.js`:
168189

169-
```javascript
190+
```js
170191
const {
171192
selectorEngine,
172193
} = require('query-selector-shadow-dom/plugins/playwright');
@@ -177,7 +198,6 @@ module.exports = {
177198
],
178199
...
179200
}
180-
181201
```
182202

183203
### Notes
@@ -199,7 +219,7 @@ All of them are available globally in each Jest test. If you are using ESLint an
199219

200220
Debugging tests can be hard sometimes and it is very useful to be able to pause tests in order to inspect the browser. Jest Playwright exposes a method `jestPlaywright.debug()` that suspends test execution and gives you opportunity to see what's going on in the browser.
201221

202-
```javascript
222+
```js
203223
await jestPlaywright.debug()
204224
```
205225

@@ -235,6 +255,54 @@ beforeEach(async () => {
235255

236256
You can use this snippet to reset current browser for each individual test. It will reset browser, context and page.
237257

258+
## Debug helper functions
259+
260+
`jest-playwright` provides some functions to debug your tests
261+
262+
### jestPlaywrightDebug
263+
264+
This helper function provide you ability to run specific tests in `debug` mode. It will run test in `headless` mode.
265+
You can find more information [here](https://github.com/playwright-community/jest-playwright/issues/216)
266+
267+
```js
268+
test.jestPlaywrightDebug('failed', async ({ page }) => {
269+
await page.goto('https://github.com/')
270+
const title = await page.title()
271+
await expect(title).toBe('Google')
272+
})
273+
```
274+
275+
Also you can define options for `debug` mode with `debugOptions`:
276+
277+
```js
278+
// jest-playwright.config.js
279+
module.exports = {
280+
debugOptions: {
281+
...
282+
contextOptions: {
283+
offline: true
284+
}
285+
}
286+
...
287+
}
288+
```
289+
290+
### jestPlaywrightConfig
291+
292+
This helper function provide you ability to run specific tests with passed options.
293+
294+
```js
295+
test.jestPlaywrightConfig(
296+
{
297+
// your jest-playwright options
298+
},
299+
'test name',
300+
async () => {
301+
/* ... */
302+
},
303+
)
304+
```
305+
238306
## Tracking the coverage
239307

240308
It's possible to track the coverage of the end-to-end tests with the [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) Babel plugin configured. It needs to be included in the web application which you are gonna test otherwise it won't work. To use it, you have to set `collectCoverage` in the `jest-playwright.config.js` to `true`. Per default the test coverage will be automatically saved after each navigation change (`beforeunload` event). If a certain code path is not covered, you can manually call and add the corresponding `saveCoverage(page)` call to your tests like that:
@@ -386,8 +454,8 @@ const PlaywrightRunner = require('jest-playwright-preset/lib/PlaywrightRunner')
386454

387455
class CustomRunner extends PlaywrightRunner {
388456
constructor(...args) {
389-
super(...args);
390-
this.isSerial = true;
457+
super(...args)
458+
this.isSerial = true
391459
}
392460
}
393461

0 commit comments

Comments
 (0)