From dc0b5576cfa222c4a292242a6452c632fbc5b154 Mon Sep 17 00:00:00 2001 From: Masoud Date: Mon, 18 Jan 2021 22:19:20 +0330 Subject: [PATCH 1/2] +optional captureContent parameter in NewHar() method to capture body content of requests --- AutomatedTester.BrowserMob/Client.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/AutomatedTester.BrowserMob/Client.cs b/AutomatedTester.BrowserMob/Client.cs index a8c46b6..5157056 100644 --- a/AutomatedTester.BrowserMob/Client.cs +++ b/AutomatedTester.BrowserMob/Client.cs @@ -44,10 +44,15 @@ public Client(string url) var parts = url.Split(':'); _proxy = parts[1].TrimStart('/') + ":" + _port; } - - public void NewHar(string reference = null) + + /// + /// + /// + /// + /// Whether to capture body content of requests or not + public void NewHar(string reference = null, bool captureContent = false) { - MakeRequest(String.Format("{0}/{1}/har", _baseUrlProxy, _port), "PUT", reference); + MakeRequest(String.Format("{0}/{1}/har" + (captureContent ? "?captureContent=true" : ""), _baseUrlProxy, _port), "PUT", reference); } private static WebResponse MakeRequest(string url, string method, string reference = null) From a2c989493998eb422af26608073367ac1cb10064 Mon Sep 17 00:00:00 2001 From: Masoud Date: Mon, 22 Mar 2021 11:11:05 +0430 Subject: [PATCH 2/2] +Write detailed error message if could not connect to BrowserMob Proxy --- AutomatedTester.BrowserMob/Server.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AutomatedTester.BrowserMob/Server.cs b/AutomatedTester.BrowserMob/Server.cs index 2692b70..3ec436a 100644 --- a/AutomatedTester.BrowserMob/Server.cs +++ b/AutomatedTester.BrowserMob/Server.cs @@ -12,6 +12,7 @@ public class Server private readonly int _port; private readonly String _path = string.Empty; private const string Host = "localhost"; + private string _errorMessage = ""; public Server(string path) : this(path, 8080) {} @@ -43,7 +44,7 @@ public void Start() count++; if (count == 30) { - throw new Exception("Can not connect to BrowserMob Proxy"); + throw new Exception($"Can not connect to BrowserMob Proxy - {_errorMessage}"); } } } @@ -96,8 +97,9 @@ private bool IsListening() socket.Close(); return true; } - catch (Exception) + catch (Exception ex) { + _errorMessage = ex.Message; return false; } }