What happens when you also need to test how your application behaves on a slow connection using Selenium?
Execute 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();
}
}
Comments
Post a Comment