From a4b846b81f6e00f0cc1131cd9f4dcc1b5d44c5df Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 28 Nov 2024 18:04:50 +0530 Subject: [PATCH 1/6] Playwright Extended Support for Network Log ,Alert message and interpolation added in Analyzer --- .../AnalyzerLib/AnalyzeAction.cs | 72 ++--- .../ActBrowserElementHandler.cs | 126 +++++++++ .../Drivers/CoreDrivers/Web/BrowserHelper.cs | 57 ++++ .../Web/Playwright/PlaywrightBrowserTab.cs | 247 ++++++++++++++++++ .../Web/Playwright/PlaywrightDriver.cs | 7 + .../Web/Selenium/SeleniumDriver.cs | 149 +++++------ 6 files changed, 540 insertions(+), 118 deletions(-) create mode 100644 Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs diff --git a/Ginger/GingerCoreNET/AnalyzerLib/AnalyzeAction.cs b/Ginger/GingerCoreNET/AnalyzerLib/AnalyzeAction.cs index 104969c02c..89caded557 100644 --- a/Ginger/GingerCoreNET/AnalyzerLib/AnalyzeAction.cs +++ b/Ginger/GingerCoreNET/AnalyzerLib/AnalyzeAction.cs @@ -70,8 +70,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (parentActivity.GetAct(f.GetGuidFromValue(true), f.GetNameFromValue(true)) == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control is mapped to Action which does not exist"; ; - AA.Details = "'" + GoToActionName + "' Action does not exist in '" + parentActivity.ActivityName + "' " + GingerDicser.GetTermResValue(eTermResKey.Activity); + AA.Description = "Flow control is mapped to Action which does not exist"; + AA.Details = $"'{ GoToActionName }' Action does not exist in '{ parentActivity.ActivityName }' { GingerDicser.GetTermResValue(eTermResKey.Activity)}"; AA.HowToFix = "Remap the Flow Control Action"; if (parentActivity.Acts.FirstOrDefault(x => x.Description == f.GetNameFromValue()) != null) @@ -101,14 +101,14 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (BusinessFlow.GetActivity(f.GetGuidFromValue(true), f.GetNameFromValue(true)) == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control is mapped to " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " which does not exist"; ; - AA.Details = "'" + GoToActivity + "' " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " does not exist in the '" + BusinessFlow.Name + " ' " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow); + AA.Description = $"Flow control is mapped to { GingerDicser.GetTermResValue(eTermResKey.Activity) } which does not exist"; ; + AA.Details = $"'{ GoToActivity }'{ GingerDicser.GetTermResValue(eTermResKey.Activity) } does not exist in the '{ BusinessFlow.Name } ' { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow)}"; AA.HowToFix = "Remap the Flow Control Action"; if (BusinessFlow.Activities.FirstOrDefault(x => x.ActivityName == f.GetNameFromValue()) != null) { //can be auto fix - AA.HowToFix = "Remap Flow Control " + GingerDicser.GetTermResValue(eTermResKey.Activity) + ". Auto fix found other " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " with the same name so it will fix the mapping to this " + GingerDicser.GetTermResValue(eTermResKey.Activity) + "."; + AA.HowToFix = $"Remap Flow Control { GingerDicser.GetTermResValue(eTermResKey.Activity) }. Auto fix found other { GingerDicser.GetTermResValue(eTermResKey.Activity) } with the same name so it will fix the mapping to this { GingerDicser.GetTermResValue(eTermResKey.Activity) }."; AA.ErrorInfoObject = f; AA.CanAutoFix = AnalyzerItemBase.eCanFix.Yes; AA.FixItHandler = FixFlowControlWrongActivityMapping; @@ -130,8 +130,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (BusinessFlow.Activities.IndexOf(parentActivity) == (BusinessFlow.Activities.Count - 1)) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control is mapped to " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " which does not exist"; ; - AA.Details = "Flow Control is set to 'GoToNextActivity' but the parent " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " is last one in flow."; + AA.Description = $"Flow control is mapped to { GingerDicser.GetTermResValue(eTermResKey.Activity) } which does not exist"; + AA.Details = $"Flow Control is set to 'GoToNextActivity' but the parent { GingerDicser.GetTermResValue(eTermResKey.Activity) } is last one in flow."; AA.HowToFix = "Remap the Flow Control Action"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; @@ -150,8 +150,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (!BusinessFlow.CheckIfVariableExists(vals[0].ToString().Trim(), parentActivity)) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control mapped to " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " which does not exist"; ; - AA.Details = "'" + vals[0].Trim() + "' " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " does not exist in parent items"; + AA.Description = $"Flow control mapped to { GingerDicser.GetTermResValue(eTermResKey.Variable) } which does not exist"; ; + AA.Details = $"'{ vals[0].Trim() }' { GingerDicser.GetTermResValue(eTermResKey.Variable) } does not exist in parent items"; AA.HowToFix = "Remap the Flow Control Action"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; @@ -172,8 +172,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (activities.FirstOrDefault(x => x.ActivityName == RunSharedRepositoryActivity) == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control mapped to Shared Repository " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " which does not exist"; - AA.Details = "'" + RunSharedRepositoryActivity + "' " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " does not exist in Shared Repository"; + AA.Description = $"Flow control mapped to Shared Repository { GingerDicser.GetTermResValue(eTermResKey.Activity) } which does not exist"; + AA.Details = $"'{ RunSharedRepositoryActivity }' { GingerDicser.GetTermResValue(eTermResKey.Activity) } does not exist in Shared Repository"; AA.HowToFix = "Remap the Flow Control Action"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; @@ -192,8 +192,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (BusinessFlow.Activities.FirstOrDefault(x => x.ActivityName == activityToGoTo) == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "Flow control mapped to " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " which does not exist"; - AA.Details = "'" + activityToGoTo + "' " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " does not exist in the parent " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow); + AA.Description = $"Flow control mapped to { GingerDicser.GetTermResValue(eTermResKey.Activity) } which does not exist"; + AA.Details = $"'{ activityToGoTo }' { GingerDicser.GetTermResValue(eTermResKey.Activity) } does not exist in the parent { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow)}"; AA.HowToFix = "Remap the Flow Control Action"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; @@ -314,12 +314,12 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (BusinessFlow.GetAllVariables(parentActivity).Where(x => x.Name == Var).Select(x => x.Name).FirstOrDefault() == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "The " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " '" + Var + "' is missing"; - AA.Details = "The " + GingerDicser.GetTermResValue(eTermResKey.Variable) + ": '" + Var + "' Does not exist In " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " '" + BusinessFlow.Name + "' => " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " '" + parentActivity.ActivityName + "' =>" + "Action '" + a.Description + "' "; - AA.HowToFix = " Create new " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " or Delete it from the action"; + AA.Description = $"The { GingerDicser.GetTermResValue(eTermResKey.Variable) } '{ Var }' is missing"; + AA.Details = $"The { GingerDicser.GetTermResValue(eTermResKey.Variable) }: '{ Var }' Does not exist In { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } '{ BusinessFlow.Name }' => { GingerDicser.GetTermResValue(eTermResKey.Activity) } '{ parentActivity.ActivityName }' => Action '{ a.Description }' "; + AA.HowToFix = $" Create new { GingerDicser.GetTermResValue(eTermResKey.Variable) } or Delete it from the action"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; - AA.Impact = GingerDicser.GetTermResValue(eTermResKey.Activity) + " will fail due to missing " + GingerDicser.GetTermResValue(eTermResKey.Variable); + AA.Impact = $"{GingerDicser.GetTermResValue(eTermResKey.Activity) } will fail due to missing { GingerDicser.GetTermResValue(eTermResKey.Variable)}"; AA.Severity = eSeverity.High; AA.IssueCategory = eIssueCategory.MissingVariable; @@ -341,12 +341,12 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (globalParam == null) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "The Application Global Parameter " + Param + " is missing"; - AA.Details = "The Application Global Parameter: '" + Param + "' Does not exist in Models Global Parameters"; + AA.Description = $"The Application Global Parameter { Param } is missing"; + AA.Details = $"The Application Global Parameter: '{ Param }' Does not exist in Models Global Parameters"; AA.HowToFix = " Create new Application Global Parameter or Delete it from the action."; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; - AA.Impact = GingerDicser.GetTermResValue(eTermResKey.Activity) + " will fail due to missing " + GingerDicser.GetTermResValue(eTermResKey.Variable); + AA.Impact = $"{GingerDicser.GetTermResValue(eTermResKey.Activity)} will fail due to missing { GingerDicser.GetTermResValue(eTermResKey.Variable)}"; AA.Severity = eSeverity.High; IssuesList.Add(AA); } @@ -359,9 +359,9 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity foreach (string Param in mMissingStoreToGlobalParameters) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "The Output Value with Parameter '" + Param + "' is having store to Parameter which doesn't exist anymore"; - AA.Details = "The Output Value with Parameter: '" + Param + "' can be found at " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " '" + BusinessFlow.Name + "' => " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " '" + parentActivity.ActivityName + "' =>" + "Action '" + a.Description + "' "; - AA.HowToFix = " Create new Parameter and change to it in the 'Store to' dropdown under the above path"; + AA.Description = $"The Output Value with Parameter '{ Param }' is having store to Parameter which doesn't exist anymore"; + AA.Details = $"The Output Value with Parameter: '{ Param }' can be found at { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } '{ BusinessFlow.Name }' => { GingerDicser.GetTermResValue(eTermResKey.Activity) } '{ parentActivity.ActivityName }' => Action '{ a.Description }' "; + AA.HowToFix = " Create new Parameter and change to it in the 'Store to' drop-down under the above path"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; AA.Impact = GingerDicser.GetTermResValue(eTermResKey.Activity) + " will fail due to missing Parameter"; @@ -379,12 +379,12 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity { string list = string.Join(",", driverActs.Select(x => x.ActionDescription).ToList().ToArray()); AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = GingerDicser.GetTermResValue(eTermResKey.Activity) + " has forbidden combinations"; - AA.Details = GingerDicser.GetTermResValue(eTermResKey.Activity) + " has " + a.ActionDescription + " Action with the following platform actions: " + list + ".\nPlatform action inside this current " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " will try to activate the agent before the application is launch(will cause agent issue)."; - AA.HowToFix = "Open the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " and put " + a.ActionDescription + " Action in a separate " + GingerDicser.GetTermResValue(eTermResKey.Activity); + AA.Description = $"{GingerDicser.GetTermResValue(eTermResKey.Activity) } has forbidden combinations"; + AA.Details = $"{GingerDicser.GetTermResValue(eTermResKey.Activity) } has { a.ActionDescription } Action with the following platform actions: { list }.\nPlatform action inside this current { GingerDicser.GetTermResValue(eTermResKey.Activity) } will try to activate the agent before the application is launch(will cause agent issue)."; + AA.HowToFix = $"Open the { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } { GingerDicser.GetTermResValue(eTermResKey.Activity) } and put { a.ActionDescription } Action in a separate { GingerDicser.GetTermResValue(eTermResKey.Activity)}"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; // we can autofix by delete, but don't want to AA.IssueType = eType.Error; - AA.Impact = GingerDicser.GetTermResValue(eTermResKey.Activity) + " will be executed and will fail due to java agent connection"; + AA.Impact = $"{GingerDicser.GetTermResValue(eTermResKey.Activity) } will be executed and will fail due to java agent connection"; AA.Severity = eSeverity.High; IssuesList.Add(AA); @@ -411,8 +411,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); AA.Description = "Action's mapped Page Objects Model is missing"; - AA.Details = "Action " + a.ActionDescription + " has mapped Page Objects Model which is missing, reason can be that the Page Objects Model has been deleted after mapping it to this action."; - AA.HowToFix = "Open the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " and the Action in order to map different Page Objects Model and Element"; + AA.Details = $"Action { a.ActionDescription } has mapped Page Objects Model which is missing, reason can be that the Page Objects Model has been deleted after mapping it to this action."; + AA.HowToFix = $"Open the { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } { GingerDicser.GetTermResValue(eTermResKey.Activity) } and the Action in order to map different Page Objects Model and Element"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; AA.Impact = "Action will fail during execution"; @@ -428,8 +428,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); AA.Description = "Page Objects Model Element which mapped to this action is missing"; - AA.Details = "Action " + a.ActionDescription + " has mapped Page Objects Model Element which is missing, reason can be that the Element has been deleted after mapping it to this action."; - AA.HowToFix = "Open the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " and the Action in order to map different Element"; + AA.Details = $"Action { a.ActionDescription } has mapped Page Objects Model Element which is missing, reason can be that the Element has been deleted after mapping it to this action."; + AA.HowToFix = $"Open the { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } { GingerDicser.GetTermResValue(eTermResKey.Activity) } and the Action in order to map different Element"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; AA.Impact = "Action will fail during execution"; @@ -445,8 +445,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity //TODO: try to find the failure outside exception AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); AA.Description = "Action's mapped Page Objects Model or Element is invalid"; - AA.Details = "Action " + a.ActionDescription + " has invalid mapped Page Objects Model or Element."; - AA.HowToFix = "Open the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " " + GingerDicser.GetTermResValue(eTermResKey.Activity) + " and the Action in order to map different Page Objects Model and Element"; + AA.Details = $"Action { a.ActionDescription } has invalid mapped Page Objects Model or Element."; + AA.HowToFix = $"Open the { GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) } { GingerDicser.GetTermResValue(eTermResKey.Activity) } and the Action in order to map different Page Objects Model and Element"; AA.CanAutoFix = AnalyzerItemBase.eCanFix.No; AA.IssueType = eType.Error; AA.Impact = "Action will fail during execution"; @@ -464,8 +464,8 @@ public static List Analyze(BusinessFlow BusinessFlow, Activity if (a.InputValues.Where(aiv => AIV != null && aiv != null && aiv.Param == AIV.Param).ToList().Count > 1) { AnalyzeAction AA = CreateNewIssue(BusinessFlow, parentActivity, a); - AA.Description = "The Input Value Parameter " + AIV.Param + " is Duplicate"; - AA.Details = "The Input Value Parameter: '" + AIV.Param + "' is duplicate in the ActInputValues"; + AA.Description = $"The Input Value Parameter { AIV.Param } is Duplicate"; + AA.Details = $"The Input Value Parameter: '{ AIV.Param }' is duplicate in the ActInputValues"; AA.HowToFix = "Open action Edit page and save it."; AA.CanAutoFix = AnalyzerItemBase.eCanFix.Yes; AA.IssueType = eType.Warning; @@ -586,7 +586,7 @@ public static void AnalyzeValueExpInAction(Act action, BusinessFlow businessFlow mActivity = activity, Description = $"Cannot Calculate Value Expression: {filteredValueExp}", ItemName = action.Description, - ItemParent = businessFlow.Name + " > " + activity.ActivityName, + ItemParent = $"{businessFlow.Name } > { activity.ActivityName}", mAction = action, mBusinessFlow = businessFlow, ItemClass = "Action", diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs index 870bca4eb5..e2b8b98c6e 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs @@ -20,6 +20,7 @@ limitations under the License. using Amdocs.Ginger.Common; using Amdocs.Ginger.Common.UIElement; using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Exceptions; +using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Playwright; using Amdocs.Ginger.Repository; using GingerCore; using GingerCore.Actions; @@ -145,6 +146,34 @@ internal async Task HandleAsync() case ActBrowserElement.eControlAction.SwitchToDefaultWindow: await HandleSwitchToDefaultWindowOperationAsync(); break; + case ActBrowserElement.eControlAction.AcceptMessageBox: + await HandleAcceptMessageBoxOperationAsync(); + break; + case ActBrowserElement.eControlAction.DismissMessageBox: + await HandleDismissMessageBoxOperationAsync(); + break; + case ActBrowserElement.eControlAction.GetMessageBoxText: + string AlertBoxText = HandleGetMessageBoxTextOperation(); + _act.AddOrUpdateReturnParamActual("Actual", AlertBoxText); + if (_act.GetReturnParam("Actual") == null) + { + _act.AddOrUpdateReturnParamActual("Actual", AlertBoxText); + } + break; + case ActBrowserElement.eControlAction.SetAlertBoxText: + string MessageBoxText = _act.GetInputParamCalculatedValue("Value"); + await HandleSetMessageBoxTextOperationAsync(MessageBoxText); + break; + + case ActBrowserElement.eControlAction.StartMonitoringNetworkLog: + await HandleStartMonitoringNetworkLogOperationAsync(); + break; + case ActBrowserElement.eControlAction.GetNetworkLog: + await HandleGetNetworkLogOperationAsync(); + break; + case ActBrowserElement.eControlAction.StopMonitoringNetworkLog: + await HandleStopMonitoringNetworkLogOperationAsync(); + break; default: string operationName = Common.GeneralLib.General.GetEnumValueDescription(typeof(ActBrowserElement.eControlAction), _act.ControlAction); _act.Error = $"Operation '{operationName}' is not supported"; @@ -538,5 +567,102 @@ private async Task HandleSwitchToDefaultWindowOperationAsync() await _browser.CurrentWindow.SetTabAsync(firstTab); } + + private async Task HandleAcceptMessageBoxOperationAsync() + { + try + { + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).AcceptMessageBox(); + } + catch (Exception e) + { + _act.Error = "Error when Accepting MessageBox."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + return; + } + } + + private async Task HandleDismissMessageBoxOperationAsync() + { + try + { + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).DismissMessageBox(); + } + catch (Exception e) + { + _act.Error = "Error when Dismiss MessageBox."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Dismiss MessageBox - " + e.Message); + return; + } + } + + private string HandleGetMessageBoxTextOperation() + { + try + { + return ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetMessageBoxText(); + } + catch (Exception e) + { + _act.Error = "Error when Get MessageBox Text."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Get MessageBox Text - " + e.Message); + return string.Empty; + } + } + + private async Task HandleSetMessageBoxTextOperationAsync(string MessageBoxText) + { + try + { + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).SetMessageBoxText(MessageBoxText); + } + catch (Exception e) + { + _act.Error = "Error when Set MessageBox Text."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Set MessageBox Text - " + e.Message); + } + } + + private async Task HandleStartMonitoringNetworkLogOperationAsync() + { + try + { + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StartCaptureNetworkLog(_act); + } + catch (Exception e) + { + _act.Error = "Error when Accepting MessageBox."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + return; + } + } + + private async Task HandleGetNetworkLogOperationAsync() + { + try + { + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetCaptureNetworkLog(_act); + } + catch (Exception e) + { + _act.Error = "Error when Accepting MessageBox."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + return; + } + } + + private async Task HandleStopMonitoringNetworkLogOperationAsync() + { + try + { + ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StopCaptureNetworkLog(_act); + } + catch (Exception e) + { + _act.Error = "Error when Accepting MessageBox."; + Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + return; + } + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs new file mode 100644 index 0000000000..8c9cdb5ed6 --- /dev/null +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs @@ -0,0 +1,57 @@ +using amdocs.ginger.GingerCoreNET; +using GingerCore.Actions; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web +{ + internal class BrowserHelper + { + ActBrowserElement _act; + public BrowserHelper() { + + } + + public bool IsToMonitorAllUrls(ActBrowserElement act) + { + _act = act; + return _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == nameof(ActBrowserElement.eMonitorUrl.AllUrl); + } + + public bool IsToMonitorOnlySelectedUrls(ActBrowserElement act,string requestUrl) + { + return _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == nameof(ActBrowserElement.eMonitorUrl.SelectedUrl) + && _act.UpdateOperationInputValues != null + && _act.UpdateOperationInputValues.Any(x => !string.IsNullOrEmpty(x.ValueForDriver) && requestUrl.ToLower().Contains(x.ValueForDriver.ToLower())); + } + + public string CreateNetworkLogFile(string Filename, List> networkLogList) + { + string FullFilePath = string.Empty; + string FullDirectoryPath = System.IO.Path.Combine(WorkSpace.Instance.Solution.Folder, "Documents", "NetworkLog"); + if (!System.IO.Directory.Exists(FullDirectoryPath)) + { + System.IO.Directory.CreateDirectory(FullDirectoryPath); + } + + FullFilePath = FullDirectoryPath + @"\" + Filename + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Millisecond.ToString() + ".har"; + if (!System.IO.File.Exists(FullFilePath)) + { + string FileContent = JsonConvert.SerializeObject(networkLogList.Select(x => x.Item2).ToList()); + + using (Stream fileStream = System.IO.File.Create(FullFilePath)) + { + fileStream.Close(); + } + System.IO.File.WriteAllText(FullFilePath, FileContent); + + } + return FullFilePath; + } + } +} diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index ecad81981b..46e5dcc1bc 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -16,15 +16,22 @@ limitations under the License. */ #endregion +using amdocs.ginger.GingerCoreNET; +using Amdocs.Ginger.Common; using Amdocs.Ginger.Common.UIElement; using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Exceptions; +using Cassandra; using Deque.AxeCore.Commons; using Deque.AxeCore.Playwright; +using GingerCore.Actions; using Microsoft.Playwright; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; +using System.Reflection; using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; @@ -63,8 +70,15 @@ internal sealed class PlaywrightBrowserTab : IBrowserTab private readonly LinkedList _consoleMessages = []; private IFrame _currentFrame; private bool _isClosed = false; + List> networkResponseLogList; + List> networkRequestLogList; + ObservableList NetworkResponseList; + ActBrowserElement _act; + public bool isNetworkLogMonitoringStarted = false; + IDialog dialogs; public bool IsClosed => _isClosed; + BrowserHelper _BrowserHelper; internal PlaywrightBrowserTab(IPlaywrightPage playwrightPage, IBrowserTab.OnTabClose onTabClose) { @@ -73,6 +87,8 @@ internal PlaywrightBrowserTab(IPlaywrightPage playwrightPage, IBrowserTab.OnTabC _currentFrame = _playwrightPage.MainFrame; _playwrightPage.Console += OnConsoleMessage; _playwrightPage.Close += OnPlaywrightPageClose; + _playwrightPage.Dialog += OnPlaywrightDialog; + _BrowserHelper = new BrowserHelper(); } private void RemoveEventHandlers() @@ -605,6 +621,237 @@ public static bool IsFrameLocatorSupported(eLocateBy locateBy) { return SupportedFrameLocators.Contains(locateBy); } + + public async Task StartCaptureNetworkLog(ActBrowserElement act) + { + try + { + await Task.Run(() => + { + _act = act; + networkRequestLogList = new List>(); + networkResponseLogList = new List>(); + NetworkResponseList = new ObservableList(); + _playwrightPage.Request += OnNetworkRequestSent; + _playwrightPage.Response += OnNetworkResponseReceived; + isNetworkLogMonitoringStarted = true; + }); + } + catch(Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + + } + + public async Task GetCaptureNetworkLog(ActBrowserElement act) + { + try + { + await Task.Run(() => + { + _act = act; + if (isNetworkLogMonitoringStarted) + { + act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); + act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); + foreach (var val in networkRequestLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } + + foreach (var val in networkResponseLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } + } + else + { + act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started"; + act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped; + } + }); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + } + + + public async void StopCaptureNetworkLog(ActBrowserElement act) + { + try + { + await Task.Run(() => + { + _act = act; + _playwrightPage.Request -= OnNetworkRequestSent; + _playwrightPage.Response -= OnNetworkResponseReceived; + isNetworkLogMonitoringStarted = false; + act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); + act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); + foreach (var val in networkRequestLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } + foreach (var val in networkResponseLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } + string requestPath = _BrowserHelper.CreateNetworkLogFile("NetworklogRequest", networkRequestLogList); + act.ExInfo = $"RequestFile : {requestPath}\n"; + string responsePath = _BrowserHelper.CreateNetworkLogFile("NetworklogResponse", networkResponseLogList); + act.ExInfo = $"{act.ExInfo} ResponseFile : {responsePath}\n"; + + act.AddOrUpdateReturnParamActual("RequestFile", requestPath); + act.AddOrUpdateReturnParamActual("ResponseFile", responsePath); + + Act.AddArtifactToAction(Path.GetFileName(requestPath), act, requestPath); + + Act.AddArtifactToAction(Path.GetFileName(responsePath), act, responsePath); + }); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + + } + + + + private async void OnNetworkRequestSent(object? sender, IRequest request) + { + try + { + if (_BrowserHelper.IsToMonitorAllUrls(_act) || _BrowserHelper.IsToMonitorOnlySelectedUrls(_act, request.Url)) + { + networkRequestLogList.Add(new Tuple($"RequestUrl:{ request.Url}", JsonConvert.SerializeObject(request, Formatting.Indented, + new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }) + )); + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + } + + private async void OnNetworkResponseReceived(object? sender, IResponse response) + { + await response.FinishedAsync(); + try + { + if (response.BodyAsync() != null) + { + string monitorType = _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value; + if (_BrowserHelper.IsToMonitorAllUrls(_act) || _BrowserHelper.IsToMonitorOnlySelectedUrls(_act,response.Url)) + { + if (_act.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == ActBrowserElement.eRequestTypes.FetchOrXHR.ToString()) + { + if (response.Request.ResourceType.Equals("XHR",StringComparison.CurrentCultureIgnoreCase) || response.Request.ResourceType.Equals("FETCH", StringComparison.CurrentCultureIgnoreCase)) + { + networkResponseLogList.Add(new Tuple($"ResponseUrl:{ response.Url}", JsonConvert.SerializeObject(response, Formatting.Indented, + new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }) + )); + } + } + else + { + networkResponseLogList.Add(new Tuple($"ResponseUrl:{response.Url}", JsonConvert.SerializeObject(response, Formatting.Indented, + new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }) + )); + } + } + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + } + + + + + + private async void OnPlaywrightDialog(object? sender, IDialog e) + { + try + { + await Task.Run(() => { + dialogs = e; + }); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + } + + public async Task AcceptMessageBox() + { + try + { + await dialogs.AcceptAsync(); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + + } + + public async Task DismissMessageBox() + { + try + { + await dialogs.DismissAsync(); + + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } + + } + + public string GetMessageBoxText() + { + try + { + return dialogs.Message; + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + return "Error While Get Message Box Text"; + } + + } + + public async Task SetMessageBoxText(string MessageBoxText) + { + try + { + await dialogs.AcceptAsync(promptText:MessageBoxText); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, "Error While Accept Message", ex); + } + + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs index 3f0fdc1858..ee99b6bc5d 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs @@ -1810,6 +1810,13 @@ public string GetViewport() ActBrowserElement.eControlAction.SwitchToParentFrame, ActBrowserElement.eControlAction.SwitchWindow, ActBrowserElement.eControlAction.SwitchToDefaultWindow, + ActBrowserElement.eControlAction.AcceptMessageBox, + ActBrowserElement.eControlAction.DismissMessageBox, + ActBrowserElement.eControlAction.GetMessageBoxText, + ActBrowserElement.eControlAction.SetAlertBoxText, + ActBrowserElement.eControlAction.StartMonitoringNetworkLog, + ActBrowserElement.eControlAction.GetNetworkLog, + ActBrowserElement.eControlAction.StopMonitoringNetworkLog, ]; } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 8159a92631..706395ad4d 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -88,6 +88,7 @@ public class SeleniumDriver : GingerWebDriver, IVirtualDriver, IWindowExplorer, INetwork interceptor; public bool isNetworkLogMonitoringStarted = false; ActBrowserElement mAct; + BrowserHelper _BrowserHelper = new BrowserHelper(); private int mDriverProcessId = 0; private readonly ShadowDOM shadowDOM = new(); private const string CHROME_DRIVER_NAME = "chromedriver"; @@ -10930,49 +10931,67 @@ private void blockOrUnblockUrls() } public async Task GetNetworkLogAsync(ActBrowserElement act) { - if (isNetworkLogMonitoringStarted) + try { - act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); - act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); - foreach (var val in networkRequestLogList.ToList()) + await Task.Run(() => { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); - } + if (isNetworkLogMonitoringStarted) + { + act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); + act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); + foreach (var val in networkRequestLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } - foreach (var val in networkResponseLogList.ToList()) - { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); - } + foreach (var val in networkResponseLogList.ToList()) + { + act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + } + } + else + { + act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started"; + act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped; + } + }); } - else + catch(Exception ex) { - act.ExInfo = "Action is skipped," + ActBrowserElement.eControlAction.StartMonitoringNetworkLog.ToString() + " Action is not started"; - act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } + } public async Task StartMonitoringNetworkLog(IWebDriver webDriver) { - networkRequestLogList = []; - networkResponseLogList = []; - interceptor = webDriver.Manage().Network; + try + { + networkRequestLogList = []; + networkResponseLogList = []; + interceptor = webDriver.Manage().Network; - ProjEnvironment projEnv = GetCurrentProjectEnvironment(); + ProjEnvironment projEnv = GetCurrentProjectEnvironment(); - ValueExpression VE = new ValueExpression(projEnv, BusinessFlow); + ValueExpression VE = new ValueExpression(projEnv, BusinessFlow); - foreach (ActInputValue item in mAct.UpdateOperationInputValues) - { - item.Value = item.Param; - item.ValueForDriver = VE.Calculate(item.Param); - } + foreach (ActInputValue item in mAct.UpdateOperationInputValues) + { + item.Value = item.Param; + item.ValueForDriver = VE.Calculate(item.Param); + } - interceptor.NetworkRequestSent += OnNetworkRequestSent; - interceptor.NetworkResponseReceived += OnNetworkResponseReceived; + interceptor.NetworkRequestSent += OnNetworkRequestSent; + interceptor.NetworkResponseReceived += OnNetworkResponseReceived; - await interceptor.StartMonitoring(); - isNetworkLogMonitoringStarted = true; + await interceptor.StartMonitoring(); + isNetworkLogMonitoringStarted = true; + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } } private ProjEnvironment GetCurrentProjectEnvironment() @@ -11001,25 +11020,25 @@ public async Task StopMonitoringNetworkLog(ActBrowserElement act) interceptor.NetworkResponseReceived -= OnNetworkResponseReceived; interceptor.ClearRequestHandlers(); interceptor.ClearResponseHandlers(); - act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); - act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); + act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); + act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); foreach (var val in networkRequestLogList.ToList()) { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); } - foreach (var val in networkRequestLogList.ToList()) + foreach (var val in networkResponseLogList.ToList()) { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); } await devToolsDomains.Network.Disable(new OpenQA.Selenium.DevTools.V125.Network.DisableCommandSettings()); devToolsSession.Dispose(); devTools.CloseDevToolsSession(); - string requestPath = CreateNetworkLogFile("NetworklogRequest"); - act.ExInfo = "RequestFile : " + requestPath + "\n"; - string responsePath = CreateNetworkLogFile("NetworklogResponse"); - act.ExInfo = act.ExInfo + "ResponseFile : " + responsePath + "\n"; + string requestPath = _BrowserHelper.CreateNetworkLogFile("NetworklogRequest", networkRequestLogList); + act.ExInfo = $"RequestFile : { requestPath }\n"; + string responsePath = _BrowserHelper.CreateNetworkLogFile("NetworklogResponse", networkResponseLogList); + act.ExInfo = $"{act.ExInfo} ResponseFile : {responsePath}\n"; act.AddOrUpdateReturnParamActual("RequestFile", requestPath); act.AddOrUpdateReturnParamActual("ResponseFile", responsePath); @@ -11030,41 +11049,17 @@ public async Task StopMonitoringNetworkLog(ActBrowserElement act) } else { - act.ExInfo = "Action is skipped," + ActBrowserElement.eControlAction.StartMonitoringNetworkLog.ToString() + " Action is not started"; + act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started"; act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped; } } catch (Exception ex) { - throw ex; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } - private string CreateNetworkLogFile(string Filename) - { - string FullFilePath = string.Empty; - string FullDirectoryPath = System.IO.Path.Combine(WorkSpace.Instance.Solution.Folder, "Documents", "NetworkLog"); - if (!System.IO.Directory.Exists(FullDirectoryPath)) - { - System.IO.Directory.CreateDirectory(FullDirectoryPath); - } - - FullFilePath = FullDirectoryPath + @"\" + Filename + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Millisecond.ToString() + ".har"; - if (!System.IO.File.Exists(FullFilePath)) - { - string FileContent = Filename.Contains("Request") ? JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList()) : JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList()); - - using (Stream fileStream = System.IO.File.Create(FullFilePath)) - { - fileStream.Close(); - } - System.IO.File.WriteAllText(FullFilePath, FileContent); - - } - return FullFilePath; - } - private int CreateConsoleLogFile(string filePath, string logs, ActBrowserElement act) { string calculatedFilePath = WorkSpace.Instance.Solution.SolutionOperations.ConvertSolutionRelativePath(filePath); @@ -11100,28 +11095,18 @@ private void OnNetworkRequestSent(object sender, NetworkRequestSentEventArgs e) { try { - if (IsToMonitorAllUrls() || IsToMonitorOnlySelectedUrls(e.RequestUrl)) + if (_BrowserHelper.IsToMonitorAllUrls(mAct) || _BrowserHelper.IsToMonitorOnlySelectedUrls(mAct, e.RequestUrl)) { - networkRequestLogList.Add(new Tuple("RequestUrl:" + e.RequestUrl, JsonConvert.SerializeObject(e))); + networkRequestLogList.Add(new Tuple($"RequestUrl: {e.RequestUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } + } catch (Exception ex) { - Reporter.ToLog(eLogLevel.ERROR, "Error in OnNetworkRequestSent ", ex); + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } - } - - private bool IsToMonitorAllUrls() - { - return mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == ActBrowserElement.eMonitorUrl.AllUrl.ToString(); - } +} - private bool IsToMonitorOnlySelectedUrls(string requestUrl) - { - return mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == ActBrowserElement.eMonitorUrl.SelectedUrl.ToString() - && mAct.UpdateOperationInputValues != null - && mAct.UpdateOperationInputValues.Any(x => !string.IsNullOrEmpty(x.ValueForDriver) && requestUrl.ToLower().Contains(x.ValueForDriver.ToLower())); - } private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEventArgs e) { @@ -11129,24 +11114,24 @@ private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEve { string monitorType = mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value; - if (IsToMonitorAllUrls() || IsToMonitorOnlySelectedUrls(e.ResponseUrl)) + if (_BrowserHelper.IsToMonitorAllUrls(mAct) || _BrowserHelper.IsToMonitorOnlySelectedUrls(mAct, e.ResponseUrl)) { if (mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == ActBrowserElement.eRequestTypes.FetchOrXHR.ToString()) { - if (e.ResponseResourceType == "XHR") + if (e.ResponseResourceType.Equals("XHR", StringComparison.CurrentCultureIgnoreCase) || e.ResponseResourceType.Equals("FETCH", StringComparison.CurrentCultureIgnoreCase)) { - networkResponseLogList.Add(new Tuple("ResponseUrl:" + e.ResponseUrl, JsonConvert.SerializeObject(e))); + networkResponseLogList.Add(new Tuple($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } } else { - networkResponseLogList.Add(new Tuple("ResponseUrl:" + e.ResponseUrl, JsonConvert.SerializeObject(e))); + networkResponseLogList.Add(new Tuple($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } } } catch (Exception ex) { - Reporter.ToLog(eLogLevel.ERROR, "Error in OnNetworkResponseReceived ", ex); + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } From 0393cdded10a5ac3e891d33b6fd1564b59d095a3 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 28 Nov 2024 19:24:37 +0530 Subject: [PATCH 2/6] Updated summery for all Methods --- .../ActBrowserElementHandler.cs | 85 +++++++++++++------ .../Web/Playwright/PlaywrightBrowserTab.cs | 55 ++++++++++-- 2 files changed, 104 insertions(+), 36 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs index e2b8b98c6e..56629fe8de 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs @@ -28,6 +28,7 @@ limitations under the License. using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; @@ -567,100 +568,130 @@ private async Task HandleSwitchToDefaultWindowOperationAsync() await _browser.CurrentWindow.SetTabAsync(firstTab); } - + /// + /// This asynchronous method accepts a message box (such as a dialog box) in the current browser tab. + /// If an error occurs, it logs the error and updates the Error property. + /// + /// private async Task HandleAcceptMessageBoxOperationAsync() { try { await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).AcceptMessageBox(); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Accepting MessageBox."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } } - + /// + /// This asynchronous method dismisses a message box (closes it) in the current browser tab. + /// If an error occurs, it logs the error and updates the Error property. + /// + /// private async Task HandleDismissMessageBoxOperationAsync() { try { await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).DismissMessageBox(); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Dismiss MessageBox."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Dismiss MessageBox - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } } + /// + /// This method retrieves the text of the message box from the current browser tab. + /// If an error occurs, it logs the error and returns an empty string. + /// + /// private string HandleGetMessageBoxTextOperation() { try { return ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetMessageBoxText(); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Get MessageBox Text."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Get MessageBox Text - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return string.Empty; } } - + /// + /// This asynchronous method sets the text of the message box in the current browser tab. + /// If an error occurs, it logs the error. + /// + /// + /// private async Task HandleSetMessageBoxTextOperationAsync(string MessageBoxText) { try { await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).SetMessageBoxText(MessageBoxText); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Set MessageBox Text."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Set MessageBox Text - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } - + /// + /// This asynchronous method starts monitoring and capturing network logs in the current browser tab. If an error occurs, + /// it logs the error and updates the Error property. + /// + /// private async Task HandleStartMonitoringNetworkLogOperationAsync() { try { await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StartCaptureNetworkLog(_act); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Accepting MessageBox."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } } - + /// + /// This asynchronous method retrieves the captured network logs from the current browser tab. + /// If an error occurs, it logs the error and updates the Error property. + /// + /// private async Task HandleGetNetworkLogOperationAsync() { try { await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetCaptureNetworkLog(_act); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Accepting MessageBox."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } } - + /// + /// This asynchronous method stops monitoring and capturing network logs in the current browser tab. + /// If an error occurs, it logs the error and updates the Error property. + /// + /// private async Task HandleStopMonitoringNetworkLogOperationAsync() { try { ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StopCaptureNetworkLog(_act); } - catch (Exception e) + catch (Exception ex) { - _act.Error = "Error when Accepting MessageBox."; - Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message); + _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 46e5dcc1bc..c43a3dfc60 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -621,7 +621,12 @@ public static bool IsFrameLocatorSupported(eLocateBy locateBy) { return SupportedFrameLocators.Contains(locateBy); } - + /// + /// This asynchronous method initiates the process of capturing network logs for the current page. + /// It sets up the necessary data structures and event handlers to monitor network requests and responses. + /// + /// + /// public async Task StartCaptureNetworkLog(ActBrowserElement act) { try @@ -643,7 +648,12 @@ await Task.Run(() => } } - + /// + /// This asynchronous method retrieves the captured network logs (requests and responses) for the current browser element and stores them in the act object. + /// It only performs the action if network log monitoring has been started. + /// + /// + /// public async Task GetCaptureNetworkLog(ActBrowserElement act) { try @@ -677,7 +687,11 @@ await Task.Run(() => Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } - + /// + /// This asynchronous method stops the network log capture by unsubscribing from the network request and response events. + /// It then processes and stores the captured logs, saves them to files, and attaches the files as artifacts to the act object. + /// + /// public async void StopCaptureNetworkLog(ActBrowserElement act) { @@ -719,8 +733,13 @@ await Task.Run(() => } - + /// + /// This method handles the network request event, capturing the details of outgoing network requests. + /// It adds the request URL and its serialized data to the network log if the request matches the specified criteria. + /// + /// + /// private async void OnNetworkRequestSent(object? sender, IRequest request) { try @@ -740,7 +759,12 @@ private async void OnNetworkRequestSent(object? sender, IRequest request) Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } - + /// + /// This method handles the network response event, capturing details about the response once it's received. + /// It checks if the response should be logged based on the configured criteria and adds relevant information to the network response log. + /// + /// + /// private async void OnNetworkResponseReceived(object? sender, IResponse response) { await response.FinishedAsync(); @@ -798,7 +822,10 @@ await Task.Run(() => { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } - + /// + /// This asynchronous method accepts (clicks the "OK" or equivalent) on a message box or dialog. + /// + /// public async Task AcceptMessageBox() { try @@ -811,7 +838,10 @@ public async Task AcceptMessageBox() } } - + /// + /// This asynchronous method dismisses (closes or cancels) a message box or dialog. + /// + /// public async Task DismissMessageBox() { try @@ -825,7 +855,10 @@ public async Task DismissMessageBox() } } - + /// + /// This method retrieves the text content of the current message box or dialog. + /// + /// public string GetMessageBoxText() { try @@ -839,7 +872,11 @@ public string GetMessageBoxText() } } - + /// + /// This asynchronous method sets the text (usually for a prompt dialog) in the message box. + /// + /// + /// public async Task SetMessageBoxText(string MessageBoxText) { try From 4d77b166cb45b07d56767a86d0022fe8f55fe9e3 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 28 Nov 2024 19:43:41 +0530 Subject: [PATCH 3/6] Updated Code According code rabbit suggestion --- .../ActBrowserElementHandler.cs | 2 +- .../Web/Playwright/PlaywrightBrowserTab.cs | 49 +++++++++++++++---- .../Web/Selenium/SeleniumDriver.cs | 3 -- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs index 56629fe8de..0f562e9918 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs @@ -686,7 +686,7 @@ private async Task HandleStopMonitoringNetworkLogOperationAsync() { try { - ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StopCaptureNetworkLog(_act); + await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StopCaptureNetworkLog(_act); } catch (Exception ex) { diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index c43a3dfc60..57aa3a0c26 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -26,6 +26,7 @@ limitations under the License. using GingerCore.Actions; using Microsoft.Playwright; using Newtonsoft.Json; +using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Drawing; @@ -693,7 +694,7 @@ await Task.Run(() => /// /// - public async void StopCaptureNetworkLog(ActBrowserElement act) + public async Task StopCaptureNetworkLog(ActBrowserElement act) { try { @@ -770,7 +771,7 @@ private async void OnNetworkResponseReceived(object? sender, IResponse response) await response.FinishedAsync(); try { - if (response.BodyAsync() != null) + if (response != null) { string monitorType = _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value; if (_BrowserHelper.IsToMonitorAllUrls(_act) || _BrowserHelper.IsToMonitorOnlySelectedUrls(_act,response.Url)) @@ -813,9 +814,7 @@ private async void OnPlaywrightDialog(object? sender, IDialog e) { try { - await Task.Run(() => { - dialogs = e; - }); + dialogs = e; } catch (Exception ex) { @@ -830,7 +829,14 @@ public async Task AcceptMessageBox() { try { - await dialogs.AcceptAsync(); + if (dialogs != null) + { + await dialogs.AcceptAsync(); + } + else + { + Reporter.ToLog(eLogLevel.WARN, "No dialog to accept."); + } } catch (Exception ex) { @@ -846,8 +852,15 @@ public async Task DismissMessageBox() { try { - await dialogs.DismissAsync(); - + if (dialogs != null) + { + await dialogs.DismissAsync(); + } + else + { + Reporter.ToLog(eLogLevel.WARN, "No dialog to dismiss."); + } + } catch (Exception ex) { @@ -863,7 +876,15 @@ public string GetMessageBoxText() { try { - return dialogs.Message; + if (dialogs != null) + { + return dialogs.Message; + } + else + { + Reporter.ToLog(eLogLevel.WARN, "No dialog to get message."); + return string.Empty; + } } catch (Exception ex) { @@ -881,7 +902,15 @@ public async Task SetMessageBoxText(string MessageBoxText) { try { - await dialogs.AcceptAsync(promptText:MessageBoxText); + if (dialogs != null) + { + await dialogs.AcceptAsync(promptText: MessageBoxText); + } + else + { + Reporter.ToLog(eLogLevel.WARN, "No dialog to accept."); + + } } catch (Exception ex) { diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 706395ad4d..d9ae10d749 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -10933,8 +10933,6 @@ public async Task GetNetworkLogAsync(ActBrowserElement act) { try { - await Task.Run(() => - { if (isNetworkLogMonitoringStarted) { act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); @@ -10954,7 +10952,6 @@ await Task.Run(() => act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started"; act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped; } - }); } catch(Exception ex) { From 0dd78e1648815a3f2e371885054a3309dc2b01bc Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 29 Nov 2024 11:23:43 +0530 Subject: [PATCH 4/6] code re factor and updated chrome devtool protocol --- .../Drivers/CoreDrivers/Web/BrowserHelper.cs | 52 +++++++++++++------ .../Web/Playwright/PlaywrightBrowserTab.cs | 14 ++--- .../Web/Selenium/SeleniumDriver.cs | 21 ++++---- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs index 8c9cdb5ed6..74c27a2096 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs @@ -1,10 +1,12 @@ using amdocs.ginger.GingerCoreNET; +using Amdocs.Ginger.Common; using GingerCore.Actions; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -12,18 +14,17 @@ namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web { internal class BrowserHelper { - ActBrowserElement _act; - public BrowserHelper() { - + private readonly ActBrowserElement _act; + public BrowserHelper(ActBrowserElement act) { + _act = act; } - public bool IsToMonitorAllUrls(ActBrowserElement act) + public bool ShouldMonitorAllUrls() { - _act = act; return _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == nameof(ActBrowserElement.eMonitorUrl.AllUrl); } - public bool IsToMonitorOnlySelectedUrls(ActBrowserElement act,string requestUrl) + public bool ShouldMonitorUrl(string requestUrl) { return _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value == nameof(ActBrowserElement.eMonitorUrl.SelectedUrl) && _act.UpdateOperationInputValues != null @@ -32,26 +33,43 @@ public bool IsToMonitorOnlySelectedUrls(ActBrowserElement act,string requestUrl) public string CreateNetworkLogFile(string Filename, List> networkLogList) { - string FullFilePath = string.Empty; - string FullDirectoryPath = System.IO.Path.Combine(WorkSpace.Instance.Solution.Folder, "Documents", "NetworkLog"); - if (!System.IO.Directory.Exists(FullDirectoryPath)) + if (string.IsNullOrEmpty(Filename)) { - System.IO.Directory.CreateDirectory(FullDirectoryPath); + Reporter.ToLog(eLogLevel.INFO, $"Method - {MethodBase.GetCurrentMethod().Name}, Filename should not be empty"); } - FullFilePath = FullDirectoryPath + @"\" + Filename + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Millisecond.ToString() + ".har"; - if (!System.IO.File.Exists(FullFilePath)) + if (networkLogList == null) { - string FileContent = JsonConvert.SerializeObject(networkLogList.Select(x => x.Item2).ToList()); - - using (Stream fileStream = System.IO.File.Create(FullFilePath)) + Reporter.ToLog(eLogLevel.INFO, $"Method - {MethodBase.GetCurrentMethod().Name}, networkLogList should not be empty"); + } + string FullFilePath = string.Empty; + try + { + string FullDirectoryPath = System.IO.Path.Combine(WorkSpace.Instance.Solution.Folder, "Documents", "NetworkLog"); + if (!System.IO.Directory.Exists(FullDirectoryPath)) { - fileStream.Close(); + System.IO.Directory.CreateDirectory(FullDirectoryPath); } - System.IO.File.WriteAllText(FullFilePath, FileContent); + FullFilePath = FullDirectoryPath + @"\" + Filename + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Millisecond.ToString() + ".har"; + if (!System.IO.File.Exists(FullFilePath)) + { + string FileContent = JsonConvert.SerializeObject(networkLogList.Select(x => x.Item2).ToList()); + + using (Stream fileStream = System.IO.File.Create(FullFilePath)) + { + fileStream.Close(); + } + System.IO.File.WriteAllText(FullFilePath, FileContent); + } + } + catch(Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name} Error: {ex.Message}", ex); } return FullFilePath; + + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 57aa3a0c26..cfe02ca03c 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -89,7 +89,6 @@ internal PlaywrightBrowserTab(IPlaywrightPage playwrightPage, IBrowserTab.OnTabC _playwrightPage.Console += OnConsoleMessage; _playwrightPage.Close += OnPlaywrightPageClose; _playwrightPage.Dialog += OnPlaywrightDialog; - _BrowserHelper = new BrowserHelper(); } private void RemoveEventHandlers() @@ -630,11 +629,12 @@ public static bool IsFrameLocatorSupported(eLocateBy locateBy) /// public async Task StartCaptureNetworkLog(ActBrowserElement act) { + _act = act; + _BrowserHelper = new BrowserHelper(act); try { await Task.Run(() => { - _act = act; networkRequestLogList = new List>(); networkResponseLogList = new List>(); NetworkResponseList = new ObservableList(); @@ -657,11 +657,12 @@ await Task.Run(() => /// public async Task GetCaptureNetworkLog(ActBrowserElement act) { + _act = act; + _BrowserHelper = new BrowserHelper(act); try { await Task.Run(() => { - _act = act; if (isNetworkLogMonitoringStarted) { act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); @@ -696,11 +697,12 @@ await Task.Run(() => public async Task StopCaptureNetworkLog(ActBrowserElement act) { + _act = act; + _BrowserHelper = new BrowserHelper(act); try { await Task.Run(() => { - _act = act; _playwrightPage.Request -= OnNetworkRequestSent; _playwrightPage.Response -= OnNetworkResponseReceived; isNetworkLogMonitoringStarted = false; @@ -745,7 +747,7 @@ private async void OnNetworkRequestSent(object? sender, IRequest request) { try { - if (_BrowserHelper.IsToMonitorAllUrls(_act) || _BrowserHelper.IsToMonitorOnlySelectedUrls(_act, request.Url)) + if (_BrowserHelper.ShouldMonitorAllUrls() || _BrowserHelper.ShouldMonitorUrl( request.Url)) { networkRequestLogList.Add(new Tuple($"RequestUrl:{ request.Url}", JsonConvert.SerializeObject(request, Formatting.Indented, new JsonSerializerSettings @@ -774,7 +776,7 @@ private async void OnNetworkResponseReceived(object? sender, IResponse response) if (response != null) { string monitorType = _act.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value; - if (_BrowserHelper.IsToMonitorAllUrls(_act) || _BrowserHelper.IsToMonitorOnlySelectedUrls(_act,response.Url)) + if (_BrowserHelper.ShouldMonitorAllUrls() || _BrowserHelper.ShouldMonitorUrl(response.Url)) { if (_act.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == ActBrowserElement.eRequestTypes.FetchOrXHR.ToString()) { diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index d9ae10d749..713f54f64b 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -71,7 +71,7 @@ limitations under the License. using System.Threading; using System.Threading.Tasks; using static GingerCoreNET.GeneralLib.General; -using DevToolsDomains = OpenQA.Selenium.DevTools.V125.DevToolsSessionDomains; +using DevToolsDomains = OpenQA.Selenium.DevTools.V127.DevToolsSessionDomains; //.V125.DevToolsSessionDomains; @@ -88,7 +88,7 @@ public class SeleniumDriver : GingerWebDriver, IVirtualDriver, IWindowExplorer, INetwork interceptor; public bool isNetworkLogMonitoringStarted = false; ActBrowserElement mAct; - BrowserHelper _BrowserHelper = new BrowserHelper(); + BrowserHelper _BrowserHelper; private int mDriverProcessId = 0; private readonly ShadowDOM shadowDOM = new(); private const string CHROME_DRIVER_NAME = "chromedriver"; @@ -8391,6 +8391,7 @@ private void HandleSwitchToDefaultDOM() public async void ActBrowserElementHandler(ActBrowserElement act) { + _BrowserHelper = new BrowserHelper(act); try { string AgentType = GetAgentAppName(); @@ -10892,9 +10893,9 @@ private void SetUPDevTools(IWebDriver webDriver) try { //DevTool Session - devToolsSession = devTools.GetDevToolsSession(125); + devToolsSession = devTools.GetDevToolsSession(127); devToolsDomains = devToolsSession.GetVersionSpecificDomains(); - devToolsDomains.Network.Enable(new OpenQA.Selenium.DevTools.V125.Network.EnableCommandSettings()); + devToolsDomains.Network.Enable(new OpenQA.Selenium.DevTools.V127.Network.EnableCommandSettings()); blockOrUnblockUrls(); } catch (Exception ex) @@ -10920,11 +10921,11 @@ private void blockOrUnblockUrls() { if (mAct.ControlAction == ActBrowserElement.eControlAction.SetBlockedUrls) { - devToolsDomains.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.V125.Network.SetBlockedURLsCommandSettings() { Urls = getBlockedUrlsArray(mAct.GetInputParamCalculatedValue("sBlockedUrls")) }); + devToolsDomains.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.V127.Network.SetBlockedURLsCommandSettings() { Urls = getBlockedUrlsArray(mAct.GetInputParamCalculatedValue("sBlockedUrls")) }); } else if (mAct.ControlAction == ActBrowserElement.eControlAction.UnblockeUrls) { - devToolsDomains.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.V125.Network.SetBlockedURLsCommandSettings() { Urls = new string[] { } }); + devToolsDomains.Network.SetBlockedURLs(new OpenQA.Selenium.DevTools.V127.Network.SetBlockedURLsCommandSettings() { Urls = new string[] { } }); } Thread.Sleep(300); } @@ -11028,7 +11029,7 @@ public async Task StopMonitoringNetworkLog(ActBrowserElement act) act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); } - await devToolsDomains.Network.Disable(new OpenQA.Selenium.DevTools.V125.Network.DisableCommandSettings()); + await devToolsDomains.Network.Disable(new OpenQA.Selenium.DevTools.V127.Network.DisableCommandSettings()); devToolsSession.Dispose(); devTools.CloseDevToolsSession(); @@ -11092,7 +11093,7 @@ private void OnNetworkRequestSent(object sender, NetworkRequestSentEventArgs e) { try { - if (_BrowserHelper.IsToMonitorAllUrls(mAct) || _BrowserHelper.IsToMonitorOnlySelectedUrls(mAct, e.RequestUrl)) + if (_BrowserHelper.ShouldMonitorAllUrls() || _BrowserHelper.ShouldMonitorUrl( e.RequestUrl)) { networkRequestLogList.Add(new Tuple($"RequestUrl: {e.RequestUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } @@ -11111,7 +11112,7 @@ private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEve { string monitorType = mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eMonitorUrl)).Value; - if (_BrowserHelper.IsToMonitorAllUrls(mAct) || _BrowserHelper.IsToMonitorOnlySelectedUrls(mAct, e.ResponseUrl)) + if (_BrowserHelper.ShouldMonitorAllUrls() || _BrowserHelper.ShouldMonitorUrl(e.ResponseUrl)) { if (mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == ActBrowserElement.eRequestTypes.FetchOrXHR.ToString()) { @@ -11122,7 +11123,7 @@ private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEve } else { - networkResponseLogList.Add(new Tuple($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); + networkResponseLogList.Add(new Tuple($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } } } From 9a7811a6b9560583963e27cfcb6d2950746c5c28 Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 29 Nov 2024 11:43:31 +0530 Subject: [PATCH 5/6] code Re factor --- .../ActBrowserElementHandler.cs | 21 +++++++------------ .../Web/Playwright/PlaywrightBrowserTab.cs | 3 --- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs index 0f562e9918..fcb861194f 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs @@ -154,12 +154,7 @@ internal async Task HandleAsync() await HandleDismissMessageBoxOperationAsync(); break; case ActBrowserElement.eControlAction.GetMessageBoxText: - string AlertBoxText = HandleGetMessageBoxTextOperation(); - _act.AddOrUpdateReturnParamActual("Actual", AlertBoxText); - if (_act.GetReturnParam("Actual") == null) - { - _act.AddOrUpdateReturnParamActual("Actual", AlertBoxText); - } + _act.AddOrUpdateReturnParamActual("Actual", HandleGetMessageBoxTextOperation()); break; case ActBrowserElement.eControlAction.SetAlertBoxText: string MessageBoxText = _act.GetInputParamCalculatedValue("Value"); @@ -581,7 +576,7 @@ private async Task HandleAcceptMessageBoxOperationAsync() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling message box operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } @@ -599,7 +594,7 @@ private async Task HandleDismissMessageBoxOperationAsync() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling message box operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } @@ -618,7 +613,7 @@ private string HandleGetMessageBoxTextOperation() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling message box operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return string.Empty; } @@ -637,7 +632,7 @@ private async Task HandleSetMessageBoxTextOperationAsync(string MessageBoxText) } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling message box operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } } @@ -654,7 +649,7 @@ private async Task HandleStartMonitoringNetworkLogOperationAsync() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling Network log operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } @@ -672,7 +667,7 @@ private async Task HandleGetNetworkLogOperationAsync() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling Network log operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } @@ -690,7 +685,7 @@ private async Task HandleStopMonitoringNetworkLogOperationAsync() } catch (Exception ex) { - _act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}."; + _act.Error = $"Error when handling Network log operation."; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return; } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index cfe02ca03c..d539c21cda 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -633,15 +633,12 @@ public async Task StartCaptureNetworkLog(ActBrowserElement act) _BrowserHelper = new BrowserHelper(act); try { - await Task.Run(() => - { networkRequestLogList = new List>(); networkResponseLogList = new List>(); NetworkResponseList = new ObservableList(); _playwrightPage.Request += OnNetworkRequestSent; _playwrightPage.Response += OnNetworkResponseReceived; isNetworkLogMonitoringStarted = true; - }); } catch(Exception ex) { From bc088d2f22a38943cc90075603aa37a128d6a8e7 Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 29 Nov 2024 17:07:20 +0530 Subject: [PATCH 6/6] Updated Code --- .../Drivers/CoreDrivers/Web/BrowserHelper.cs | 2 +- .../Web/Playwright/PlaywrightBrowserTab.cs | 60 ++++++++++--------- .../Web/Selenium/SeleniumDriver.cs | 8 +-- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs index 74c27a2096..7d0fb1169e 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs @@ -51,7 +51,7 @@ public string CreateNetworkLogFile(string Filename, List> System.IO.Directory.CreateDirectory(FullDirectoryPath); } - FullFilePath = FullDirectoryPath + @"\" + Filename + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Millisecond.ToString() + ".har"; + FullFilePath = $"FullDirectoryPath{Path.PathSeparator}{Filename}_{DateTime.Now.Day.ToString() }_{ DateTime.Now.Month.ToString() }_{ DateTime.Now.Year.ToString() }_{DateTime.Now.Millisecond.ToString()}.har"; if (!System.IO.File.Exists(FullFilePath)) { string FileContent = JsonConvert.SerializeObject(networkLogList.Select(x => x.Item2).ToList()); diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index d539c21cda..99333987fd 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -16,17 +16,14 @@ limitations under the License. */ #endregion -using amdocs.ginger.GingerCoreNET; using Amdocs.Ginger.Common; using Amdocs.Ginger.Common.UIElement; using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Exceptions; -using Cassandra; using Deque.AxeCore.Commons; using Deque.AxeCore.Playwright; using GingerCore.Actions; using Microsoft.Playwright; using Newtonsoft.Json; -using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Drawing; @@ -73,7 +70,6 @@ internal sealed class PlaywrightBrowserTab : IBrowserTab private bool _isClosed = false; List> networkResponseLogList; List> networkRequestLogList; - ObservableList NetworkResponseList; ActBrowserElement _act; public bool isNetworkLogMonitoringStarted = false; IDialog dialogs; @@ -633,9 +629,8 @@ public async Task StartCaptureNetworkLog(ActBrowserElement act) _BrowserHelper = new BrowserHelper(act); try { - networkRequestLogList = new List>(); - networkResponseLogList = new List>(); - NetworkResponseList = new ObservableList(); + networkRequestLogList = []; + networkResponseLogList = []; _playwrightPage.Request += OnNetworkRequestSent; _playwrightPage.Response += OnNetworkResponseReceived; isNetworkLogMonitoringStarted = true; @@ -666,12 +661,12 @@ await Task.Run(() => act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); foreach (var val in networkRequestLogList.ToList()) { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); } foreach (var val in networkResponseLogList.ToList()) { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); } } else @@ -700,30 +695,37 @@ public async Task StopCaptureNetworkLog(ActBrowserElement act) { await Task.Run(() => { - _playwrightPage.Request -= OnNetworkRequestSent; - _playwrightPage.Response -= OnNetworkResponseReceived; - isNetworkLogMonitoringStarted = false; - act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); - act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); - foreach (var val in networkRequestLogList.ToList()) + try { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); - } - foreach (var val in networkResponseLogList.ToList()) - { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); - } - string requestPath = _BrowserHelper.CreateNetworkLogFile("NetworklogRequest", networkRequestLogList); - act.ExInfo = $"RequestFile : {requestPath}\n"; - string responsePath = _BrowserHelper.CreateNetworkLogFile("NetworklogResponse", networkResponseLogList); - act.ExInfo = $"{act.ExInfo} ResponseFile : {responsePath}\n"; + _playwrightPage.Request -= OnNetworkRequestSent; + _playwrightPage.Response -= OnNetworkResponseReceived; + isNetworkLogMonitoringStarted = false; + act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList())); + act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); + foreach (var val in networkRequestLogList) + { + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); + } + foreach (var val in networkResponseLogList) + { + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); + } + string requestPath = _BrowserHelper.CreateNetworkLogFile("NetworklogRequest", networkRequestLogList); + act.ExInfo = $"RequestFile : {requestPath}\n"; + string responsePath = _BrowserHelper.CreateNetworkLogFile("NetworklogResponse", networkResponseLogList); + act.ExInfo = $"{act.ExInfo} ResponseFile : {responsePath}\n"; - act.AddOrUpdateReturnParamActual("RequestFile", requestPath); - act.AddOrUpdateReturnParamActual("ResponseFile", responsePath); + act.AddOrUpdateReturnParamActual("RequestFile", requestPath); + act.AddOrUpdateReturnParamActual("ResponseFile", responsePath); - Act.AddArtifactToAction(Path.GetFileName(requestPath), act, requestPath); + Act.AddArtifactToAction(Path.GetFileName(requestPath), act, requestPath); - Act.AddArtifactToAction(Path.GetFileName(responsePath), act, responsePath); + Act.AddArtifactToAction(Path.GetFileName(responsePath), act, responsePath); + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); + } }); } catch (Exception ex) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 713f54f64b..20716b025b 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -10940,12 +10940,12 @@ public async Task GetNetworkLogAsync(ActBrowserElement act) act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList())); foreach (var val in networkRequestLogList.ToList()) { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); } foreach (var val in networkResponseLogList.ToList()) { - act.AddOrUpdateReturnParamActual(act.ControlAction.ToString() + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); } } else @@ -11022,11 +11022,11 @@ public async Task StopMonitoringNetworkLog(ActBrowserElement act) act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList(), Formatting.Indented)); foreach (var val in networkRequestLogList.ToList()) { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2)); } foreach (var val in networkResponseLogList.ToList()) { - act.AddOrUpdateReturnParamActual(nameof(act.ControlAction) + " " + val.Item1.ToString(), Convert.ToString(val.Item2)); + act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString() } {val.Item1}", Convert.ToString(val.Item2)); } await devToolsDomains.Network.Disable(new OpenQA.Selenium.DevTools.V127.Network.DisableCommandSettings());