Web Timing API と Selenium 2 Webdrivers と C# を使用して、Web ページの読み込みのさまざまなイベントにかかる時間を (パフォーマンスをキャプチャするために) キャプチャしようとしています。
基本的に、このアイデア (元は Mozilla チームの開発者によるもの) は、Dean Hume のブログ投稿からのものです ... http://deanhume.com/Home/BlogPost/measuring-web-page-performance-with-selenium-2-and- the-web-timings-api/56
私は恥知らずに拡張機能クラスをコピーし、必要な形式で数値を取得するためのいくつかのメソッドを作成しました..
public static class Extensions
{
public static Dictionary<string, object> WebTimings(this IWebDriver driver)
{
const string scriptToExecute =
"var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var timings = performance.timing || {}; return timings;";
var webTiming = (Dictionary<string, object>)((IJavaScriptExecutor)driver)
.ExecuteScript(scriptToExecute);
return webTiming;
}
}
私に時差を与える私の方法...
//InternetExplorerOptions options = new InternetExplorerOptions();
//options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
//options.UseInternalServer = true;
//IWebDriver _driver = new InternetExplorerDriver(options);
IWebDriver _driver = new FirefoxDriver();
//IWebDriver _driver = new ChromeDriver();
Program p = new Program();
_driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
_driver.Navigate().GoToUrl("http://www.google.com");
Dictionary<string, object> webTimings = _driver.WebTimings();
Dictionary<string, Int64> timeinSec = new Dictionary<string, Int64>();
timeinSec.Add("ConnectTime", p.GetTimeDiff(webTimings["connectEnd"], webTimings["connectStart"]));
InternetExplorerDriver(options) を使用すると、この例外が発生します。ただし、同じコードが Firefox および chrome ドライバーでも機能します。
.ExecuteScript(scriptToExecute);
IE は常にお尻の痛みであり、そうであることが証明され続けています ** 他に何を返すかをキャストする方法がわかりません...?
ここでの入力に感謝します..
Unhandled Exception: System.InvalidCastException: Unable to cast object of type
'OpenQA.Selenium.Remote.RemoteWebElement' to type 'System.Collections.Generic.Di
ctionary`2[System.String,System.Object]'.
at Selenium.Examples.Performance.Extensions.WebTimings(IWebDriver driver) in
C:\Users\......\Extensions.cs:line 13
at PerfCaptureSample.Program.Main(String[] args) in C:\.........\Program.cs:line 52