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
Copy file name to clipboardExpand all lines: docs/helpers/Puppeteer.md
+61-30Lines changed: 61 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -39,26 +39,26 @@ Type: [object][4]
39
39
40
40
-`url`**[string][6]** base url of website to be tested
41
41
-`basicAuth`**[object][4]?** (optional) the basic authentication to pass to base url. Example: {username: 'username', password: 'password'}
42
-
-`show`**[boolean][20]?** show Google Chrome window for debug.
43
-
-`restart`**[boolean][20]?** restart browser between tests.
44
-
-`disableScreenshots`**[boolean][20]?** don't save screenshot on failure.
45
-
-`fullPageScreenshots`**[boolean][20]?** make full page screenshots on failure.
46
-
-`uniqueScreenshotNames`**[boolean][20]?** option to prevent screenshot override if you have scenarios with the same name in different suites.
47
-
-`trace`**[boolean][20]?** record [tracing information][24] with screenshots.
48
-
-`keepTraceForPassedTests`**[boolean][20]?** save trace for passed tests.
49
-
-`keepBrowserState`**[boolean][20]?** keep browser state between tests when `restart` is set to false.
50
-
-`keepCookies`**[boolean][20]?** keep cookies between tests when `restart` is set to false.
42
+
-`show`**[boolean][22]?** show Google Chrome window for debug.
43
+
-`restart`**[boolean][22]?** restart browser between tests.
44
+
-`disableScreenshots`**[boolean][22]?** don't save screenshot on failure.
45
+
-`fullPageScreenshots`**[boolean][22]?** make full page screenshots on failure.
46
+
-`uniqueScreenshotNames`**[boolean][22]?** option to prevent screenshot override if you have scenarios with the same name in different suites.
47
+
-`trace`**[boolean][22]?** record [tracing information][26] with screenshots.
48
+
-`keepTraceForPassedTests`**[boolean][22]?** save trace for passed tests.
49
+
-`keepBrowserState`**[boolean][22]?** keep browser state between tests when `restart` is set to false.
50
+
-`keepCookies`**[boolean][22]?** keep cookies between tests when `restart` is set to false.
51
51
-`waitForAction`**[number][10]?** how long to wait after click, doubleClick or PressKey actions in ms. Default: 100.
52
-
-`waitForNavigation`**[string][6]?** when to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API][23]. Array values are accepted as well.
52
+
-`waitForNavigation`**[string][6]?** when to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API][25]. Array values are accepted as well.
53
53
-`pressKeyDelay`**[number][10]?** delay between key presses in ms. Used when calling Puppeteers page.type(...) in fillField/appendField
54
54
-`getPageTimeout`**[number][10]?** config option to set maximum navigation time in milliseconds. If the timeout is set to 0, then timeout will be disabled.
55
55
-`waitForTimeout`**[number][10]?** default wait* timeout in ms.
56
56
-`windowSize`**[string][6]?** default window size. Set a dimension in format WIDTHxHEIGHT like `640x480`.
57
57
-`userAgent`**[string][6]?** user-agent string.
58
-
-`manualStart`**[boolean][20]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
58
+
-`manualStart`**[boolean][22]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
59
59
-`browser`**[string][6]?** can be changed to `firefox` when using [puppeteer-firefox][2].
60
-
-`chrome`**[object][4]?** pass additional [Puppeteer run options][25].
61
-
-`highlightElement`**[boolean][20]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
60
+
-`chrome`**[object][4]?** pass additional [Puppeteer run options][27].
61
+
-`highlightElement`**[boolean][22]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
62
62
63
63
64
64
@@ -1255,6 +1255,21 @@ I.seeFile('avatar.jpg');
1255
1255
1256
1256
- `downloadPath` **[string][6]** change this parameter to set another directory for saving
1257
1257
1258
+
### mockRoute
1259
+
1260
+
Mocks network request using [`Request Interception`][17]
Web application sends various requests to local services (Rest API, GraphQL) or to 3rd party services (CDNS, Google Analytics, etc).
222
-
When you run tests with Puppeteer you can control those requests by mocking them. For instance, you can speed up your tests by blocking trackers, Google Analytics, and other services you don't control.
223
-
224
-
Also you can replace real request with a one explicitly defined. This is useful when you want to isolate application testing from a backend. For instance, if you don't want to save data to database, and you know the request which performs save, you can mock the request, so application will treat this as valid response, but no data will be actually saved.
225
-
226
-
To mock requests enable additional helper [MockRequest](/helpers/MockRequest) (which is based on Polly.js).
221
+
Network requests & responses can be mocked and modified. Use `mockRoute` which strictly follows [Puppeteer's `setRequestInterception` API](https://pptr.dev/next/api/puppeteer.page.setrequestinterception).
227
222
228
223
```js
229
-
helpers: {
230
-
Puppeteer: {
231
-
// regular Puppeteer config here
232
-
},
233
-
MockRequest: {}
234
-
}
235
-
```
236
-
237
-
And install additional packages:
238
-
239
-
```
240
-
npm i @pollyjs/core @pollyjs/adapter-puppeteer --save-dev
241
-
```
242
-
243
-
After an installation function `mockRequest` will be added to `I` object. You can use it to explicitly define which requests to block and which response they should return instead:
244
-
245
-
```js
246
-
// block all Google Analytics calls
247
-
I.mockRequest('/google-analytics/*path', 200);
248
-
// return an empty successful response
249
-
I.mockRequest('GET', '/api/users', 200);
250
-
// block post requests to /api/users and return predefined object
0 commit comments