1

I am working on selenium to track network traffic for website.

I have followed referred two links: 1. Using Selenium how to get network request 2. http://chromedriver.chromium.org/logging/performance-log

I got log data as after configuration. you can refer point 2 for example data: Here is what i got

[2015-03-21T16:50:20+0400] [INFO] {"message":{"method":"Network.responseReceived","params":{"frameId":"28480.1","loaderId":"28480.2","requestId":"28480.1","response":{"connectionId":0,"connectionReused":false,"encodedDataLength":-1,"fromDiskCache":false,"fromServiceWorker":false,"headers":{"Access-Control-Allow-Origin":"*","Content-Type":"text/plain;charset=US-ASCII"},"mimeType":"text/plain","protocol":"data","status":200,"statusText":"OK","url":"data:,"},"timestamp":1426942217.5344,"type":"Other"}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} [2015-03-21T16:50:20+0400] [INFO] {"message":{"method":"Network.loadingFinished","params":{"encodedDataLength":0,"requestId":"28480.1","timestamp":1426942217.5344}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} [2015-03-21T16:50:20+0400] [INFO] {"message":{"method":"Page.frameNavigated","params":{"frame":{"id":"28480.1","loaderId":"28480.2","mimeType":"text/plain","securityOrigin":"://","url":"data:,"}}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} [2015-03-21T16:50:21+0400] [INFO] {"message":{"method":"Page.loadEventFired","params":{"timestamp":1426942220.99924}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} [2015-03-21T16:50:21+0400] [INFO] {"message":{"method":"Page.frameStoppedLoading","params":{"frameId":"28480.1"}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} [2015-03-21T16:50:21+0400] [INFO] {"message":{"method":"Page.domContentEventFired","params":{"timestamp":1426942220.99927}},"webview":"C359224A-06E5-42B6-8D1B-52687733920A"} ....

But i dont know how to calculate time of one request xhr request?

I have searched for it but now luck...

Pankaj Badukale
  • 1,721
  • 2
  • 15
  • 31

1 Answers1

0

after enabling the PERFORMANCE logs, you can iterate the log entries using:

List<LogEntry> entries = this.driver.manage().logs().get(LogType.PERFORMANCE).getAll();

Then, you can get the json with the following values:

private String url;
private Boolean timing;
private Long connectEnd;
private Long connectStart;
private Long dnsEnd;
private Long dnsStart;
private Long receiveHeadersEnd;
private Long sslStart;
private Long sslEnd;
private Long proxyStart;
private Long proxyEnd;
private Long sendStart;
private Long sendEnd;
private String mimeType;
private String requestStatus;
private String method;

to get the total time for a single request you can use:

sendStart - sendEnd

Creation of the Chrome Driver:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    logPrefs.enable(LogType.DRIVER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
    perfLogPrefs.put("traceCategories", "browser,devtools.timeline,devtools");
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    WebDriver driver = new ChromeDriver(capabilities);
Adi Ohana
  • 807
  • 1
  • 13
  • 18