From 4d77b166cb45b07d56767a86d0022fe8f55fe9e3 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 28 Nov 2024 19:43:41 +0530 Subject: [PATCH] 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) {