throttle
Throttle the network capabilities of the browser. This can help to emulate certain scenarios where a user loses their internet connection and your app needs to address that.
There are many presets available with default configurations for ease of use.
They are offline
, GPRS
, Regular2G
, Good2G
, Regular3G
, Good3G
,
Regular4G
, DSL
, WiFi
, online
.
You can see the values for these presets in the source code.
info
Note that using the throttle
command requires support for Chrome DevTools protocol and e.g.
can not be used when running automated tests in the cloud. Find out more in the
Automation Protocols section.
Usage
browser.throttle({ offline, latency, downloadThroughput, uploadThroughput })
Parameters
Name | Type | Details |
---|---|---|
params | ThrottleOptions | parameters for throttling |
params.offline | Boolean | True to emulate internet disconnection. |
params.latency | Number | Minimum latency from request sent to response headers received (ms). |
params.downloadThroughput | Number | Maximal aggregated download throughput (bytes/sec). -1 disables download throttling. |
params.uploadThroughput | Number | Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling. |
Example
- Asynchronous Mode
- Synchronous Mode
it('should throttle the network', async () => {
// via static string preset
await browser.throttle('Regular 3G')
// via custom values
await browser.throttle({
offline: false,
downloadThroughput: 200 * 1024 / 8,
uploadThroughput: 200 * 1024 / 8,
latency: 20
})
});
it('should throttle the network', () => {
// via static string preset
browser.throttle('Regular 3G')
// via custom values
browser.throttle({
offline: false,
downloadThroughput: 200 * 1024 / 8,
uploadThroughput: 200 * 1024 / 8,
latency: 20
})
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.