Can you please help me track the pageload time using chrome driver - I know selinium is not prefferable to tack performace time
I want capture time dispalyed in :
Developer tools ->Network ->load time
Can you please help me track the pageload time using chrome driver - I know selinium is not prefferable to tack performace time
I want capture time dispalyed in :
Developer tools ->Network ->load time
The webpage load timeline in the image link provided is nothing but HTTP Archive (HAR) data which you can get through BrowserMob proxy.
A java implementation of BrowserMob usage is given in this blog post.
import java.io.FileOutputStream;
import org.browsermob.core.har.Har;
import org.browsermob.proxy.ProxyServer;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PerfTest {
    public static void main(String[] args) throws Exception {
        String strFilePath = "";
        // start the proxy
        ProxyServer server = new ProxyServer(4444);
        server.start();
        //captures the moouse movements and navigations
        server.setCaptureHeaders(true);
        server.setCaptureContent(true);
        // get the Selenium proxy object
        Proxy proxy = server.seleniumProxy();
        // configure it as a desired capability
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, proxy);
        // start the browser up
        WebDriver driver = new FirefoxDriver(capabilities);
        // create a new HAR with the label "apple.com"
        server.newHar("assertselenium.com");
        driver.get("http://assertselenium.com");
        // get the HAR data
        Har har = server.getHar();
        FileOutputStream fos = new FileOutputStream(strFilePath);
        har.writeTo(fos);
        server.stop();
        driver.quit();
    }
}
And getting page load time from HAR file generated in the previous line, can be seen explained in this stack overflow question.
public class ParseHarFile {
     public static void main(String[] args) {
         String fileName = "www.google.com.har";
         ReadHarFile(fileName);
    }
    public static void ReadHarFile(String fileName){
         File f = new File("C:\\Users\\Administrator\\Desktop\\test_files\\" + fileName);
         HarFileReader r = new HarFileReader();
         try
         {
             System.out.println("Reading " + fileName);
             HarLog log = r.readHarFile(f);
             // Access all pages elements as an object
              HarPages pages = log.getPages();
              long startTime =   pages.getPages().get(0).getStartedDateTime().getTime();
              System.out.println("page start time: " + startTime);
             // Access all entries elements as an object
             HarEntries entries = log.getEntries();
             List<HarEntry> hentry = entries.getEntries();
             long loadTime = 0;
             int entryIndex = 0;
             //Output "response" code of entries.
             for (HarEntry entry : hentry)
             {
                 System.out.println("entry: " + entryIndex);
                 //Output request type 
                 System.out.println("request code: "+entry.getRequest().getMethod()); 
                 // Output start time
                 System.out.println("start time: "+entry.getStartedDateTime().getTime()); 
                 // Output start time
                 System.out.println("time: " + entry.getTime()); 
                 long entryLoadTime = entry.getStartedDateTime().getTime() 
                                       + entry.getTime();
                 if(entryLoadTime > loadTime){
                     loadTime = entryLoadTime;
                 }
                 System.out.println();
                 entryIndex++;
             }
             long loadTimeSpan = loadTime - startTime;
             System.out.println("loadTimeSpan: " + loadTimeSpan);
             Double webLoadTime = ((double)loadTimeSpan) / 1000;
             double webLoadTimeInSeconds = Math.round(webLoadTime * 100.0) / 100.0; 
             System.out.println("Web Load Time: " + webLoadTimeInSeconds) ;
         }
         catch (JsonParseException e)
         {
             e.printStackTrace();
             System.out.println("Parsing error during test");
         }
         catch (IOException e)
         {
             e.printStackTrace();
             System.out.println("IO exception during test");
         }
     }
}
Refer this:-
how to access Network panel on google chrome developer toools with selenium?
While you just want time then use below code:-
long start = System.currentTimeMillis();
driver.get("Some url");
long finish = System.currentTimeMillis();
long totalTime = finish - start; 
System.out.println("Total Time for page load - "+totalTime); 
Page load time Plugin is available for chrome, it shows the load time next to the location bar and it also provides details.