CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver

Selenium Chrome Driver provides WebDriver implementation for Google Chrome with Chrome DevTools Protocol support, network conditions simulation, permissions management, media casting capabilities, and Chrome-specific service configuration.

Pending
Overview
Eval results
Files

network-conditions.mddocs/

Network Conditions

Network conditions simulation allows testing applications under various connectivity scenarios including different latencies, throughput limitations, and offline conditions.

Network Conditions Management

Get Network Conditions

Retrieve current network condition settings.

public ChromiumNetworkConditions getNetworkConditions();

Returns: ChromiumNetworkConditions - Current network condition settings

Usage Example:

// ChromiumDriver is typically used through subclasses like ChromeDriver, EdgeDriver
ChromiumDriver driver = ...; // Obtain from ChromeDriver, EdgeDriver, etc.

// Get current network conditions
ChromiumNetworkConditions conditions = driver.getNetworkConditions(); 
boolean isOffline = conditions.getOffline();
Duration latency = conditions.getLatency();

Set Network Conditions

Apply network condition settings to simulate different connectivity scenarios.

public void setNetworkConditions(ChromiumNetworkConditions networkConditions);

Parameters:

  • networkConditions (ChromiumNetworkConditions): Network conditions to apply

Usage Example:

import java.time.Duration;

ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();

// Simulate slow 3G connection
conditions.setOffline(false);
conditions.setLatency(Duration.ofMillis(300));
conditions.setDownloadThroughput(400); // kb/s
conditions.setUploadThroughput(200);   // kb/s

driver.setNetworkConditions(conditions);

Delete Network Conditions

Reset network conditions to default (no simulation).

public void deleteNetworkConditions();

Usage Example:

// Reset to normal network conditions
driver.deleteNetworkConditions();

ChromiumNetworkConditions Configuration

Offline Mode

Control whether the network is simulated as offline.

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

Parameters:

  • offline (boolean): Whether to simulate offline mode

Usage Example:

ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();

// Enable offline mode
conditions.setOffline(true);
driver.setNetworkConditions(conditions);

// Navigate - this will fail due to offline mode
driver.get("https://example.com"); // Will show Chrome's offline page

// Disable offline mode
conditions.setOffline(false);
driver.setNetworkConditions(conditions);
driver.get("https://example.com"); // Will work normally

Network Latency

Configure simulated network latency.

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

Parameters:

  • latency (Duration): Network latency to simulate

Usage Example:

import java.time.Duration;

ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();

// Simulate high latency (500ms)
conditions.setLatency(Duration.ofMillis(500));

// Simulate moderate latency (100ms)  
conditions.setLatency(Duration.ofMillis(100));

// No additional latency
conditions.setLatency(Duration.ZERO);

Download Throughput

Set download bandwidth limitations.

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

Parameters:

  • downloadThroughput (int): Download speed in kilobytes per second

Usage Example:

ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();

// Simulate different connection speeds
conditions.setDownloadThroughput(50);    // Slow 2G: ~50 KB/s
conditions.setDownloadThroughput(250);   // 3G: ~250 KB/s  
conditions.setDownloadThroughput(1500);  // 4G: ~1.5 MB/s
conditions.setDownloadThroughput(10000); // Fast broadband: ~10 MB/s

Upload Throughput

Set upload bandwidth limitations.

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

Parameters:

  • uploadThroughput (int): Upload speed in kilobytes per second

Usage Example:

ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();

// Typical upload speeds (usually lower than download)
conditions.setUploadThroughput(25);    // Slow 2G upload
conditions.setUploadThroughput(125);   // 3G upload
conditions.setUploadThroughput(750);   // 4G upload  
conditions.setUploadThroughput(5000);  // Fast broadband upload

Common Network Profiles

Mobile Network Profiles

// Slow 2G
ChromiumNetworkConditions slow2G = new ChromiumNetworkConditions();
slow2G.setOffline(false);
slow2G.setLatency(Duration.ofMillis(2000));
slow2G.setDownloadThroughput(50);
slow2G.setUploadThroughput(25);

// 3G
ChromiumNetworkConditions threeG = new ChromiumNetworkConditions();
threeG.setOffline(false);
threeG.setLatency(Duration.ofMillis(300));
threeG.setDownloadThroughput(400);
threeG.setUploadThroughput(200);

// 4G
ChromiumNetworkConditions fourG = new ChromiumNetworkConditions();
fourG.setOffline(false);
fourG.setLatency(Duration.ofMillis(50));
fourG.setDownloadThroughput(1500);
fourG.setUploadThroughput(750);

Offline Testing

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

// Test offline functionality
driver.get("https://example.com"); // Will show offline page
// Test service worker, cached content, etc.

High Latency Testing

// Simulate satellite connection (high latency, decent throughput)
ChromiumNetworkConditions satellite = new ChromiumNetworkConditions();
satellite.setOffline(false);
satellite.setLatency(Duration.ofMillis(800)); // High latency
satellite.setDownloadThroughput(2000);         // Good throughput
satellite.setUploadThroughput(1000);

Constants

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";

These constants represent the keys used in the underlying network conditions implementation.

Command Integration

The network conditions functionality integrates with ChromiumDriverCommandExecutor through these commands:

// Command constants from AddHasNetworkConditions
public static final String GET_NETWORK_CONDITIONS = "getNetworkConditions";
public static final String SET_NETWORK_CONDITIONS = "setNetworkConditions"; 
public static final String DELETE_NETWORK_CONDITIONS = "deleteNetworkConditions";

Complete Testing Example

import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumNetworkConditions;
import java.time.Duration;

public class NetworkConditionsTest {
    public void testUnderVariousNetworkConditions() {
        ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");
        
        try {
            // Test under normal conditions
            driver.get("https://example.com");
            long normalLoadTime = measurePageLoadTime();
            
            // Test under slow 3G
            ChromiumNetworkConditions slow3G = new ChromiumNetworkConditions();
            slow3G.setLatency(Duration.ofMillis(300));
            slow3G.setDownloadThroughput(400);
            slow3G.setUploadThroughput(200);
            
            driver.setNetworkConditions(slow3G);
            driver.get("https://example.com");
            long slow3GLoadTime = measurePageLoadTime();
            
            // Test offline functionality
            ChromiumNetworkConditions offline = new ChromiumNetworkConditions();
            offline.setOffline(true);
            
            driver.setNetworkConditions(offline);
            driver.get("https://example.com");
            // Verify offline page or cached content
            
            // Reset conditions
            driver.deleteNetworkConditions();
            
        } finally {
            driver.quit();
        }
    }
    
    private long measurePageLoadTime() {
        // Implementation to measure page load time
        return System.currentTimeMillis();
    }
}

Error Handling

Network conditions operations may encounter these exceptions:

  • IllegalArgumentException: When null network conditions are provided
  • WebDriverException: When network condition commands fail to execute
try {
    ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();
    conditions.setLatency(Duration.ofMillis(100));
    driver.setNetworkConditions(conditions);
} catch (IllegalArgumentException e) {
    System.err.println("Invalid network conditions: " + e.getMessage());
} catch (WebDriverException e) {
    System.err.println("Failed to set network conditions: " + e.getMessage());
}

Best Practices

  1. Realistic Profiles: Use realistic network profiles based on actual mobile network conditions
  2. Gradual Testing: Test with progressively slower conditions to identify performance bottlenecks
  3. Offline Testing: Always test offline scenarios for PWAs and applications with offline capabilities
  4. Cleanup: Reset network conditions after tests to avoid affecting subsequent tests
  5. Load Time Monitoring: Measure and assert on page load times under different conditions
  6. Progressive Enhancement: Use network simulation to test progressive loading strategies
  7. Error Scenarios: Test how applications handle network timeouts and interruptions
  8. Mobile First: Start testing with mobile network conditions, then improve for faster connections

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver

docs

application-launching.md

browser-configuration.md

devtools-protocol.md

index.md

media-casting.md

network-conditions.md

permissions-management.md

service-management.md

webdriver-operations.md

tile.json