John Riker

John Riker

  • NA
  • 85
  • 15.8k

Server and Client invalid?

Nov 28 2020 10:18 AM
I am trying to figure out how to use Browsermob, Selenium 4 and get the HAR for a URL programatically.  Not sure if anyone can share current way to do this, but all the references I find do not seem to compile.  Like:
 
  1. // Supply the path to the Browsermob Proxy batch file  
  2. Server server = new Server(@"C:\temp\browsermob-proxy-2.1.4\bin\BrowserMobProxybinbrowsermob-proxy.bat");  
  3. server.Start();  
  4. Thread.Sleep(1000);  
  5.   
  6. Client client = server.CreateProxy();  
  7. client.NewHar("assertselenium");  
  8.   
  9. var chromeOptions = new ChromeOptions();  
  10. var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy, SslProxy = client.SeleniumProxy };  
  11. chromeOptions.Proxy = seleniumProxy;  
  12. var dr = new ChromeDriver(chromeOptions);  
  13.   
  14. dr.Navigate().GoToUrl("http://www.google.com");  
  15. dr.FindElementByClassName("gb_e").Click();  
  16.   
  17. Thread.Sleep(3500);  
  18. dr.Navigate().Refresh();  
  19.   
  20. // Get the performance stats  
  21. HarResult harData = client.GetHar();  
  22. Log log = harData.Log;  
  23. Entry[] entries = log.Entries;  
  24.   
  25. foreach (var e in entries)  
  26. {  
  27. Request request = e.Request;  
  28. Response response = e.Response;  
  29. var url = request.Url;  
  30. var time = e.Time;  
  31. var status = response.Status;  
  32. var testStr = "Url: " + url + " - Time: " + time + " Response: " + status;  
  33. }  
  34.   
  35. dr.Quit();  
  36. client.Close();  
  37. server.Stop();  
 The Server and Client errors that the Namespace could not be found.  Tried a number of paths but things like server.Stop() aren't found even if I can find an assembly just to get server.Start() to "look" OK.  Though still think it's the wrong assembly.
 
Get the same for just HarResult, Log, Entry.  Log and Entry I in theory can get to show OK with Grpc but not sure that's really the right reference to use.
 
Thoughts? 

Answers (2)