Java 如何从chrome驱动程序性能日志计算一个请求的总时间?

Java 如何从chrome驱动程序性能日志计算一个请求的总时间?,java,selenium,selenium-webdriver,webdriver,google-chrome-devtools,Java,Selenium,Selenium Webdriver,Webdriver,Google Chrome Devtools,我正在使用selenium跟踪网站的网络流量 我关注了两个链接: 1. 2. 我得到了配置后的日志数据。 关于示例数据,您可以参考第2点: 这是我得到的 [2015-03-21T16:50:20+0400][INFO]{“message”:{“method”:“Network.responseReceived”,“params”:{“frameId”:“28480.1”,“loaderId”:“28480.2”,“requestId”:“28480.1”,“response”:{“connec

我正在使用selenium跟踪网站的网络流量

我关注了两个链接: 1. 2.

我得到了配置后的日志数据。 关于示例数据,您可以参考第2点: 这是我得到的

[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”:{“访问控制允许来源”*,“内容类型”:“text/plain;charset=US-ASCII”},“mimeType”:“text/plain”,“协议”:“数据”,“状态”:200,“状态文本”:“确定”,“url”:“数据:,”},“时间戳”:1426942217.5344,“类型”:“其他”}},“网络视图”:“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]{“消息”:{“方法”:“Page.loadEventFireed”,“参数”:{“timestamp”:1426942220.99924},“网络视图”:“C359224A-06E5-42B6-8D1B-52687733920A”} [2015-03-21T16:50:21+0400][INFO]{“消息”:{“方法”:“Page.frameStoppedLoading”,“参数”:{“frameId”:“28480.1”},“网络视图”:“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”}

但我不知道如何计算一个请求的时间xhr请求


我已经搜索过了,但现在很幸运…

启用性能日志后,您可以使用以下方法迭代日志条目:

List<LogEntry> entries = this.driver.manage().logs().get(LogType.PERFORMANCE).getAll();
要获取单个请求的总时间,您可以使用:

发送开始-发送结束

创建Chrome驱动程序:

    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);
DesiredCapabilities=新的DesiredCapabilities();
LoggingPreferences logPrefs=新的LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE,Level.ALL);
logPrefs.enable(LogType.DRIVER,Level.ALL);
Capability.setCapability(CapabilityType.LOGGING_PREFS,logPrefs);
Map perfLogPrefs=new HashMap();
perfLogPrefs.put(“traceCategories”、“browser,devtools.timeline,devtools”);
ChromeOptions选项=新的ChromeOptions();
options.setExperimentalOption(“perfLoggingPrefs”,perfLogPrefs);
能力。设置能力(ChromeOptions.CAPABILITY,选项);
WebDriver=新的ChromeDriver(功能);

启用性能日志后,可以使用以下方法迭代日志条目:

List<LogEntry> entries = this.driver.manage().logs().get(LogType.PERFORMANCE).getAll();
要获取单个请求的总时间,您可以使用:

发送开始-发送结束

创建Chrome驱动程序:

    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);
DesiredCapabilities=新的DesiredCapabilities();
LoggingPreferences logPrefs=新的LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE,Level.ALL);
logPrefs.enable(LogType.DRIVER,Level.ALL);
Capability.setCapability(CapabilityType.LOGGING_PREFS,logPrefs);
Map perfLogPrefs=new HashMap();
perfLogPrefs.put(“traceCategories”、“browser,devtools.timeline,devtools”);
ChromeOptions选项=新的ChromeOptions();
options.setExperimentalOption(“perfLoggingPrefs”,perfLogPrefs);
能力。设置能力(ChromeOptions.CAPABILITY,选项);
WebDriver=新的ChromeDriver(功能);

日志中有多种方法,如requestwillbesent、responsereceived,我可以在其中获取日志数据sendStart和SendEnd。上述代码应提供所述的所有值。您还获得了其他信息吗?是的,您提到的所有方法都可以在日志消息中获取,其中包含方法Network.requestResponseReceived。但我没有看到sendStart and sendEnd在其中,因此询问这是我正在使用的方法:Network.responseReceived。还使用更多代码编辑了答案
sendStart
sendEnd
是秒还是毫秒?在诸如requestwillbesent、responseReceived这样的日志中有多种方法,我可以从中获取sendStart和sendEnd上述代码应该提供给您的日志数据提到的所有值。您还有其他信息吗?是的,您提到的所有信息都可以在日志消息中获取,其中包含方法Network.requestResponseReceived。但是我没有在其中看到SendStart和sendEnd,因此我问这是我使用的方法:Network.responseReceived。还使用更多代码编辑了答案
SendStart
sendEnd是秒还是毫秒?