Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium ChromiumNetworkConditions

From Leeroopedia
Knowledge Sources
Domains WebDriver, Chromium_Browser
Last Updated 2026-02-12 00:00 GMT

Overview

ChromiumNetworkConditions is a Java class that models network condition parameters (offline state, latency, download/upload throughput) for simulating various network environments in Chromium-based browsers.

Description

The ChromiumNetworkConditions class acts as a plain data object holding four configurable properties: whether the network should be treated as offline (offline), the simulated connection latency (latency as a java.time.Duration), and the download and upload throughput rates in kb/second. It exposes string constants (OFFLINE, LATENCY, DOWNLOAD_THROUGHPUT, UPLOAD_THROUGHPUT) matching the wire-protocol field names expected by ChromeDriver. Defaults are: offline = false, latency = Duration.ZERO, and both throughput values = -1 (unlimited).

Usage

Use ChromiumNetworkConditions when you need to throttle or simulate network conditions during automated browser testing. Instances of this class are passed to and returned from the HasNetworkConditions interface methods on ChromeDriver or EdgeDriver.

Code Reference

Source Location

Signature

public class ChromiumNetworkConditions {
    public static final String OFFLINE = "offline";
    public static final String LATENCY = "latency";
    public static final String DOWNLOAD_THROUGHPUT = "download_throughput";
    public static final String UPLOAD_THROUGHPUT = "upload_throughput";

    public boolean getOffline();
    public void setOffline(boolean offline);

    public Duration getLatency();
    public void setLatency(Duration latency);

    public int getDownloadThroughput();
    public void setDownloadThroughput(int downloadThroughput);

    public int getUploadThroughput();
    public void setUploadThroughput(int uploadThroughput);
}

Import

import org.openqa.selenium.chromium.ChromiumNetworkConditions;

I/O Contract

Constants

Constant Value Description
OFFLINE "offline" Wire-protocol key for the offline flag
LATENCY "latency" Wire-protocol key for latency
DOWNLOAD_THROUGHPUT "download_throughput" Wire-protocol key for download throughput
UPLOAD_THROUGHPUT "upload_throughput" Wire-protocol key for upload throughput

Properties

Property Type Default Description
offline boolean false When true, the network is simulated as offline.
latency java.time.Duration Duration.ZERO Simulated connection latency (typically in milliseconds).
downloadThroughput int -1 Download speed in kb/second. -1 indicates unlimited.
uploadThroughput int -1 Upload speed in kb/second. -1 indicates unlimited.

Methods

Method Parameters Return Type Description
getOffline() none boolean Returns whether the network is simulated as offline.
setOffline(boolean) offline void Sets offline simulation state.
getLatency() none Duration Returns the current simulated latency.
setLatency(Duration) latency void Sets the simulated latency.
getDownloadThroughput() none int Returns the download throughput in kb/second.
setDownloadThroughput(int) downloadThroughput void Sets the download throughput in kb/second.
getUploadThroughput() none int Returns the upload throughput in kb/second.
setUploadThroughput(int) uploadThroughput void Sets the upload throughput in kb/second.

Usage Examples

// Create network conditions simulating a slow 3G connection
ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();
conditions.setOffline(false);
conditions.setLatency(Duration.ofMillis(100));
conditions.setDownloadThroughput(750);  // 750 kb/s
conditions.setUploadThroughput(250);    // 250 kb/s

// Apply to a ChromeDriver instance (via HasNetworkConditions)
ChromeDriver driver = new ChromeDriver();
driver.setNetworkConditions(conditions);

// Retrieve current network conditions
ChromiumNetworkConditions current = driver.getNetworkConditions();
System.out.println("Offline: " + current.getOffline());
System.out.println("Latency: " + current.getLatency().toMillis() + "ms");

// Simulate offline mode
ChromiumNetworkConditions offlineConditions = new ChromiumNetworkConditions();
offlineConditions.setOffline(true);
driver.setNetworkConditions(offlineConditions);

// Reset to defaults
driver.deleteNetworkConditions();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment