Select Page
Selenium Testing

How to set Network Conditions in Selenium?

In this blog article, you will learn to set Network Conditions in Selenium.

Listen to this blog

If you want to run your Selenium script in different network conditions, you can do it using Chrome CommandExecutor.

Using Chrome Developer Tools, you can emulate different network conditions to check your app’s performance. If you want this to be implemented in automation testing, we have a command to do that. Let’s see with an example.

System.setProperty("webdriver.chrome.driver","drivers/chromedriver.exe");

ChromeDriver driver = new ChromeDriver();
        
CommandExecutor executor = driver.getCommandExecutor();
        
//Set the conditions
Map<String, Object> map = new HashMap<String, Object>();
map.put("offline", false);
map.put("latency", 5);
map.put("download_throughput", 5000);
map.put("upload_throughput", 5000);

Response response = executor.execute(new Command(driver.getSessionId(),"setNetworkConditions", ImmutableMap.of("network_conditions", ImmutableMap.copyOf(map))));

driver.get("http://google.com");
  

Initially, we didn’t have this implementation in Java bindings to set network conditions. After a fix from Andrii Rohovets, GET_NETWORK_CONDITIONS, SET_NETWORK_CONDITIONS and DELETE_NETWORK_CONDITIONS are available to emulate network conditions in Selenium & Java.

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility