如何使用c#代码获取每个selenium命令所花费的时间,意味着我想获得网页为HTTP请求和响应所花费的时间,正如我们在firebug-> Net-> HTML中看到的那样,如果我们做任何行动。 请有人建议我如何记录api通话时间。
谢谢, 的Eswar
答案 0 :(得分:0)
你可以使用下面提到的代码,它会返回一个包含性能指标的字典。
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using OpenQA.Selenium;
namespace AutomatedTester.PagePerf
{
public static class Extensions
{
public static Dictionary<string,object> WebTimings(this IWebDriver driver)
{
var webTiming = (Dictionary<string, object>)((IJavaScriptExecutor)driver)
.ExecuteScript(@"var performance = window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance || {};
var timings = performance.timing || {};
return timings;");
/* The dictionary returned will contain something like the following.
* The values are in milliseconds since 1/1/1970
*
* connectEnd: 1280867925716
* connectStart: 1280867925687
* domainLookupEnd: 1280867925687
* domainLookupStart: 1280867925687
* fetchStart: 1280867925685
* legacyNavigationStart: 1280867926028
* loadEventEnd: 1280867926262
* loadEventStart: 1280867926155
* navigationStart: 1280867925685
* redirectEnd: 0
* redirectStart: 0
* requestEnd: 1280867925716
* requestStart: 1280867925716
* responseEnd: 1280867925940
* responseStart: 1280867925919
* unloadEventEnd: 1280867925940
*/
return webTiming;
}
}
}