Skip to main content

How to Manage Network Bandwidth

Overview

warning

This recipe only works when using Chrome DevTools Protocol (CDP).

Read details in the section “How to use CDP in Testplane”.

A large number of users access services from mobile devices where internet speed can be quite slow or may even drop out intermittently. In webdriverio, we can limit network bandwidth using the throttle method, thereby testing the website's behavior under various network conditions.

Besides custom settings, the throttle method supports the following ready-made presets:

  • offline | online
  • GPRS
  • Regular2G | Good2G
  • Regular3G | Good3G
  • Regular4G
  • DSL
  • WiFi

Example 1: Emulating a 2G Connection

Let's emulate a 2G connection and open yandex.ru in Chrome with phone emulation:

it("should open yandex.ru with emulation of 2G-connection", async function () {
// Emulate a 2G connection
await this.browser.throttle("Good2G");

await this.browser.url("https://yandex.ru");
});

Example 2: Emulating a Network with Given Characteristics

We can also emulate a connection with specific characteristics:

it("should open yandex.ru with emulation of custom connection", async function () {
// Emulate a network connection with specified characteristics
await this.browser.throttle({
offline: false, // emulate offline state
downloadThroughput: (10 * 1024) / 8, // max download bandwidth (byte/sec)
uploadThroughput: (10 * 1024) / 8, // max upload bandwidth (byte/sec)
latency: 10, // min latency from sending the request to receiving the response headers
});

await this.browser.url("https://yandex.ru");
});