In the following image, I want the total response time from the webpage. I can\'t seem to find it in the file sample HAR file, i.e. 38.79s in this case. Does anyone know how
Based on @Sebastian Zartner's answer and the Google sample, the following is an Java attempt:
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 hentry = entries.getEntries();
long loadTime = 0;
int entryIndex = 0;
//Output "response" code of entries.
for (HarEntry entry : hentry)
{
System.out.println("entry: " + entryIndex);
System.out.println("request code: " + entry.getRequest().getMethod()); //Output request type
System.out.println(" start time: " + entry.getStartedDateTime().getTime()); // Output start time
System.out.println(" time: " + entry.getTime()); // Output start time
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");
}
}
}