Skip to content
Software Testing Journal
Software Testing Journal

Your daily dose of learning!

  • Blog
  • Help Center
  • Video Playlist
  • Podcast & FAQ
  • Privacy Policy
Software Testing Journal

Your daily dose of learning!

What happens when you also need to test how your application behaves on a slow connection using Selenium?

Dheeraj Gambhir, 2023-10-192023-10-19

Execute the Selenium test suite on a slow network connection:

public class SetNetworkConditions {

public static WebDriver driver;

@Test

public static void setSlowNetwork() throws IOException {

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.manage().window().maximize();

CommandExecutor executor = ((RemoteWebDriver) driver).getCommandExecutor();

// Setting the slow network conditions

Map<String, Comparable> map = new HashMap<String, Comparable>();

map.put(“offline”, false);

map.put(“latency”, 5);

map.put(“download_throughput”, 5000);

map.put(“upload_throughput”, 5000);

Response response = executor.execute(new Command(((RemoteWebDriver) driver).getSessionId(),

“setNetworkConditions”, ImmutableMap.of(“network_conditions”, ImmutableMap.copyOf(map))));

driver.get(“https://testersdigest.blogspot.com”);

long navigationStart = (long) ((JavascriptExecutor) driver)

.executeScript(“return window.performance.timing.navigationStart”);

long responseStart = (long) ((JavascriptExecutor) driver)

.executeScript(“return window.performance.timing.responseStart”);

long domComplete = (long) ((JavascriptExecutor) driver)

.executeScript(“return window.performance.timing.domComplete”);

long backendPerformance = responseStart — navigationStart;

long frontendPerformance = domComplete — responseStart;

System.out.println(“Your web page backend Performance is: “ + backendPerformance + “ milli seconds”);

System.out.println(“Your web page frontend Performance is: “ + frontendPerformance + “ milli seconds”);

driver.quit();

}

}

If you find this post helpful, please share them with your colleagues and friends.

  • Facebook
  • Twitter
  • LinkedIn
  • Email
Automation SeleniumTips

Post navigation

Previous post
Next post
©2025 Software Testing Journal | WordPress Theme by SuperbThemes