Skip to main content

Posts

Showing posts with the label Performance

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.performa...

Measuring page load time using Selenium

There are many tools that are designed specifically to measure a load of your web pages such as LoadRunner, JMeter, WebLoad, etc. and preference should be given to these tools only. But in case, there is an ask to do it using Selenium, we can use Performance Timing and Navigation Interface APIs to measure the page load time on client-side: - https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming - https://www.w3.org/TR/navigation-timing/#sec-navigation-timing-interface The first image shows when we are executing it manually on the Chrome Dev Tools console. We can use the output generated by these APIs in our Se framework (if required) as shown in the Second Image. P.S. As from Se4 alpha-3 onwards, we can directly play with Dev Tools- I will check if we can directly use it instead of capturing time using these APIs.  #selenium   #loadTime   #devTools   #testAutomation   #seleniumautomation