Selenium: using Selenium JavaScript executor for WebPage Performance monitoring

Last updated on:

In my current project one of the goal we have is to improve application performance, currently we looking at the application from browser(UI) prospective,
What kind of data we could possibly get while running selenium tests? Can we store this data and then compare it after performance been improved?
Here is how I'm collecting the data, I'd love to find a way get loading page size in bytes, so I could have more accurate results.

Resource timing overview:

public void pageLoadTime(){
    		JavascriptExecutor js = (JavascriptExecutor) getCurrentDriver();
    		// Total requests, made to get page rendered
                long totalRequests = (Long) js.executeScript("return window.performance.getEntries().length;");
    		System.out.println("Total requests: " + totalRequests);
                // Time to load DOM Content
    		long domLoadEventEnd = (Long) js.executeScript("return window.performance.timing.domContentLoadedEventEnd;");
    		long fetchStart = (Long) js.executeScript("return window.performance.timing.fetchStart;");
    		System.out.println("DOM Content Loaded: " + (domLoadEventEnd - fetchStart) + " ms.");
                // Time to load entire page
    		long loadEventEnd = (Long) js.executeScript("return window.performance.timing.loadEventEnd;");
    		System.out.println("Loaded: " + (loadEventEnd - fetchStart) + " ms.");

Yeah there is lots of factors affecting page loading speed, but you have to start from something. For more information "Evaluating network performance"

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.