Network Throttling
Test your website's functionality on low latency networks (2G/3G/LTE) or offline conditions. These networks have variable upload and download speeds that can alter how your website performs on different browsers.
To validate your website on such network profiles, simulate these network conditions using capabilities. If you want the test suite to start with the default network, use the preset capabilities. The device will have unobstructed internet connectivity.
| KEY | VALUES | CAPABILITY |
|---|---|---|
| networkThrottling | Regular 4G, Regular 3G, Regular 2G, Good 3G, Good 2G, Offline, Reset, GPRS, DSL | Based on the user-provided input, this capability starts the test suite with the specified default network. For example, if the user selects Regular 4G, the capability looks like this: capabilities.setCapability("networkThrottling", "Regular 4G"); |
capabilities.setCapability("networkThrottling", "Regular 4G");
List of Network Profiles
The following table lists all available preset network profiles with their speed and latency values.
| CONDITION | MAX DOWNLOAD SPEED (KBPS) | MAX UPLOAD SPEED (KBPS) | LATENCY (MS) |
|---|---|---|---|
| Offline | 0 | 0 | 0 |
| Reset | Reset to default | Reset to default | Reset to default |
| GPRS | 50 | 20 | 500 |
| Regular 2G | 250 | 50 | 300 |
| Good 2G | 450 | 150 | 150 |
| Regular 3G | 750 | 250 | 100 |
| Good 3G | 1 Mbps | 750 | 20 |
| Regular 4G | 4 Mbps | 3 Mbps | 20 |
| DSL | 2 Mbps | 1 Mbps | 5 |
Custom Network Profile: Create custom network conditions using objects. Define the upload speed, max download speed, and latency for the custom condition, as shown in the table above.
Configuring Network Profile
Use the Selenium JavaScript Executor to apply custom network throttling during tests.
// Using executeScript to apply custom network throttling
Map<String, Object> throttleParams = Map.of(
"download", 500, // Maximum download speed in kbps
"upload", 100, // Maximum upload speed in kbps
"latency", 30 // Latency in ms
);
driver.executeScript("lambda-throttle-network", throttleParams);
TestMu AI allows you to select a network profile before running automation tests. This lets you conduct functional tests on low/high latency networks and offline. Use the networkProfile capability as shown below to simulate the network conditions.
| JAVASCRIPT EXECUTOR COMMAND | REQUEST PARAMETERS | EXAMPLE |
|---|---|---|
| networkProfile | condition: a string or object representing browser network conditions | driver.execute_script("networkProfile", {"condition": {"download": 500,"upload": 100,"latency": 30}}) |
Configuring Network Throttling in Test Automation
Define network throttle capabilities in your automation scripts to configure network throttling.
To configure network throttling in automation, use the TestMu AI TestNG GitHub repository to run automation tests.
Configuring Capabilities for Pre-defined Network Settings
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "Chrome");
caps.setCapability("build", "Demo-TestNG");
caps.setCapability("name", "TestNG-Todo-Script-1");
caps.setCapability("networkThrottling", "Regular 4G"); //Set Network Speed to Regular 4G
The following TestNG code validates your TestMu AI credentials for authentication. The code selects basic capabilities such as OS, browser, browser version, and network.
Configuring Custom Network Settings
package com.lambdatest;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestNGTodo1 {
private RemoteWebDriver driver;
private String Status="failed";
@BeforeSuite
public void setup() throws MalformedURLException {
String username = System.getenv("LT_USERNAME");
String authkey = System.getenv("LT_ACCESS_KEY");
String hub = "@hub.lambdatest.com/wd/hub";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "Chrome");
caps.setCapability("build", "Demo-TestNG");
caps.setCapability("name", "TestNG-Todo-Script-1");
caps.setCapability("networkThrottling", true); //To enable network throttling
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
// Custom network throttling using executeScript
Map<String, Object> throttleParams = new HashMap<>();
throttleParams.put("download", 500); // Maximum download speed in kbps
throttleParams.put("upload", 100); // Maximum upload speed in kbps
throttleParams.put("latency", 30); // Latency in ms
// Use executeScript with the provided payload
driver.executeScript("lambda-throttle-network", throttleParams);
}
@Test
public void basicTest() throws InterruptedException {
String spanText;
System.out.println("Loading Url");
Thread.sleep(100);
driver.get("https://4dvanceboy.github.io/lambdatest/todo.html");
Thread.sleep(100);
System.out.println("Checking Box");
driver.findElement(By.name("todo-1")).click();
Thread.sleep(400);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-2")).click();
Thread.sleep(400);
System.out.println("Checking Box");
driver.findElement(By.name("todo-3")).click();
Thread.sleep(400);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-4")).click();
Thread.sleep(400);
driver.findElement(By.id("todotext")).sendKeys(" List Item 6");
driver.findElement(By.id("addbutton")).click();
Thread.sleep(200);
driver.findElement(By.id("todotext")).sendKeys(" List Item 7");
driver.findElement(By.id("addbutton")).click();
Thread.sleep(200);
driver.findElement(By.id("todotext")).sendKeys(" List Item 8");
driver.findElement(By.id("addbutton")).click();
Thread.sleep(200);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-1")).click();
Thread.sleep(300);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-3")).click();
Thread.sleep(300);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-7")).click();
Thread.sleep(300);
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-8")).click();
Thread.sleep(300);
System.out.println("Entering Text");
driver.findElement(By.id("todotext")).sendKeys("Get Taste of Lambda and Stick to It");
Thread.sleep(300);
driver.findElement(By.id("addbutton")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("todo-9")).click();
Thread.sleep(300);
// Let's also assert that the todo we added is present in the list.
spanText = driver.findElementByXPath("/html/body/div/div/div/ul/li[9]/span").getText();
Assert.assertEquals("Get Taste of Lambda and Stick to It", spanText);
Status="passed";
Thread.sleep(150);
System.out.println("TestFinished");
}
@AfterSuite
public void tearDown() {
driver.executeScript("lambda-status=" + Status);
driver.quit();
}
}
Find your defined network capabilities under the section 'Input Config' by navigating to the 'METADATA' section of your automation build-logs.
If you have any questions, feel free to share them with us. Our experts are available on 24/7 Customer chat support. You can also drop us a mail at [email protected]. Happy testing!
