public static void ReadRegisterResponse() { string path = Path.Combine(Directory.GetCurrentDirectory(), "\\browsermob-proxy.bat"); Server server = new Server(path); server.Start(); Client client = server.CreateProxy(); client.NewHar("RegistrationResponse"); var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy }; DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability(CapabilityType.Proxy, seleniumProxy); // retrieve performance stats for IWebDriver driver = new ChromeDriver(capabilities); driver.Navigate().GoToUrl("https://www.phptravels.net/account/"); // Get the performance stats //That contains the response of the login an successful registration HarResult harData = client.GetHar(); client.Close(); server.Stop(); }
public void ProxyTest() { driver.Url = "http://google.com"; HarResult harData = client.GetHar(); foreach (var en in harData.Log.Entries) { Debug.WriteLine(en.Response.Status.ToString() + " " + en.Response.StatusText + " " + en.Request.Url); } }
public void TestProxy() { driver.Navigate().GoToUrl("https://selenium2.ru/"); // Get the performance stats HarResult harData = client.GetHar(); var allRequests = harData.Log.Entries;//cписок содержит инфо о всех перехваченных запросах. //Почему-то перехватываются только HTTP запросы, а HTTPS - нет. allRequests.ToList().ForEach(l => Console.WriteLine(string.Concat(l.Response.Status, ":", l.Request.Url))); //Не обязательно выводить информацию на консоль! Можно сделать какие - угодно проверки, например можно проверять, что //нету ответов со статусами 4хх или 5хх серий, можно собирать информацию о времени загрузки этих ресуров, //можно анализировать заголовки запросов и ответов, и даже можна анализировать текст ответов(нужно включить опцию, чтобы текст сохранался //т.к по умолчанию он не сохраняется.) }
public Guid SaveHarResult(HarResultJsonDto harResult) { using (var context = new RemoteWebHostingContext()) { HarData harData = new HarData(); //TODO Zach: Fix the default Date Times HarResult harRes = new HarResult { Dns = harResult.Dns, Ip = harResult.Ip, NodeId = Guid.Parse(harResult.NodeId), NodeName = harResult.NodeName, Ping = harResult.Ping, TestTime = DateTimeOffset.UtcNow,//harResult.TestTime, TotalSize = harResult.TotalSize, TotalTime = harResult.TotalTime, HarData = harData, CreatedOn = DateTimeOffset.UtcNow }; if (harResult.GeoTo != null) { harRes.To = new Geo { Latitude = harResult.GeoTo.Latitude, Longitude = harResult.GeoTo.Longitude }; } if (harResult.GeoFrom != null) { harRes.From = new Geo { Latitude = harResult.GeoFrom.Latitude, Longitude = harResult.GeoFrom.Longitude }; } context.HarResults.Add(harRes); context.HarDatas.Add(harData); context.SaveChanges(); return(harData.Id); } }
public void UsingBrowserMob() { // Supply the path to the Browsermob Proxy batch file Server server = new Server(@"C:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat", 8090); server.Start(); Client client = server.CreateProxy(); client.NewHar("sample"); var options = new ChromeOptions { Proxy = new Proxy { HttpProxy = client.SeleniumProxy } }; driver = new ChromeDriver(options); LoginAsAdmin(); driver.Url = "http://localhost:8080/litecart/admin/?app=catalog&doc=catalog&category_id=1"; var itemsCount = driver.FindElements(By.CssSelector("img[style*='margin-left: 32px; width: 16px; height: 16px; vertical-align: bottom;'] + a")).Count; for (var i = 0; i < itemsCount; i++) { driver.FindElements(By. CssSelector("img[style*='margin-left: 32px; width: 16px; height: 16px; vertical-align: bottom;'] + a"))[i]. Click(); driver.Url = "http://localhost:8080/litecart/admin/?app=catalog&doc=catalog&category_id=1"; } // Get the performance stats HarResult harData = client.GetHar(); // write to HAR.txt //Log log = harData.Log; //Entry[] entries = log.Entries; //var logFileInfo = new FileInfo(Path.Combine( // Path.GetDirectoryName( // Assembly.GetExecutingAssembly().Location), // "HAR.txt")); //var file = new StreamWriter(logFileInfo.FullName); //foreach (var entry in entries) //{ // Request request = entry.Request; // Response response = entry.Response; // var url = request.Url; // var time = entry.Time; // var status = response.Status; // Console.WriteLine("Url: " + url + " - Time: " + time + " Response: " + status); // file.WriteLine("Url: " + url + " - Time: " + time + " Response: " + status); //} //file.Close(); // write to sample.har var json = new JavaScriptSerializer().Serialize(harData); Log logJSON = harData.Log; Entry[] entriesJSON = logJSON.Entries; var logFileInfoJSON = new FileInfo(Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location), "sample.har")); var fileJSON = new StreamWriter(logFileInfoJSON.FullName); fileJSON.WriteLine(json.ToLower()); fileJSON.Close(); client.Close(); server.Stop(); }