Using Selenium JavaScript executor for WebPage Performance monitoring

By: Slav Kurochkin

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:

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"

Note: I'd love to find a way to get loading page size in bytes, to have more accurate results.

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.