Skip to main content

Posts

Showing posts with the label SlowPages

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

How to make sure that your Selenium automation test works fine even for slow loading web pages?

Rather than using methods like waitForPageToComplete() or document.readyState property etc. to wait for a page to load in your Se tests, the better way is to use the LoadableComponent and SlowLoadableComponent pattern in Page Object Model. You need to make sure that your Page Object classes extends the abstract LoadableComponent class which in turn provides the implementation for the following methods: - load() //The load method is used to navigate to the page - isLoaded() throws java.lang.Error //The isLoaded method is used to determine whether we are on the right page. The get() method from the LoadableComponent class will ensure that the page/component is loaded by invoking the isLoaded() method. If the check fails here, load() method is called followed by isLoaded(). If your site loads very slow, then we should consider using SlowLoadableComponent instead of LoadableComponent. SlowLoadableComponent verifies the page is loaded until the given maximum timeout.