From 9e9ddb10657112675374dc5757fdb9bf03f78d30 Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Fri, 24 Jan 2025 15:12:18 +0530 Subject: [PATCH 01/19] Web smart sync action changes --- .../GingerCoreCommon/UIElement/ElementInfo.cs | 2 + .../ActionHandlers/ActWebSmartSyncHandler.cs | 368 ++++++++++++++++++ .../CoreDrivers/Web/IBrowserElement.cs | 13 + .../Drivers/CoreDrivers/Web/IBrowserTab.cs | 12 +- .../Playwright/PlaywrightBrowserElement.cs | 179 +++++++++ .../Web/Playwright/PlaywrightBrowserTab.cs | 161 ++++++++ .../Web/Playwright/PlaywrightDriver.cs | 44 ++- Ginger/GingerCoreNET/GingerCoreNET.csproj | 3 +- 8 files changed, 779 insertions(+), 3 deletions(-) create mode 100644 Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs diff --git a/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs b/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs index 36958ee702..0e7aeed609 100644 --- a/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs +++ b/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs @@ -549,6 +549,8 @@ public enum eLocateBy ByCSS, [EnumValueDescription("By XPath")] ByXPath, + [EnumValueDescription("By Attribute")] + ByAttribute, [EnumValueDescription("By Relative XPath")] ByRelXPath, [EnumValueDescription("By X,Y")] diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs new file mode 100644 index 0000000000..f9e24cbccf --- /dev/null +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs @@ -0,0 +1,368 @@ +using DocumentFormat.OpenXml.Drawing.Charts; +using GingerCore; +using GingerCore.Actions; +using GingerCore.Actions.Common; +using Microsoft.Graph; +using Microsoft.Playwright; +using Microsoft.VisualStudio.Services.WebApi; +using OpenQA.Selenium; +using OpenQA.Selenium.Common; +using OpenQA.Selenium.Support.UI; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.ActionHandlers +{ + internal class ActWebSmartSyncHandler + { + private ActWebSmartSync _actWebSmartSync; + private IBrowserTab _browserTab; + private IBrowserElementLocator _elementLocator; + + internal ActWebSmartSyncHandler(ActWebSmartSync actWebSmartSync, IBrowserTab browserTab, IBrowserElementLocator elementLocator) + { + _actWebSmartSync = actWebSmartSync; + _browserTab = browserTab; + _elementLocator = elementLocator; + } + + /// + /// Executes various web synchronization operations within a specified timeout. + /// Sets an error message in the act object if the condition is not met in time. + /// + public async Task HandleAsync(Act act, float waitUntilTimeout) + { + try + { + switch (_actWebSmartSync.SyncOperations) + { + case ActWebSmartSync.eSyncOperation.ElementIsVisible: + await HandleElementIsVisibleAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.ElementExists: + await HandleElementExistsAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.AlertIsPresent: + await HandleAlertIsPresentAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.ElementIsSelected: + await HandleElementIsSelectedAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.PageHasBeenLoaded: + await HandlePageHasBeenLoadedAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.ElementToBeClickable: + await HandleElementToBeClickableAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.TextMatches: + await HandleTextMatchesAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.AttributeMatches: + await HandleAttributeMatchesAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.EnabilityOfAllElementsLocatedBy: + await HandleEnabilityOfAllElementsLocatedByAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.FrameToBeAvailableAndSwitchToIt: + await HandleFrameToBeAvailableAndSwitchToItAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.InvisibilityOfAllElementsLocatedBy: + await HandleInvisibilityOfAllElementsLocatedByAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.InvisibilityOfElementLocated: + await HandleInvisibilityOfElementLocatedAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.PresenceOfAllElementsLocatedBy: + await HandlePresenceOfAllElementsLocatedByAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.SelectedOfAllElementsLocatedBy: + await HandleSelectedOfAllElementsLocatedByAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.UrlMatches: + await HandleUrlMatchesAsync(act, waitUntilTimeout); + break; + + case ActWebSmartSync.eSyncOperation.VisibilityOfAllElementsLocatedBy: + await HandleVisibilityOfAllElementsLocatedByAsync(act, waitUntilTimeout); + break; + + default: + act.Error = "Unsupported operation."; + break; + } + } + catch (Exception ex) + { + act.Error = ex.Message + ex.InnerException; + } + } + + /// + /// Handles the operation to check if an element is visible within the given timeout. + /// + private async Task HandleElementIsVisibleAsync(Act act, float waitUntilTimeout) + { + IBrowserElement element = await GetFirstMatchingElementAsync(); + if (await element.ToBeVisibleAsync(waitUntilTimeout)) + { + return; + } + act.Error = "Element is not visible within the given time."; + } + + /// + /// Handles the operation to check if an element exists within the given timeout. + /// + private async Task HandleElementExistsAsync(Act act, float waitUntilTimeout) + { + Stopwatch stopwatch = Stopwatch.StartNew(); + while (stopwatch.Elapsed.TotalSeconds < waitUntilTimeout) + { + var elements = await _browserTab.GetElementsAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue); + if (elements.Any()) + { + return; + } + await Task.Delay(100); + } + act.Error = "Element does not exist within the given time."; + } + + /// + /// Handles the operation to check if an alert is present within the given timeout. + /// + private async Task HandleAlertIsPresentAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForAlertAsync(waitUntilTimeout)) + { + return; + } + act.Error = "Alert is not present within the given time."; + } + + /// + /// Handles the operation to check if an element is selected within the given timeout. + /// + private async Task HandleElementIsSelectedAsync(Act act, float waitUntilTimeout) + { + IBrowserElement selectedElement = await GetFirstMatchingElementAsync(); + if (await selectedElement.ElementIsSelectedAsync(waitUntilTimeout)) + { + return; + } + act.Error = "Element is not selected within the given time."; + } + + /// + /// Handles the operation to check if the page has been loaded within the given timeout. + /// + private async Task HandlePageHasBeenLoadedAsync(Act act, float waitUntilTimeout) + { + Stopwatch stopwatch = Stopwatch.StartNew(); + while (stopwatch.Elapsed.TotalSeconds < waitUntilTimeout) + { + var state = await _browserTab.ExecuteJavascriptAsync("document.readyState"); + if (state.Equals("complete", StringComparison.OrdinalIgnoreCase)) + { + return; + } + await Task.Delay(100); + } + act.Error = "Page has not been loaded within the given time."; + } + + /// + /// Handles the operation to check if an element is clickable within the given timeout. + /// + private async Task HandleElementToBeClickableAsync(Act act, float waitUntilTimeout) + { + IBrowserElement clickableElement = await GetFirstMatchingElementAsync(); + if (await clickableElement.ElementToBeClickableAsync(waitUntilTimeout)) + { + return; + } + act.Error = "Element is not clickable within the given time."; + } + + /// + /// Handles the operation to check if the text matches within the given timeout. + /// + private async Task HandleTextMatchesAsync(Act act, float waitUntilTimeout) + { + string expectedText = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.TxtMatchInput)); + if (string.IsNullOrEmpty(expectedText)) + { + throw new InvalidDataException("For TextMatches operation, the input value is missing or invalid."); + } + IBrowserElement textElement = await GetFirstMatchingElementAsync(); + if (await textElement.TextMatchesAsync(expectedText, waitUntilTimeout)) + { + return; + } + act.Error = "Text does not match within the given time."; + } + + /// + /// Handles the operation to check if the attribute matches within the given timeout. + /// + private async Task HandleAttributeMatchesAsync(Act act, float waitUntilTimeout) + { + IBrowserElement attributeElement = await GetFirstMatchingElementAsync(); + string attributeName = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.AttributeName)); + string attributeValue = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.AttributeValue)); + if (string.IsNullOrEmpty(attributeName) || string.IsNullOrEmpty(attributeValue)) + { + throw new InvalidDataException("For AttributeMatches operation, the input value is missing or invalid."); + } + if (await attributeElement.AttributeMatchesAsync(attributeName, attributeValue, waitUntilTimeout)) + { + return; + } + act.Error = "Attribute does not match within the given time."; + } + + /// + /// Handles the operation to check if all elements located by are enabled within the given timeout. + /// + private async Task HandleEnabilityOfAllElementsLocatedByAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForElementsEnabledAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue, waitUntilTimeout)) + { + return; + } + act.Error = "Not all elements are enabled within the given time."; + } + + /// + /// Handles the operation to check if the frame is available and switches to it within the given timeout. + /// + private async Task HandleFrameToBeAvailableAndSwitchToItAsync(Act act, float waitUntilTimeout) + { + Stopwatch stopwatch = Stopwatch.StartNew(); + while (stopwatch.Elapsed.TotalSeconds < waitUntilTimeout) + { + bool wasSwitched = await _browserTab.SwitchFrameAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue); + if (wasSwitched) + { + return; + } + await Task.Delay(100); + } + act.Error = "Frame is not available within the given time."; + } + + /// + /// Handles the operation to check if all elements located by are invisible within the given timeout. + /// + private async Task HandleInvisibilityOfAllElementsLocatedByAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForElementsInvisibleAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue, waitUntilTimeout)) + { + return; + } + act.Error = "Not all elements are invisible within the given time."; + } + + /// + /// Handles the operation to check if an element is invisible within the given timeout. + /// + private async Task HandleInvisibilityOfElementLocatedAsync(Act act, float waitUntilTimeout) + { + IBrowserElement invisibleElement = await GetFirstMatchingElementAsync(); + if (await invisibleElement.ToBeNotVisibleAsync(waitUntilTimeout)) + { + return; + } + act.Error = "Element is not visible within the given time."; + } + + /// + /// Handles the operation to check if all elements located by are present within the given timeout. + /// + private async Task HandlePresenceOfAllElementsLocatedByAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForElementsPresenceAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue, waitUntilTimeout)) + { + return; + } + act.Error = "Elements are not present within the given time."; + } + + /// + /// Handles the operation to check if all elements located by are selected within the given timeout. + /// + private async Task HandleSelectedOfAllElementsLocatedByAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForElementsCheckedAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue, waitUntilTimeout)) + { + return; + } + act.Error = "Not all elements are selected within the given time."; + } + + /// + /// Handles the operation to check if the URL matches within the given timeout. + /// + private async Task HandleUrlMatchesAsync(Act act, float waitUntilTimeout) + { + string expectedUrl = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.UrlMatches)); + if (string.IsNullOrEmpty(expectedUrl)) + { + throw new InvalidDataException("For URLMatches operation, the input value is missing or invalid."); + } + if (await _browserTab.WaitForUrlMatchAsync(expectedUrl, waitUntilTimeout)) + { + return; + } + act.Error = "URL does not match within the given time."; + } + + /// + /// Handles the operation to check if all elements located by are visible within the given timeout. + /// + private async Task HandleVisibilityOfAllElementsLocatedByAsync(Act act, float waitUntilTimeout) + { + if (await _browserTab.WaitForElementsVisibleAsync(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue, waitUntilTimeout)) + { + return; + } + act.Error = "Not all elements are visible within the given time."; + } + + /// + /// Retrieves the first matching element based on the locator and value. + /// + private async Task GetFirstMatchingElementAsync() + { + IEnumerable elements = await _elementLocator.FindMatchingElements(_actWebSmartSync.ElementLocateBy, _actWebSmartSync.ElementLocateValue); + IBrowserElement? firstElement = elements.FirstOrDefault(); + if (firstElement == null) + { + throw new InvalidDataException("No matching element found."); + } + return firstElement; + } + + } +} diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserElement.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserElement.cs index f95f359dd5..12b71562fc 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserElement.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserElement.cs @@ -94,5 +94,18 @@ internal interface IBrowserElement public Task TestAccessibilityAsync(AxeRunOptions? options = null); public Task SetFileValueAsync(string[] value); + + public Task ToBeVisibleAsync(float timeOut); + + public Task AttributeMatchesAsync(string attributeName, string attributeValue, float timeOut); + + public Task TextMatchesAsync(string textToMatch, float timeOut); + + public Task ElementToBeClickableAsync(float timeOut); + + public Task ElementIsSelectedAsync(float timeOut); + + public Task ToBeNotVisibleAsync(float timeOut); + } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs index 2e89eaade8..dd8e748714 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs @@ -36,7 +36,7 @@ internal interface IBrowserTab public Task GoToURLAsync(string url); - public Task TitleAsync(); + public Task TitleAsync(); public Task NavigateBackAsync(); @@ -100,6 +100,16 @@ internal interface IBrowserTab public Task StartListenDialogsAsync(); + public Task WaitForUrlMatchAsync(string urlPattern, float timeout); + + public Task WaitForAlertAsync(float timeout); + + public Task WaitForElementsEnabledAsync(eLocateBy locateBy, string selector, float timeout); + + public Task WaitForElementsCheckedAsync(eLocateBy locateBy, string locateValue, float timeout); + public Task WaitForElementsPresenceAsync(eLocateBy locateBy, string locateValue, float timeout); + public Task WaitForElementsInvisibleAsync(eLocateBy locateBy, string locateValue, float timeout); + public Task WaitForElementsVisibleAsync(eLocateBy locateBy, string locateValue, float timeout); } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs index 12c413cf61..4026ab1727 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs @@ -19,6 +19,7 @@ limitations under the License. using Deque.AxeCore.Commons; using Deque.AxeCore.Playwright; using Microsoft.Playwright; +using NUnit.Framework; using System; using System.Collections.Generic; using System.Drawing; @@ -1041,5 +1042,183 @@ private Task SetFileValueAsync(IPlaywrightElementHandle playwrightElementHandle, { return playwrightElementHandle.SetInputFilesAsync(value); } + + + /// + /// Waits for the element to be visible within the specified timeout. + /// + /// The timeout in milliseconds. + /// True if the element is visible, otherwise false. + public Task ToBeVisibleAsync(float timeOut) => ToBeVisibleAsync(_playwrightLocator, timeOut); + + /// + /// Waits for the element to be visible within the specified timeout. + /// + /// The locator of the element. + /// The timeout in milliseconds. + /// True if the element is visible, otherwise false. + public async Task ToBeVisibleAsync(IPlaywrightLocator playwrightLocator, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToBeVisibleOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut }); + await Assertions.Expect(playwrightLocator).ToBeVisibleAsync(options); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + + /// + /// Waits for the element to be selected within the specified timeout. + /// + /// The timeout in milliseconds. + /// True if the element is selected, otherwise false. + public Task ElementIsSelectedAsync(float timeOut) => ElementIsSelectedAsync(_playwrightLocator, timeOut); + + /// + /// Waits for the element to be selected within the specified timeout. + /// + /// The locator of the element. + /// The timeout in milliseconds. + /// True if the element is selected, otherwise false. + public async Task ElementIsSelectedAsync(IPlaywrightLocator playwrightLocator, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToBeCheckedOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut }); + await Assertions.Expect(playwrightLocator).ToBeCheckedAsync(options); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + + /// + /// Waits for the element to be clickable within the specified timeout. + /// + /// The timeout in milliseconds. + /// True if the element is clickable, otherwise false. + public Task ElementToBeClickableAsync(float timeOut) => ElementToBeClickableAsync(_playwrightLocator, timeOut); + + /// + /// Waits for the element to be clickable within the specified timeout. + /// + /// The locator of the element. + /// The timeout in milliseconds. + /// True if the element is clickable, otherwise false. + public async Task ElementToBeClickableAsync(IPlaywrightLocator playwrightLocator, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToBeVisibleOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut }); + await Assertions.Expect(playwrightLocator).ToBeVisibleAsync(options); + await Assertions.Expect(playwrightLocator).ToBeEnabledAsync(new LocatorAssertionsToBeEnabledOptions { Timeout = timeOut }); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + + /// + /// Waits for the element's text to match the specified text within the specified timeout. + /// + /// The text to match. + /// The timeout in milliseconds. + /// True if the text matches, otherwise false. + public Task TextMatchesAsync(string textToMatch, float timeOut) => TextMatchesAsync(_playwrightLocator, textToMatch, timeOut); + + /// + /// Waits for the element's text to match the specified text within the specified timeout. + /// + /// The locator of the element. + /// The text to match. + /// The timeout in milliseconds. + /// True if the text matches, otherwise false. + public async Task TextMatchesAsync(IPlaywrightLocator playwrightLocator, string textToMatch, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToContainTextOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut }); + await Assertions.Expect(playwrightLocator).ToContainTextAsync(textToMatch, options); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + + /// + /// Waits for the element's attribute to match the specified value within the specified timeout. + /// + /// The name of the attribute. + /// The value of the attribute. + /// The timeout in milliseconds. + /// True if the attribute matches, otherwise false. + public Task AttributeMatchesAsync(string attributeName, string attributeValue, float timeOut) => AttributeMatchesAsync(_playwrightLocator, attributeName, attributeValue, timeOut); + + /// + /// Waits for the element's attribute to match the specified value within the specified timeout. + /// + /// The locator of the element. + /// The name of the attribute. + /// The value of the attribute. + /// The timeout in milliseconds. + /// True if the attribute matches, otherwise false. + public async Task AttributeMatchesAsync(IPlaywrightLocator playwrightLocator, string attributeName, string attributeValue, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToHaveAttributeOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut }); + await Assertions.Expect(playwrightLocator).ToHaveAttributeAsync(attributeName, attributeValue, options); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + + /// + /// Waits for the element to be not visible within the specified timeout. + /// + /// The timeout in milliseconds. + /// True if the element is not visible, otherwise false. + public Task ToBeNotVisibleAsync(float timeOut) => ToBeNotVisibleAsync(_playwrightLocator, timeOut); + + /// + /// Waits for the element to be not visible within the specified timeout. + /// + /// The locator of the element. + /// The timeout in milliseconds. + /// True if the element is not visible, otherwise false. + public async Task ToBeNotVisibleAsync(IPlaywrightLocator playwrightLocator, float timeOut) + { + ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator)); + + try + { + var options = new LocatorAssertionsToBeVisibleOptions { Timeout = timeOut }; + await playwrightLocator.WaitForAsync(new LocatorWaitForOptions { Timeout = timeOut, State = WaitForSelectorState.Hidden }); + await Assertions.Expect(playwrightLocator).Not.ToBeVisibleAsync(options); + return true; + } + catch (TimeoutException) { return false; } + catch (AssertionException) { return false; } + } + } + } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 02e161dabc..858daabaf7 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -1048,6 +1048,167 @@ public async Task StartListenDialogsAsync() isDialogDismiss = false; } + /// + /// Waits for the URL to match the specified pattern within the given timeout. + /// + public async Task WaitForUrlMatchAsync(string urlPattern, float timeout) + { + ThrowIfClosed(); + try + { + await _playwrightPage.WaitForURLAsync(urlPattern, new PageWaitForURLOptions { Timeout = timeout }); + return true; + } + catch (Exception ex) + { + throw new Exception("URL did not match the pattern", ex); + } + } + + /// + /// Waits for elements to become enabled within the specified timeout. + /// + public async Task WaitForElementsEnabledAsync(eLocateBy locateBy, string locateValue, float timeout) + { + return await WaitForElementsStateAsync(locateBy, locateValue, timeout, ElementState.Visible, ElementState.Enabled); + } + + /// + /// Waits for elements to become visible within the specified timeout. + /// + public async Task WaitForElementsVisibleAsync(eLocateBy locateBy, string locateValue, float timeout) + { + return await WaitForElementsStateAsync(locateBy, locateValue, timeout, ElementState.Visible); + } + + /// + /// Waits for elements to become invisible within the specified timeout. + /// + public async Task WaitForElementsInvisibleAsync(eLocateBy locateBy, string locateValue, float timeout) + { + return await WaitForElementsStateAsync(locateBy, locateValue, timeout, ElementState.Hidden); + } + + /// + /// Waits for elements to become present within the specified timeout. + /// + public async Task WaitForElementsPresenceAsync(eLocateBy locateBy, string locateValue, float timeout) + { + return await WaitForElementsStateAsync(locateBy, locateValue, timeout, ElementState.Stable); + } + + /// + /// Waits for elements to become checked within the specified timeout. + /// + public async Task WaitForElementsCheckedAsync(eLocateBy locateBy, string locateValue, float timeout) + { + ThrowIfClosed(); + try + { + string selector = GetSelector(locateBy, locateValue); + var elements = await _playwrightPage.QuerySelectorAllAsync(selector); + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + + while (stopwatch.ElapsedMilliseconds < timeout) + { + bool allChecked = true; + foreach (var element in elements) + { + if (!await element.IsCheckedAsync()) + { + allChecked = false; + break; + } + } + + if (allChecked) + { + return true; + } + + await Task.Delay(100); + } + + throw new Exception("Elements did not become checked within the specified time"); + } + catch (Exception ex) + { + throw new Exception("Elements did not become checked within the specified time", ex); + } + } + + /// + /// Waits for elements to reach the specified state(s) within the given timeout. + /// + private async Task WaitForElementsStateAsync(eLocateBy locateBy, string locateValue, float timeout, params ElementState[] states) + { + ThrowIfClosed(); + try + { + string selector = GetSelector(locateBy, locateValue); + var elements = await _playwrightPage.QuerySelectorAllAsync(selector); + foreach (var element in elements) + { + foreach (var state in states) + { + await element.WaitForElementStateAsync(state, new ElementHandleWaitForElementStateOptions { Timeout = timeout }); + } + } + return true; + } + catch (Exception ex) + { + throw new Exception($"Elements did not reach the desired state(s) within the specified time", ex); + } + } + + /// + /// Gets the selector string based on the locator type and value. + /// + private string GetSelector(eLocateBy locateBy, string locateValue) + { + return locateBy switch + { + eLocateBy.ByID => $"#{locateValue}", + eLocateBy.ByClassName => $".{locateValue}", + eLocateBy.ByTagName => locateValue, + eLocateBy.ByAttribute => $"[{locateValue}]", + eLocateBy.ByName => $"[name='{locateValue}']", + eLocateBy.ByXPath => locateValue, // XPath is used as-is + eLocateBy.ByCSSSelector => locateValue, // CSS Selector is used as-is + eLocateBy.ByLinkText => $"a:contains('{locateValue}')", + eLocateBy.ByText => $"*:contains('{locateValue}')", // For elements containing text + _ => throw new ArgumentException("Invalid locator type") + }; + } + + /// + /// Waits for an alert to appear within the specified timeout. + /// + public async Task WaitForAlertAsync(float timeout) + { + var alertDetected = new TaskCompletionSource(); + + _playwrightPage.Dialog += (_, dialog) => + { + if (dialog.Type == DialogType.Alert) + { + alertDetected.TrySetResult(true); + } + }; + + var delayTask = Task.Delay((int)timeout); + var completedTask = await Task.WhenAny(alertDetected.Task, delayTask); + + if (completedTask == delayTask) + { + throw new TimeoutException("Alert did not appear within the specified timeout."); + } + + return await alertDetected.Task; + } + } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs index f716d6883b..e30ff985dc 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs @@ -282,6 +282,48 @@ public override void RunAction(Act act) browserOptions.Timeout = driverDefaultTimeout; } break; + case ActWebSmartSync actWebSmartSync: + ActWebSmartSyncHandler actWebSmartSyncHandler = new( + actWebSmartSync, + _browser.CurrentWindow.CurrentTab, + new BrowserElementLocator( + _browser.CurrentWindow.CurrentTab, + new() + { + BusinessFlow = BusinessFlow, + Environment = Environment, + POMExecutionUtils = new POMExecutionUtils(actWebSmartSync, actWebSmartSync.ElementLocateValue), + Agent = BusinessFlow.CurrentActivity.CurrentAgent, + })); + float? driverDefaultTimeout1 = browserOptions.Timeout; + float waitUntilTime; + if (act.Timeout > 0) + { + // waitUntilTime= TimeSpan.FromSeconds(act.Timeout.GetValueOrDefault()); + waitUntilTime = act.Timeout.GetValueOrDefault(); + } + else if(browserOptions.Timeout>0) + { + waitUntilTime = browserOptions.Timeout.Value; + } + else + { + waitUntilTime = 5; + } + browserOptions.Timeout = (float)waitUntilTime; + try + { + actWebSmartSyncHandler.HandleAsync(act, waitUntilTime*1000).Wait(); + } + catch (Exception ex) + { + act.Error = ex.Message; + } + finally + { + browserOptions.Timeout = driverDefaultTimeout1; + } + break; default: act.Error = $"This Action is not supported for Playwright driver"; break; @@ -293,7 +335,7 @@ public bool IsActionSupported(Act act, out string message) { message = string.Empty; - if (act is ActWithoutDriver or ActScreenShot or ActGotoURL or ActAccessibilityTesting or ActSmartSync) + if (act is ActWithoutDriver or ActScreenShot or ActGotoURL or ActAccessibilityTesting or ActSmartSync or ActWebSmartSync) { return true; } diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 365a712782..38149f3225 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -311,7 +311,8 @@ - + + From e6b41f9c7a6b8b41ee814b5d5b95898c80a84597 Mon Sep 17 00:00:00 2001 From: Mayur Rathi Date: Mon, 27 Jan 2025 18:39:42 +0530 Subject: [PATCH 02/19] Enhanced REST API code for allowing Any Content type for Response Content --- .../WebServices/ActWebAPIEditPage.xaml.cs | 30 ++++-- .../APIModelBodyNodeSyncPage.xaml.cs | 20 ++-- .../APIModels/APIModelPage.xaml.cs | 28 ++--- .../ModelParams Pages/ModelParamsPage.xaml.cs | 2 +- .../APIModelLib/SwaggerApi/OpenApiBase.cs | 12 +-- .../APIModelLib/SwaggerApi/OpenApiVer3.cs | 8 +- .../APIModelLib/SwaggerApi/SwaggerVer2.cs | 16 +-- .../Actions/Webservices/ActWebAPIBase.cs | 4 +- .../APIModelLib/ApplicationAPIModel.cs | 8 +- .../APIModelLib/ApplicationAPIUtils.cs | 23 +++- .../APIModelLib/EnumExtensions.cs | 20 ++++ .../WebServicesDriver/HttpWebClientUtils.cs | 101 +++++++----------- .../PlatformsInfo/Webserviceplatforminfo.cs | 8 +- .../ErrorHandlerActivityTest.cs | 8 +- .../Webservice/WebServicesTest.cs | 28 ++--- .../GingerCoreTest/Misc/OutputSimulation.cs | 16 +-- 16 files changed, 182 insertions(+), 150 deletions(-) create mode 100644 Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs diff --git a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs index 26b75956df..eb9279082d 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs @@ -88,10 +88,13 @@ private void InitializeUIByActionType() HttpVersioncombobox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ReqHttpVersion, ApplicationAPIUtils.eHttpVersion.HTTPV11.ToString()), typeof(ApplicationAPIUtils.eHttpVersion), false, null); //Request content type - ContentTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eContentType), false, ContentTypeChange); + ContentTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eRequestContentType), false, ContentTypeChange); //Response Content Type - ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eContentType), false, ResponseTypeComboBox_SelectionChanged); + ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eResponseContentType), false, ResponseTypeComboBox_SelectionChanged); + //ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()), + // GetFilteredContentTypes(), + // false, ResponseTypeComboBox_SelectionChanged); //Request Template file: TemplateFileNameFileBrowser.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.TemplateFileNameFileBrowser), true, true, UCValueExpression.eBrowserType.File, "txt; *.xml; *.json;", new RoutedEventHandler(BrowseTemplateFileButton_Click)); @@ -111,6 +114,13 @@ private void InitializeUIByActionType() break; } } + //public static IEnumerable GetFilteredContentTypes() + //{ + // return Enum.GetValues(typeof(ApplicationAPIUtils.eContentType)) + // .Cast() + // .Where(ct => ct != ApplicationAPIUtils.eContentType.Any); // Exclude Any + //} + public void BindUiControls() { @@ -188,7 +198,7 @@ private void CheckNetworkCredentials() private void CheckRequestBodySelection() { - if ((mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded.ToString())) + if ((mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded.ToString())) { FreeTextStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -196,7 +206,7 @@ private void CheckRequestBodySelection() FormDataGridPanel.Visibility = System.Windows.Visibility.Visible; DynamicElementGridPanel.Visibility = System.Windows.Visibility.Collapsed; } - if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.FormData.ToString()) + if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.FormData.ToString()) { FreeTextStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -279,7 +289,7 @@ private void RequestBodyType_Selection(object sender, RoutedEventArgs e) BodyInputGridPannel.Visibility = System.Windows.Visibility.Collapsed; FreeTextStackPanel.Visibility = Visibility.Collapsed; } - else if ((mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded.ToString()) || (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.FormData.ToString())) + else if ((mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded.ToString()) || (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.FormData.ToString())) { if (!String.IsNullOrEmpty((mAct.GetInputParamCalculatedValue(ActWebAPIBase.Fields.TemplateFileNameFileBrowser)))) { @@ -506,12 +516,12 @@ public void RefreshRequestKeyValuesGrid() mAct.RequestKeyValues.ClearAll(); } - if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded.ToString()) + if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded.ToString()) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.FormData.ToString()) + else if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.FormData.ToString()) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); @@ -571,12 +581,12 @@ public void SetKeyValuesGrid(ObservableList RequestKeyValue FormDataGrid.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddRow)); - if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded.ToString()) + if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded.ToString()) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eContentType.FormData.ToString()) + else if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == ApplicationAPIUtils.eRequestContentType.FormData.ToString()) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); @@ -620,7 +630,7 @@ private void AddRow(object sender, RoutedEventArgs e) } private void ResponseTypeComboBox_SelectionChanged(object sender, RoutedEventArgs e) { - if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eContentType.JSon.ToString()) + if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eResponseContentType.JSon.ToString()) { JSON.Visibility = Visibility.Visible; } diff --git a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelBodyNodeSyncPage.xaml.cs b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelBodyNodeSyncPage.xaml.cs index fe942bd6c0..9b1ecf55e4 100644 --- a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelBodyNodeSyncPage.xaml.cs +++ b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelBodyNodeSyncPage.xaml.cs @@ -36,7 +36,7 @@ namespace Ginger.ApplicationModelsLib.APIModels public partial class APIModelBodyNodeSyncPage : Page { GenericWindow _pageGenericWin = null; - ApplicationAPIUtils.eContentType requestBodyType; + ApplicationAPIUtils.eRequestContentType requestBodyType; XmlDocument XMLDoc = null; JsonExtended JsonDoc = null; List mParamsPendingDelete = []; @@ -52,18 +52,18 @@ public APIModelBodyNodeSyncPage(ApplicationAPIModel applicationAPIModel, List x.ParentOuterXml).Select(group => group.First()).ToList(); //For Json only - remove spaces and new lines from string - if (requestBodyType == ApplicationAPIUtils.eContentType.JSon)//For Json - remove spaces + if (requestBodyType == ApplicationAPIUtils.eRequestContentType.JSon)//For Json - remove spaces { foreach (NodeToDelete nodeToDelete in mNodesToDeleteList) { @@ -96,11 +96,11 @@ private void PrepareNodesPendingForDelete() } //4.Find the actual node string inside the request body and save its text range - if (requestBodyType == ApplicationAPIUtils.eContentType.XML) + if (requestBodyType == ApplicationAPIUtils.eRequestContentType.XML) { FindXMLElementAndSaveItsTextRange(NodeToInspect); } - else if (requestBodyType == ApplicationAPIUtils.eContentType.JSon) + else if (requestBodyType == ApplicationAPIUtils.eRequestContentType.JSon) { FindJSONElementAndSaveItsTextRange(NodeToInspect); } @@ -120,7 +120,7 @@ private void PrepareNodesListForDeletion() switch (requestBodyType) { //Try first searching node using Path, if not succeed try search param using placeholder - case ApplicationAPIUtils.eContentType.XML: + case ApplicationAPIUtils.eRequestContentType.XML: XmlNode xmlNodeByXpath = XMLDocExtended.GetNodeByXpath(XMLDoc, paramToDelete.Path); if (xmlNodeByXpath != null && xmlNodeByXpath.InnerText == paramToDelete.PlaceHolder) { @@ -136,7 +136,7 @@ private void PrepareNodesListForDeletion() } } break; - case ApplicationAPIUtils.eContentType.JSon: + case ApplicationAPIUtils.eRequestContentType.JSon: JToken jNode = JsonDoc.SelectToken(paramToDelete.Path); if (jNode != null && jNode.Value() == paramToDelete.PlaceHolder) { @@ -333,7 +333,7 @@ private void AddAssociatedParamsForDeletion() public void ShowAsWindow(eWindowShowStyle windowStyle = eWindowShowStyle.Dialog) { - if (requestBodyType is ApplicationAPIUtils.eContentType.XML or ApplicationAPIUtils.eContentType.JSon) + if (requestBodyType is ApplicationAPIUtils.eRequestContentType.XML or ApplicationAPIUtils.eRequestContentType.JSon) { PrepareNodesPendingForDelete(); diff --git a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs index 2c606fdfc4..a998ea0ba1 100644 --- a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs +++ b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs @@ -147,8 +147,8 @@ private void InitializeUIByActionType() CookieMode.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.CookieMode), typeof(ApplicationAPIUtils.eCookieMode)); RequestTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.RequestType), typeof(ApplicationAPIUtils.eRequestType)); HttpVersioncombobox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ReqHttpVersion), typeof(ApplicationAPIUtils.eHttpVersion)); - ContentTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ContentType), typeof(ApplicationAPIUtils.eContentType), ContentTypeChange); - ResponseTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ResponseContentType), typeof(ApplicationAPIUtils.eContentType)); + ContentTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ContentType), typeof(ApplicationAPIUtils.eRequestContentType), ContentTypeChange); + ResponseTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ResponseContentType), typeof(ApplicationAPIUtils.eResponseContentType)); //Check maybe the binding of TemplateFileNameFileBrowser need to be different between soap and rest GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(TemplateFileNameFileBrowser, TextBox.TextProperty, mApplicationAPIModel, nameof(mApplicationAPIModel.TemplateFileNameFileBrowser)); @@ -323,19 +323,19 @@ private void ContentTypeChange(object sender, RoutedEventArgs e) { switch (mApplicationAPIModel.ContentType) { - case ApplicationAPIUtils.eContentType.JSon: + case ApplicationAPIUtils.eRequestContentType.JSon: RequestBodyTypePanel.Visibility = Visibility.Visible; CheckRequestBodySelection(); break; - case ApplicationAPIUtils.eContentType.TextPlain: + case ApplicationAPIUtils.eRequestContentType.TextPlain: RequestBodyTypePanel.Visibility = System.Windows.Visibility.Visible; CheckRequestBodySelection(); break; - case ApplicationAPIUtils.eContentType.XML: + case ApplicationAPIUtils.eRequestContentType.XML: RequestBodyTypePanel.Visibility = System.Windows.Visibility.Visible; CheckRequestBodySelection(); break; - case ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded: + case ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded: BodyInputGridPannel.Visibility = System.Windows.Visibility.Collapsed; FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -343,7 +343,7 @@ private void ContentTypeChange(object sender, RoutedEventArgs e) FormDataGridPanel.Visibility = System.Windows.Visibility.Visible; RefreshRequestKeyValuesGrid(); break; - case ApplicationAPIUtils.eContentType.FormData: + case ApplicationAPIUtils.eRequestContentType.FormData: BodyInputGridPannel.Visibility = System.Windows.Visibility.Collapsed; FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -361,12 +361,12 @@ public void RefreshRequestKeyValuesGrid() mApplicationAPIModel.APIModelBodyKeyValueHeaders.Clear(); } - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.FormData) + else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); @@ -439,14 +439,14 @@ private void BodyExpanded(object sender, RoutedEventArgs e) private void CheckRequestBodySelection() { - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; RequestBodyTypePanel.Visibility = System.Windows.Visibility.Collapsed; FormDataGridPanel.Visibility = System.Windows.Visibility.Visible; } - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.FormData) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) { FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -571,7 +571,7 @@ private void RequestBodyType_Selection(object sender, RoutedEventArgs e) break; default: - if (mApplicationAPIModel.ContentType is ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded or ApplicationAPIUtils.eContentType.FormData) + if (mApplicationAPIModel.ContentType is ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded or ApplicationAPIUtils.eRequestContentType.FormData) { if (!String.IsNullOrEmpty(mApplicationAPIModel.TemplateFileNameFileBrowser)) { @@ -736,12 +736,12 @@ public void SetKeyValuesGrid() FormDataGrid.btnAdd.RemoveHandler(Button.ClickEvent, new RoutedEventHandler(AddFormDataGridRow)); FormDataGrid.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddFormDataGridRow)); - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eContentType.FormData) + else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); diff --git a/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs b/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs index 76c4f3f9e9..bb4118aefa 100644 --- a/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs +++ b/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs @@ -357,7 +357,7 @@ private void ClearAllParams_Clicked(object sender, RoutedEventArgs e) private void DeleteParams(bool ClearAllParams) { Amdocs.Ginger.Common.eUserMsgSelection messageResult = Amdocs.Ginger.Common.eUserMsgSelection.No; - if (mApplicationModel is ApplicationAPIModel && (((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eContentType.XML || ((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eContentType.JSon)) + if (mApplicationModel is ApplicationAPIModel && (((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eRequestContentType.XML || ((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eRequestContentType.JSon)) { messageResult = Reporter.ToUser(eUserMsgKey.DeleteNodesFromRequest); } diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs index 6d2d6dd37a..de6ba952c3 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs @@ -59,7 +59,7 @@ public void GenerateResponse(SwaggerOperation operation, ApplicationAPIModel bas { schemaObj = response.Schema.Reference; } - if (basicModal.ContentType == ApplicationAPIUtils.eContentType.XML) + if (basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.XML) { ApplicationAPIModel JsonResponseModel = new ApplicationAPIModel(); @@ -76,8 +76,8 @@ public void GenerateResponse(SwaggerOperation operation, ApplicationAPIModel bas basicModal.ReturnValues.Add(arv); } } - else if (basicModal.ContentType == ApplicationAPIUtils.eContentType.JSon || - basicModal.ContentType == ApplicationAPIUtils.eContentType.FormData) + else if (basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.JSon || + basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) { ApplicationAPIModel jsonResponseModel = new ApplicationAPIModel(); var generatedJsonBody = GenerateJsonBody(jsonResponseModel, schemaObj); @@ -211,7 +211,7 @@ public ObservableList GenerateXMLBody(ApplicationAPIModel aAM ApplicationAPIModel aam = XTp.ParseDocument(temppath, new ObservableList()).ElementAt(0); aAM.RequestBody = aam.RequestBody; aAM.RequestBodyType = ApplicationAPIUtils.eRequestBodyType.FreeText; - aam.ContentType = ApplicationAPIUtils.eContentType.XML; + aam.ContentType = ApplicationAPIUtils.eRequestContentType.XML; return aam.AppModelParameters; } @@ -228,11 +228,11 @@ public void GenerateFormParameters(ApplicationAPIModel aAM, SwaggerOperation ope { if (isMultiPartFormdata) { - aAM.ContentType = ApplicationAPIUtils.eContentType.FormData; + aAM.ContentType = ApplicationAPIUtils.eRequestContentType.FormData; } else { - aAM.ContentType = ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded; + aAM.ContentType = ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded; } foreach (SwaggerParameter SP in operation.ActualParameters) { diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs index d4484664e5..ed10572fdd 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs @@ -79,8 +79,8 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd } break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eContentType.JSon; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.JSon; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); @@ -90,8 +90,8 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eContentType.XML; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.XML; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs index 17c0f5e97a..8b326a1afd 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs @@ -76,8 +76,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc GenerateFormParameters(AAM, Operation, true); break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eContentType.JSon; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.JSon; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); @@ -89,8 +89,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eContentType.XML; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.XML; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); @@ -135,8 +135,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc GenerateFormParameters(AAM, Operation, true); break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eContentType.JSon; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.JSon; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); @@ -149,8 +149,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eContentType.XML; - AAM.ResponseContentType = ApplicationAPIUtils.eContentType.XML; + AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); diff --git a/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs b/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs index dae1ad70a5..1bb72a4e72 100644 --- a/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs +++ b/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs @@ -221,7 +221,7 @@ public static bool ParseNodesToReturnParams(ActWebAPIBase mAct, string ResponseM string ResponseContentType = mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); bool jsonParsinFailed = false; - if (ResponseContentType == ApplicationAPIUtils.eContentType.JSon.ToString()) + if (ResponseContentType == ApplicationAPIUtils.eResponseContentType.JSon.ToString()) { if (!ParseJsonNodesToReturnParams(mAct, ResponseMessage)) { @@ -234,7 +234,7 @@ public static bool ParseNodesToReturnParams(ActWebAPIBase mAct, string ResponseM } if (XMLResponseCanBeParsed && ( - (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eContentType.XML.ToString()) || jsonParsinFailed)) + (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eResponseContentType.XML.ToString()) || jsonParsinFailed)) { return ParseXMLNodesToReturnParams(mAct, ResponseMessage); } diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs index ccf3689f4c..1bb05abdc1 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs @@ -140,13 +140,13 @@ public override string ObjFileExt [IsSerializedForLocalRepository] public ApplicationAPIUtils.eRequestType RequestType { get { return mRequestType; } set { if (mRequestType != value) { mRequestType = value; OnPropertyChanged(nameof(RequestType)); } } } - ApplicationAPIUtils.eContentType mResponseContentType = ApplicationAPIUtils.eContentType.JSon; + ApplicationAPIUtils.eResponseContentType mResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; [IsSerializedForLocalRepository] - public ApplicationAPIUtils.eContentType ResponseContentType { get { return mResponseContentType; } set { if (mResponseContentType != value) { mResponseContentType = value; OnPropertyChanged(nameof(ResponseContentType)); } } } + public ApplicationAPIUtils.eResponseContentType ResponseContentType { get { return mResponseContentType; } set { if (mResponseContentType != value) { mResponseContentType = value; OnPropertyChanged(nameof(ResponseContentType)); } } } - ApplicationAPIUtils.eContentType mContentType = ApplicationAPIUtils.eContentType.JSon; + ApplicationAPIUtils.eRequestContentType mContentType = ApplicationAPIUtils.eRequestContentType.JSon; [IsSerializedForLocalRepository] - public ApplicationAPIUtils.eContentType ContentType { get { return mContentType; } set { if (mContentType != value) { mContentType = value; OnPropertyChanged(nameof(ContentType)); } } } + public ApplicationAPIUtils.eRequestContentType ContentType { get { return mContentType; } set { if (mContentType != value) { mContentType = value; OnPropertyChanged(nameof(ContentType)); } } } ApplicationAPIUtils.eCookieMode mCookieMode = ApplicationAPIUtils.eCookieMode.Session; [IsSerializedForLocalRepository] diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs index 79d2dee5e2..d7d528d2ee 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs @@ -16,6 +16,9 @@ limitations under the License. */ #endregion +using System.ComponentModel; +using System.Reflection; +using System; using Amdocs.Ginger.Common; namespace Amdocs.Ginger.Repository @@ -97,7 +100,7 @@ public enum eHttpVersion HTTPV11, } - public enum eContentType + public enum eRequestContentType { [EnumValueDescription("application/json;charset=utf-8")] JSon, @@ -115,6 +118,24 @@ public enum eContentType JSonWithoutCharset } + public enum eResponseContentType + { + [EnumValueDescription("application/json")] + JSon, + [EnumValueDescription("text/plain")] + TextPlain, + [EnumValueDescription("xml")] + XML, + [EnumValueDescription("application/x-www-form-urlencoded")] + XwwwFormUrlEncoded, + [EnumValueDescription("multipart/form-data")] + FormData, + [EnumValueDescription("application/pdf")] + PDF, + [EnumValueDescription("*/*")] + Any + } + public enum eCookieMode { [EnumValueDescription("Use session cookies")] diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs new file mode 100644 index 0000000000..4e1431342d --- /dev/null +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib +{ + public static class EnumExtensions + { + public static string GetDescription(this Enum value) + { + FieldInfo field = value.GetType().GetField(value.ToString()); + EnumValueDescriptionAttribute attribute = (EnumValueDescriptionAttribute)field.GetCustomAttribute(typeof(EnumValueDescriptionAttribute)); + return attribute == null ? value.ToString() : attribute.ValueDescription; + } + } +} diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs index ac92162dd8..dc30fd6652 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs @@ -18,6 +18,7 @@ limitations under the License. using amdocs.ginger.GingerCoreNET; using Amdocs.Ginger.Common; +using Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib; using Amdocs.Ginger.CoreNET.Platform; using Amdocs.Ginger.Repository; using GingerCore.Actions.WebServices; @@ -51,13 +52,13 @@ public class HttpWebClientUtils HttpResponseMessage Response = null; string BodyString = null; string ContentType; - ApplicationAPIUtils.eContentType eContentType; + ApplicationAPIUtils.eRequestContentType eContentType; public string ResponseMessage = null; public string RequestFileContent = null; public string ResponseFileContent = null; public bool RequestContstructor(ActWebAPIBase act, string ProxySettings, bool useProxyServerSettings) - { + { mAct = act; Handler = new HttpClientHandler(); @@ -522,7 +523,7 @@ public bool SendRequest() Response = Client.SendAsync(RequestMessage).Result; Reporter.ToLog(eLogLevel.DEBUG, "Response status: " + Response.StatusCode); - if (ApplicationAPIUtils.eContentType.PDF.ToString() != mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType)) + if (ApplicationAPIUtils.eResponseContentType.PDF.ToString() != mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType)) { ResponseMessage = Response.Content.ReadAsStringAsync().Result; } @@ -721,7 +722,7 @@ private bool RequestConstractorREST(HttpClientHandler handler) //HTTP Version: SetHTTPVersion(); //Request Content Type: - SetContentType(); + SetResponseContentType(); //Cookie Settings: SetCookies(handler); //Request Body: @@ -731,11 +732,17 @@ private bool RequestConstractorREST(HttpClientHandler handler) private void SetRequestContent(HttpMethod RequestMethod) { - List> KeyValues = []; + eContentType = (ApplicationAPIUtils.eRequestContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ContentType); + + // If the Content-Type is not set using Client Headers then it will be taken through ActWebAPIRest.Fields.ContentType + if (ContentType == null) + { + ContentType = eContentType.GetDescription(); + } if ((RequestMethod.ToString() == ApplicationAPIUtils.eRequestType.GET.ToString())) { - if (eContentType == ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded) + if (eContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { string GetRequest = "?"; if (mAct.RequestKeyValues.Any()) @@ -755,30 +762,15 @@ private void SetRequestContent(HttpMethod RequestMethod) } else { - if (eContentType is not ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded and not ApplicationAPIUtils.eContentType.FormData) - { - string RequestBodyType = mAct.GetInputParamValue(ActWebAPIBase.Fields.RequestBodyTypeRadioButton); - if (RequestBodyType == ApplicationAPIUtils.eRequestBodyType.FreeText.ToString()) - { - string RequestBodyWithDynamicParameters = mAct.GetInputParamCalculatedValue(ActWebAPIBase.Fields.RequestBody).ToString(); - BodyString = SetDynamicValues(RequestBodyWithDynamicParameters); - } - else if (RequestBodyType == ApplicationAPIUtils.eRequestBodyType.TemplateFile.ToString()) - { - BodyString = SetDynamicValues(GetStringBodyFromFile()); - } - } - switch (eContentType) { - case ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded: + case ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded: if (mAct.RequestKeyValues.Any()) { - KeyValues = ConstructURLEncoded((ActWebAPIRest)mAct); - RequestMessage.Content = new FormUrlEncodedContent(KeyValues); + RequestMessage.Content = new FormUrlEncodedContent(ConstructURLEncoded((ActWebAPIRest)mAct)); } break; - case ApplicationAPIUtils.eContentType.FormData: + case ApplicationAPIUtils.eRequestContentType.FormData: if (mAct.RequestKeyValues.Any()) { MultipartFormDataContent requestContent = []; @@ -807,8 +799,9 @@ private void SetRequestContent(HttpMethod RequestMethod) RequestMessage.Content = requestContent; } break; - case ApplicationAPIUtils.eContentType.XML: + case ApplicationAPIUtils.eRequestContentType.XML: string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); + BodyString = GetRequestBodyString(); if (BodyString.StartsWith(_byteOrderMarkUtf8)) { var lastIndexOfUtf8 = _byteOrderMarkUtf8.Length - 1; @@ -817,17 +810,36 @@ private void SetRequestContent(HttpMethod RequestMethod) RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); break; - case ApplicationAPIUtils.eContentType.JSonWithoutCharset: + case ApplicationAPIUtils.eRequestContentType.JSonWithoutCharset: + BodyString = GetRequestBodyString(); RequestMessage.Content = new StringContent(BodyString, new MediaTypeHeaderValue(ContentType)); break; default: + BodyString = GetRequestBodyString(); RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); break; } } } + private string GetRequestBodyString() + { + string RequestBodyType = mAct.GetInputParamValue(ActWebAPIBase.Fields.RequestBodyTypeRadioButton); + + if (RequestBodyType == ApplicationAPIUtils.eRequestBodyType.FreeText.ToString()) + { + string RequestBodyWithDynamicParameters = mAct.GetInputParamCalculatedValue(ActWebAPIBase.Fields.RequestBody).ToString(); + return SetDynamicValues(RequestBodyWithDynamicParameters); + } + else if (RequestBodyType == ApplicationAPIUtils.eRequestBodyType.TemplateFile.ToString()) + { + return SetDynamicValues(GetStringBodyFromFile()); + } + + return string.Empty; + } + private void SetCookies(HttpClientHandler handler) { ApplicationAPIUtils.eCookieMode contentType = (ApplicationAPIUtils.eCookieMode)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.CookieMode); @@ -861,41 +873,10 @@ private void SetCookies(HttpClientHandler handler) } } - private void SetContentType() + private void SetResponseContentType() { - eContentType = (ApplicationAPIUtils.eContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ContentType); - - if (ContentType == null) - { - switch (eContentType) - { - case ApplicationAPIUtils.eContentType.JSon: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - ContentType = "application/json"; - break; - case ApplicationAPIUtils.eContentType.XwwwFormUrlEncoded: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); - ContentType = "application/x-www-form-urlencoded"; - break; - case ApplicationAPIUtils.eContentType.FormData: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data")); - ContentType = "multipart/form-data"; //update to correct value - break; - case ApplicationAPIUtils.eContentType.TextPlain: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); - ContentType = "text/plain; charset=utf-8"; - break; - case ApplicationAPIUtils.eContentType.XML: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); - ContentType = "application/xml"; - break; - - case ApplicationAPIUtils.eContentType.JSonWithoutCharset: - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - ContentType = "application/json"; - break; - } - } + ApplicationAPIUtils.eResponseContentType responseContentType = (ApplicationAPIUtils.eResponseContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(responseContentType.GetDescription())); } private void SetHTTPVersion() diff --git a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs index 78b273db69..2b93b48302 100644 --- a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs +++ b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs @@ -92,15 +92,15 @@ public static string SaveToFile(string fileType, string fileContent, string save contentType = mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType); } - if (contentType == ApplicationAPIUtils.eContentType.XML.ToString()) + if (contentType == ApplicationAPIUtils.eRequestContentType.XML.ToString()) { extension = "xml"; } - else if (contentType == ApplicationAPIUtils.eContentType.JSon.ToString()) + else if (contentType == ApplicationAPIUtils.eRequestContentType.JSon.ToString()) { extension = "json"; } - else if (contentType == ApplicationAPIUtils.eContentType.PDF.ToString()) + else if (contentType == ApplicationAPIUtils.eRequestContentType.PDF.ToString()) { extension = "pdf"; } @@ -122,7 +122,7 @@ public static string SaveToFile(string fileType, string fileContent, string save actName = PathHelper.CleanInValidPathChars(mAct.Description); fullFileName = Path.Combine(directoryFullPath, actName + "_" + timeStamp + "_" + fileType + "." + extension); Act.AddArtifactToAction(Path.GetFileName(fullFileName), mAct, fullFileName); - if (contentType != ApplicationAPIUtils.eContentType.PDF.ToString()) + if (contentType != ApplicationAPIUtils.eRequestContentType.PDF.ToString()) { File.WriteAllText(fullFileName, fileContent); } diff --git a/Ginger/GingerCoreNETUnitTest/GingerRunnerTests/ErrorHandlerActivityTest.cs b/Ginger/GingerCoreNETUnitTest/GingerRunnerTests/ErrorHandlerActivityTest.cs index 38e2f03ccb..a7ddd1e4ce 100644 --- a/Ginger/GingerCoreNETUnitTest/GingerRunnerTests/ErrorHandlerActivityTest.cs +++ b/Ginger/GingerCoreNETUnitTest/GingerRunnerTests/ErrorHandlerActivityTest.cs @@ -146,8 +146,8 @@ public void ErrorHandlerActivityShouldExecuteWhenAnyActivitiesFail() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/100"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; @@ -464,8 +464,8 @@ private Activity GetActivityWithFailedActionScenario() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/100"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; diff --git a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs index 7b96506295..0f3e01f6f4 100644 --- a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs +++ b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs @@ -354,8 +354,8 @@ public void WebServices_RawRequestWebAPIRestWithJSON() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://petstore.swagger.io/v2/pet"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); @@ -454,8 +454,8 @@ public void WebServices_RawRequestWebAPIRestWithXML() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://petstore.swagger.io/v2/pet"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.XML.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.XML.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); @@ -519,8 +519,8 @@ public void WebServices_RawRequestWebAPIRestWithFormData() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://petstore.swagger.io/v2/pet/9223372000668906000"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.FormData.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.FormData.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); @@ -576,8 +576,8 @@ public void WebServices_RawRequestWebAPIRestWithHeaders() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "http://usstlattstl01:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.FormData.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.FormData.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); @@ -617,8 +617,8 @@ public void WebServices_RawRequestWebAPIRestWithAuthentication() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://petstore.swagger.io/v2/user/login"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.BasicAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); @@ -688,8 +688,8 @@ public void WebServices_RawResponseWebAPIRest() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://petstore.swagger.io/v2/pet"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.POST.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.Session.ToString()); @@ -751,8 +751,8 @@ public void WebServices_WebAPIRest() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/1"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.None.ToString()); diff --git a/Ginger/GingerCoreTest/Misc/OutputSimulation.cs b/Ginger/GingerCoreTest/Misc/OutputSimulation.cs index c59223a7e0..54c248efb3 100644 --- a/Ginger/GingerCoreTest/Misc/OutputSimulation.cs +++ b/Ginger/GingerCoreTest/Misc/OutputSimulation.cs @@ -114,8 +114,8 @@ public void SimulatedOuputGingerRunnerFlagOn() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/1"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; @@ -170,8 +170,8 @@ public void SimulatedOuputActionFlagOn() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/1"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; @@ -229,8 +229,8 @@ public void SimulatedOutputWithVETest() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/1"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; @@ -293,8 +293,8 @@ public void SimulatedOutputTest() restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "https://jsonplaceholder.typicode.com/posts/1"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); - restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()); + restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()); restAct.Active = true; restAct.EnableRetryMechanism = false; From e34c68a387d9383d8ffd359e39d9d9a40b78d1c3 Mon Sep 17 00:00:00 2001 From: Mayur Rathi Date: Mon, 27 Jan 2025 20:12:41 +0530 Subject: [PATCH 03/19] Fixed the Unit Tests --- .../APIModelLib/ApplicationAPIUtils.cs | 6 ++-- .../WebServicesDriver/HttpWebClientUtils.cs | 32 ++++++++++++++++++- .../Webservice/WebServicesTest.cs | 6 ++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs index d7d528d2ee..c6aff722e9 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs @@ -102,11 +102,11 @@ public enum eHttpVersion public enum eRequestContentType { - [EnumValueDescription("application/json;charset=utf-8")] + [EnumValueDescription("application/json; charset=utf-8")] JSon, [EnumValueDescription("text/plain;charset=utf-8")] TextPlain, - [EnumValueDescription("xml")] + [EnumValueDescription("application/xml")] XML, [EnumValueDescription("application/x-www-form-urlencoded")] XwwwFormUrlEncoded, @@ -124,7 +124,7 @@ public enum eResponseContentType JSon, [EnumValueDescription("text/plain")] TextPlain, - [EnumValueDescription("xml")] + [EnumValueDescription("application/xml")] XML, [EnumValueDescription("application/x-www-form-urlencoded")] XwwwFormUrlEncoded, diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs index dc30fd6652..79e8475804 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs @@ -737,7 +737,7 @@ private void SetRequestContent(HttpMethod RequestMethod) // If the Content-Type is not set using Client Headers then it will be taken through ActWebAPIRest.Fields.ContentType if (ContentType == null) { - ContentType = eContentType.GetDescription(); + ContentType = GetRequestContentTypeText(eContentType); } if ((RequestMethod.ToString() == ApplicationAPIUtils.eRequestType.GET.ToString())) @@ -823,6 +823,36 @@ private void SetRequestContent(HttpMethod RequestMethod) } } + private static string GetRequestContentTypeText(ApplicationAPIUtils.eRequestContentType eContentType) + { + switch (eContentType) + { + case ApplicationAPIUtils.eRequestContentType.JSon: + return "application/json"; + + case ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded: + return "application/x-www-form-urlencoded"; + + case ApplicationAPIUtils.eRequestContentType.FormData: + return "multipart/form-data"; //update to correct value + + case ApplicationAPIUtils.eRequestContentType.TextPlain: + return "text/plain; charset=utf-8"; + + case ApplicationAPIUtils.eRequestContentType.XML: + return "application/xml"; + + case ApplicationAPIUtils.eRequestContentType.JSonWithoutCharset: + return "application/json"; + + case ApplicationAPIUtils.eRequestContentType.PDF: + return "application/pdf"; + + default: + return string.Empty; + } + } + private string GetRequestBodyString() { string RequestBodyType = mAct.GetInputParamValue(ActWebAPIBase.Fields.RequestBodyTypeRadioButton); diff --git a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs index 0f3e01f6f4..3af6fefa8c 100644 --- a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs +++ b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs @@ -476,7 +476,7 @@ public void WebServices_RawRequestWebAPIRestWithXML() string rawRequestContent = webAPI.RequestFileContent; StringAssert.Contains(rawRequestContent, "POST https://petstore.swagger.io/v2/pet HTTP/1.1"); - StringAssert.Contains(rawRequestContent, "Accept: application/xml"); + StringAssert.Contains(rawRequestContent, "Accept: application/json"); StringAssert.Contains(rawRequestContent, "Content-Type: application/xml; charset=utf-8"); StringAssert.Contains(rawRequestContent, "Content-Length: 229"); StringAssert.Contains(rawRequestContent, "Host: petstore.swagger.io"); @@ -542,7 +542,7 @@ public void WebServices_RawRequestWebAPIRestWithFormData() string untilBoundary = rawRequestContent[..143]; string afterBoundary = rawRequestContent[180..]; StringAssert.Contains(rawRequestContent, "POST https://petstore.swagger.io/v2/pet/9223372000668906000 HTTP/1.1"); - StringAssert.Contains(rawRequestContent, "Accept: multipart/form-data"); + StringAssert.Contains(rawRequestContent, "Accept: application/json"); StringAssert.Contains(rawRequestContent, "Content-Type: multipart/form-data; boundary="); StringAssert.Contains(rawRequestContent, "Content-Length: 313"); StringAssert.Contains(rawRequestContent, "Host: petstore.swagger.io"); @@ -597,7 +597,7 @@ public void WebServices_RawRequestWebAPIRestWithHeaders() string rawRequestContent = webAPI.RequestFileContent; StringAssert.Contains(rawRequestContent, "GET http://usstlattstl01:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c HTTP/1.0"); StringAssert.Contains(rawRequestContent, "IncludeRequestDetails: true"); - StringAssert.Contains(rawRequestContent, "Accept: multipart/form-data"); + StringAssert.Contains(rawRequestContent, "Accept: application/json"); StringAssert.Contains(rawRequestContent, "Host: usstlattstl01:8002"); } From efa1f1f3527ac5545b0c2eb9668bc533a427cb0d Mon Sep 17 00:00:00 2001 From: mayurrat Date: Tue, 28 Jan 2025 12:51:50 +0530 Subject: [PATCH 04/19] Handled CodeRabbitAI Suggestions --- .../WebServices/ActWebAPIEditPage.xaml.cs | 7 ---- .../APIModels/APIModelPage.xaml.cs | 18 +++++----- .../ModelParams Pages/ModelParamsPage.xaml.cs | 2 +- .../APIModelLib/SwaggerApi/OpenApiBase.cs | 12 +++---- .../APIModelLib/SwaggerApi/OpenApiVer3.cs | 4 +-- .../APIModelLib/SwaggerApi/SwaggerVer2.cs | 8 ++--- .../APIModelLib/ApplicationAPIModel.cs | 10 ++++-- .../APIModelLib/EnumExtensions.cs | 27 ++++++++++---- .../Webservices/ActWebAPIModelOperation.cs | 2 +- .../Delta/APIDelta/APIDeltaUtils.cs | 2 +- .../APIModels/ApiActionConversionUtils.cs | 2 +- .../WebServicesDriver/HttpWebClientUtils.cs | 36 ++++++++++--------- .../WebServicesDriver/WebServicesDriver.cs | 8 ++--- .../Webservice/WebServicesTest.cs | 12 +++---- 14 files changed, 82 insertions(+), 68 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs index eb9279082d..0d09a967f8 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs @@ -114,13 +114,6 @@ private void InitializeUIByActionType() break; } } - //public static IEnumerable GetFilteredContentTypes() - //{ - // return Enum.GetValues(typeof(ApplicationAPIUtils.eContentType)) - // .Cast() - // .Where(ct => ct != ApplicationAPIUtils.eContentType.Any); // Exclude Any - //} - public void BindUiControls() { diff --git a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs index a998ea0ba1..3ccc3f83d8 100644 --- a/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs +++ b/Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs @@ -147,7 +147,7 @@ private void InitializeUIByActionType() CookieMode.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.CookieMode), typeof(ApplicationAPIUtils.eCookieMode)); RequestTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.RequestType), typeof(ApplicationAPIUtils.eRequestType)); HttpVersioncombobox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ReqHttpVersion), typeof(ApplicationAPIUtils.eHttpVersion)); - ContentTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ContentType), typeof(ApplicationAPIUtils.eRequestContentType), ContentTypeChange); + ContentTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.RequestContentType), typeof(ApplicationAPIUtils.eRequestContentType), ContentTypeChange); ResponseTypeComboBox.Init(mApplicationAPIModel, nameof(mApplicationAPIModel.ResponseContentType), typeof(ApplicationAPIUtils.eResponseContentType)); //Check maybe the binding of TemplateFileNameFileBrowser need to be different between soap and rest GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(TemplateFileNameFileBrowser, TextBox.TextProperty, mApplicationAPIModel, nameof(mApplicationAPIModel.TemplateFileNameFileBrowser)); @@ -321,7 +321,7 @@ public void BindUiControls() private void ContentTypeChange(object sender, RoutedEventArgs e) { - switch (mApplicationAPIModel.ContentType) + switch (mApplicationAPIModel.RequestContentType) { case ApplicationAPIUtils.eRequestContentType.JSon: RequestBodyTypePanel.Visibility = Visibility.Visible; @@ -361,12 +361,12 @@ public void RefreshRequestKeyValuesGrid() mApplicationAPIModel.APIModelBodyKeyValueHeaders.Clear(); } - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) + else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.FormData) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); @@ -439,14 +439,14 @@ private void BodyExpanded(object sender, RoutedEventArgs e) private void CheckRequestBodySelection() { - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; RequestBodyTypePanel.Visibility = System.Windows.Visibility.Collapsed; FormDataGridPanel.Visibility = System.Windows.Visibility.Visible; } - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.FormData) { FreeStackPanel.Visibility = System.Windows.Visibility.Collapsed; TemplateStackPanel.Visibility = System.Windows.Visibility.Collapsed; @@ -571,7 +571,7 @@ private void RequestBodyType_Selection(object sender, RoutedEventArgs e) break; default: - if (mApplicationAPIModel.ContentType is ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded or ApplicationAPIUtils.eRequestContentType.FormData) + if (mApplicationAPIModel.RequestContentType is ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded or ApplicationAPIUtils.eRequestContentType.FormData) { if (!String.IsNullOrEmpty(mApplicationAPIModel.TemplateFileNameFileBrowser)) { @@ -736,12 +736,12 @@ public void SetKeyValuesGrid() FormDataGrid.btnAdd.RemoveHandler(Button.ClickEvent, new RoutedEventHandler(AddFormDataGridRow)); FormDataGrid.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddFormDataGridRow)); - if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) + if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { //switch combobox & browse button off FormDataGrid.ChangeGridView("UrlEncoded"); } - else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) + else if ((mApplicationAPIModel.APIType == ApplicationAPIUtils.eWebApiType.REST) && mApplicationAPIModel.RequestContentType == ApplicationAPIUtils.eRequestContentType.FormData) { //switch combobox & browse button on FormDataGrid.ChangeGridView("FormData"); diff --git a/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs b/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs index bb4118aefa..d0aa5c570f 100644 --- a/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs +++ b/Ginger/Ginger/ApplicationModelsLib/ModelParams Pages/ModelParamsPage.xaml.cs @@ -357,7 +357,7 @@ private void ClearAllParams_Clicked(object sender, RoutedEventArgs e) private void DeleteParams(bool ClearAllParams) { Amdocs.Ginger.Common.eUserMsgSelection messageResult = Amdocs.Ginger.Common.eUserMsgSelection.No; - if (mApplicationModel is ApplicationAPIModel && (((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eRequestContentType.XML || ((ApplicationAPIModel)mApplicationModel).ContentType == ApplicationAPIUtils.eRequestContentType.JSon)) + if (mApplicationModel is ApplicationAPIModel && (((ApplicationAPIModel)mApplicationModel).RequestContentType == ApplicationAPIUtils.eRequestContentType.XML || ((ApplicationAPIModel)mApplicationModel).RequestContentType == ApplicationAPIUtils.eRequestContentType.JSon)) { messageResult = Reporter.ToUser(eUserMsgKey.DeleteNodesFromRequest); } diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs index de6ba952c3..f2728c5540 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs @@ -59,7 +59,7 @@ public void GenerateResponse(SwaggerOperation operation, ApplicationAPIModel bas { schemaObj = response.Schema.Reference; } - if (basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.XML) + if (basicModal.RequestContentType == ApplicationAPIUtils.eRequestContentType.XML) { ApplicationAPIModel JsonResponseModel = new ApplicationAPIModel(); @@ -76,8 +76,8 @@ public void GenerateResponse(SwaggerOperation operation, ApplicationAPIModel bas basicModal.ReturnValues.Add(arv); } } - else if (basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.JSon || - basicModal.ContentType == ApplicationAPIUtils.eRequestContentType.FormData) + else if (basicModal.RequestContentType == ApplicationAPIUtils.eRequestContentType.JSon || + basicModal.RequestContentType == ApplicationAPIUtils.eRequestContentType.FormData) { ApplicationAPIModel jsonResponseModel = new ApplicationAPIModel(); var generatedJsonBody = GenerateJsonBody(jsonResponseModel, schemaObj); @@ -211,7 +211,7 @@ public ObservableList GenerateXMLBody(ApplicationAPIModel aAM ApplicationAPIModel aam = XTp.ParseDocument(temppath, new ObservableList()).ElementAt(0); aAM.RequestBody = aam.RequestBody; aAM.RequestBodyType = ApplicationAPIUtils.eRequestBodyType.FreeText; - aam.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + aam.RequestContentType = ApplicationAPIUtils.eRequestContentType.XML; return aam.AppModelParameters; } @@ -228,11 +228,11 @@ public void GenerateFormParameters(ApplicationAPIModel aAM, SwaggerOperation ope { if (isMultiPartFormdata) { - aAM.ContentType = ApplicationAPIUtils.eRequestContentType.FormData; + aAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.FormData; } else { - aAM.ContentType = ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded; + aAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded; } foreach (SwaggerParameter SP in operation.ActualParameters) { diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs index ed10572fdd..74ff2a2732 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs @@ -79,7 +79,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd } break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.JSon; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { @@ -90,7 +90,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.XML; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs index 8b326a1afd..c745823af9 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs @@ -76,7 +76,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc GenerateFormParameters(AAM, Operation, true); break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.JSon; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { @@ -89,7 +89,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.XML; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { @@ -135,7 +135,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc GenerateFormParameters(AAM, Operation, true); break; case "application/json": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.JSon; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.JSon; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; if (Operation.RequestBody != null) { @@ -149,7 +149,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; case "application/xml": - AAM.ContentType = ApplicationAPIUtils.eRequestContentType.XML; + AAM.RequestContentType = ApplicationAPIUtils.eRequestContentType.XML; AAM.ResponseContentType = ApplicationAPIUtils.eResponseContentType.XML; if (Operation.RequestBody != null) { diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs index 1bb05abdc1..bd60d26f88 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs @@ -140,13 +140,19 @@ public override string ObjFileExt [IsSerializedForLocalRepository] public ApplicationAPIUtils.eRequestType RequestType { get { return mRequestType; } set { if (mRequestType != value) { mRequestType = value; OnPropertyChanged(nameof(RequestType)); } } } + /// + /// Gets or sets the content type expected in the response. + /// ApplicationAPIUtils.eResponseContentType mResponseContentType = ApplicationAPIUtils.eResponseContentType.JSon; [IsSerializedForLocalRepository] public ApplicationAPIUtils.eResponseContentType ResponseContentType { get { return mResponseContentType; } set { if (mResponseContentType != value) { mResponseContentType = value; OnPropertyChanged(nameof(ResponseContentType)); } } } - ApplicationAPIUtils.eRequestContentType mContentType = ApplicationAPIUtils.eRequestContentType.JSon; + /// ++ /// Gets or sets the content type to be used in the request. ++ /// + ApplicationAPIUtils.eRequestContentType mRequestContentType = ApplicationAPIUtils.eRequestContentType.JSon; [IsSerializedForLocalRepository] - public ApplicationAPIUtils.eRequestContentType ContentType { get { return mContentType; } set { if (mContentType != value) { mContentType = value; OnPropertyChanged(nameof(ContentType)); } } } + public ApplicationAPIUtils.eRequestContentType RequestContentType { get { return mRequestContentType; } set { if (mRequestContentType != value) { mRequestContentType = value; OnPropertyChanged(nameof(RequestContentType)); } } } ApplicationAPIUtils.eCookieMode mCookieMode = ApplicationAPIUtils.eCookieMode.Session; [IsSerializedForLocalRepository] diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs index 4e1431342d..516d563fbd 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs @@ -1,16 +1,29 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; +#region License +/* +Copyright © 2014-2024 European Support Limited + +Licensed under the Apache License, Version 2.0 (the "License") +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#endregion + +using System; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib { public static class EnumExtensions { - public static string GetDescription(this Enum value) + public static string GetEnumValueDescription(this Enum value) { FieldInfo field = value.GetType().GetField(value.ToString()); EnumValueDescriptionAttribute attribute = (EnumValueDescriptionAttribute)field.GetCustomAttribute(typeof(EnumValueDescriptionAttribute)); diff --git a/Ginger/GingerCoreNET/ActionsLib/Webservices/ActWebAPIModelOperation.cs b/Ginger/GingerCoreNET/ActionsLib/Webservices/ActWebAPIModelOperation.cs index 49b49d50cb..97a70b70a4 100644 --- a/Ginger/GingerCoreNET/ActionsLib/Webservices/ActWebAPIModelOperation.cs +++ b/Ginger/GingerCoreNET/ActionsLib/Webservices/ActWebAPIModelOperation.cs @@ -26,7 +26,7 @@ public void FillAPIBaseFields(ApplicationAPIModel AAMB, ActWebAPIBase actWebAPIB actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.ReqHttpVersion, AAMBDuplicate.ReqHttpVersion.ToString()); actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.ResponseContentType, AAMBDuplicate.ResponseContentType.ToString()); actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.CookieMode, AAMBDuplicate.CookieMode.ToString()); - actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.ContentType, AAMBDuplicate.ContentType.ToString()); + actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.ContentType, AAMBDuplicate.RequestContentType.ToString()); actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPISoap.Fields.SOAPAction, AAMBDuplicate.SOAPAction); actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIBase.Fields.EndPointURL, AAMBDuplicate.EndpointURL); actWebAPIBase.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIBase.Fields.NetworkCredentialsRadioButton, AAMBDuplicate.NetworkCredentials.ToString()); diff --git a/Ginger/GingerCoreNET/Application Models/Delta/APIDelta/APIDeltaUtils.cs b/Ginger/GingerCoreNET/Application Models/Delta/APIDelta/APIDeltaUtils.cs index 6363f0988e..be87cb75ac 100644 --- a/Ginger/GingerCoreNET/Application Models/Delta/APIDelta/APIDeltaUtils.cs +++ b/Ginger/GingerCoreNET/Application Models/Delta/APIDelta/APIDeltaUtils.cs @@ -105,7 +105,7 @@ public static List CompareAPIModels(ApplicationAPIModel lea existingAPIs = existingAPIs.Where(m => m.ResponseContentType == learnedModel.ResponseContentType).ToList(); // Filter matching APIs based on Content Type - existingAPIs = existingAPIs.Where(m => m.ContentType == learnedModel.ContentType).ToList(); + existingAPIs = existingAPIs.Where(m => m.RequestContentType == learnedModel.RequestContentType).ToList(); } // Filter matching APIs based on URL Domain diff --git a/Ginger/GingerCoreNET/Application Models/Learn/APIModels/ApiActionConversionUtils.cs b/Ginger/GingerCoreNET/Application Models/Learn/APIModels/ApiActionConversionUtils.cs index 0d1bea9a1d..b8f17547b3 100644 --- a/Ginger/GingerCoreNET/Application Models/Learn/APIModels/ApiActionConversionUtils.cs +++ b/Ginger/GingerCoreNET/Application Models/Learn/APIModels/ApiActionConversionUtils.cs @@ -426,7 +426,7 @@ private void CreateAPIModelFromWebserviceAction(ref ApplicationAPIModel aPIModel SetPropertyValue(aPIModel, nameof(ActWebAPIRest.Fields.ReqHttpVersion), nameof(ApplicationAPIModel.ReqHttpVersion), actionToConvert); SetPropertyValue(aPIModel, nameof(ActWebAPIRest.Fields.ResponseContentType), nameof(ApplicationAPIModel.ResponseContentType), actionToConvert); SetPropertyValue(aPIModel, nameof(ActWebAPIRest.Fields.CookieMode), nameof(ApplicationAPIModel.CookieMode), actionToConvert); - SetPropertyValue(aPIModel, nameof(ActWebAPIRest.Fields.ContentType), nameof(ApplicationAPIModel.ContentType), actionToConvert); + SetPropertyValue(aPIModel, nameof(ActWebAPIRest.Fields.ContentType), nameof(ApplicationAPIModel.RequestContentType), actionToConvert); SetPropertyValue(aPIModel, nameof(ActWebAPISoap.Fields.SOAPAction), nameof(ApplicationAPIModel.SOAPAction), actionToConvert); SetPropertyValue(aPIModel, nameof(ActWebAPIBase.Fields.EndPointURL), nameof(ApplicationAPIModel.EndpointURL), actionToConvert); SetPropertyValue(aPIModel, nameof(ActWebAPIBase.Fields.URLUser), nameof(ApplicationAPIModel.URLUser), actionToConvert); diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs index 79e8475804..6ca844f048 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs @@ -51,13 +51,12 @@ public class HttpWebClientUtils static Dictionary SessionCokiesDic = []; HttpResponseMessage Response = null; string BodyString = null; - string ContentType; - ApplicationAPIUtils.eRequestContentType eContentType; + string ContentType; public string ResponseMessage = null; public string RequestFileContent = null; public string ResponseFileContent = null; - public bool RequestContstructor(ActWebAPIBase act, string ProxySettings, bool useProxyServerSettings) + public bool RequestConstructor(ActWebAPIBase act, string ProxySettings, bool useProxyServerSettings) { mAct = act; Handler = new HttpClientHandler(); @@ -80,7 +79,7 @@ public bool RequestContstructor(ActWebAPIBase act, string ProxySettings, bool us SetSecurityType(); AddHeadersToClient(); - return act.GetType() == typeof(ActWebAPISoap) ? RequestConstracotSOAP((ActWebAPISoap)act) : RequestConstractorREST(Handler); + return act.GetType() == typeof(ActWebAPISoap) ? RequestConstracotSOAP((ActWebAPISoap)act) : RequestConstructorREST(Handler); } private void SetAutoDecompression(HttpClientHandler handler) @@ -492,7 +491,7 @@ public string GetRawRequestContentPreview(ActWebAPIBase act) context.Runner.PrepActionValueExpression(act, context.BusinessFlow); } //Create Request content - RequestContstructor(act, null, false); + RequestConstructor(act, null, false); CreateRawRequestContent(); return RequestFileContent; } @@ -640,7 +639,7 @@ public bool ParseRespondToOutputParams() return true; } - public void CreatRawResponseContent() + public void CreateRawResponseContent() { @@ -677,7 +676,7 @@ public void SaveResponseToFile(bool saveResponse, string savePath) { if (saveResponse) { - CreatRawResponseContent(); + CreateRawResponseContent(); string FileFullPath = Webserviceplatforminfo.SaveToFile("Response", ResponseFileContent, savePath, mAct); mAct.AddOrUpdateReturnParamActual("Saved Response File Name", Path.GetFileName(FileFullPath)); @@ -714,7 +713,7 @@ private void HandleResponseCookies() } } - private bool RequestConstractorREST(HttpClientHandler handler) + private bool RequestConstructorREST(HttpClientHandler handler) { //Request Method: HttpMethod RequestMethod = new HttpMethod(mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.RequestType).ToUpper()); @@ -732,17 +731,17 @@ private bool RequestConstractorREST(HttpClientHandler handler) private void SetRequestContent(HttpMethod RequestMethod) { - eContentType = (ApplicationAPIUtils.eRequestContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ContentType); + ApplicationAPIUtils.eRequestContentType requestContentType = (ApplicationAPIUtils.eRequestContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ContentType); // If the Content-Type is not set using Client Headers then it will be taken through ActWebAPIRest.Fields.ContentType if (ContentType == null) { - ContentType = GetRequestContentTypeText(eContentType); + ContentType = GetRequestContentTypeText(requestContentType); } if ((RequestMethod.ToString() == ApplicationAPIUtils.eRequestType.GET.ToString())) { - if (eContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) + if (requestContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { string GetRequest = "?"; if (mAct.RequestKeyValues.Any()) @@ -762,7 +761,7 @@ private void SetRequestContent(HttpMethod RequestMethod) } else { - switch (eContentType) + switch (requestContentType) { case ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded: if (mAct.RequestKeyValues.Any()) @@ -815,10 +814,13 @@ private void SetRequestContent(HttpMethod RequestMethod) RequestMessage.Content = new StringContent(BodyString, new MediaTypeHeaderValue(ContentType)); break; - default: + case ApplicationAPIUtils.eRequestContentType.JSon: BodyString = GetRequestBodyString(); RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); break; + + default: + throw new InvalidOperationException($"Unsupported Content-Type: {requestContentType}"); } } } @@ -849,7 +851,7 @@ private static string GetRequestContentTypeText(ApplicationAPIUtils.eRequestCont return "application/pdf"; default: - return string.Empty; + throw new InvalidOperationException($"Unsupported RequestBodyType: {eContentType}"); } } @@ -867,7 +869,7 @@ private string GetRequestBodyString() return SetDynamicValues(GetStringBodyFromFile()); } - return string.Empty; + throw new InvalidOperationException($"Unsupported RequestBodyType: {RequestBodyType}"); } private void SetCookies(HttpClientHandler handler) @@ -906,7 +908,7 @@ private void SetCookies(HttpClientHandler handler) private void SetResponseContentType() { ApplicationAPIUtils.eResponseContentType responseContentType = (ApplicationAPIUtils.eResponseContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(responseContentType.GetDescription())); + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(responseContentType.GetEnumValueDescription())); } private void SetHTTPVersion() @@ -1076,4 +1078,4 @@ public static List GetSoapSecurityHeaderContent(ref string txtBoxBodyCon return SecuritryContent; } } -} +} \ No newline at end of file diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/WebServicesDriver.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/WebServicesDriver.cs index b30d9dcb35..74e95640cd 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/WebServicesDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/WebServicesDriver.cs @@ -256,7 +256,7 @@ public void CreateRawRequest(Act act) if (act is ActWebAPISoap or ActWebAPIRest) { - if (WebAPI.RequestContstructor((ActWebAPIBase)act, WebServicesProxy, UseServerProxySettings)) + if (WebAPI.RequestConstructor((ActWebAPIBase)act, WebServicesProxy, UseServerProxySettings)) { WebAPI.SaveRequest(SaveRequestXML, SavedXMLDirectoryPath); @@ -288,7 +288,7 @@ public void CreateRawRequest(Act act) throw new Exception("The Action from type '" + act.GetType().ToString() + "' is unknown/Not Implemented by the Driver - " + this.GetType().ToString()); } - if (WebAPI.RequestContstructor(actWebAPI, WebServicesProxy, UseServerProxySettings)) + if (WebAPI.RequestConstructor(actWebAPI, WebServicesProxy, UseServerProxySettings)) { WebAPI.SaveRequest(SaveRequestXML, SavedXMLDirectoryPath); } @@ -494,12 +494,12 @@ private void HandleWebApiRequest(ActWebAPIBase act) mWebAPI = new HttpWebClientUtils(); //Call for Request Construction - if (mWebAPI.RequestContstructor(act, WebServicesProxy, UseServerProxySettings)) + if (mWebAPI.RequestConstructor(act, WebServicesProxy, UseServerProxySettings)) { mWebAPI.SaveRequest(SaveRequestXML, SavedXMLDirectoryPath); mRawRequest = mWebAPI.RequestFileContent; - Reporter.ToLog(eLogLevel.DEBUG, "RequestContstructor passed successfully"); + Reporter.ToLog(eLogLevel.DEBUG, "RequestConstructor passed successfully"); if (mWebAPI.SendRequest()) { diff --git a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs index 3af6fefa8c..96b84e4286 100644 --- a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs +++ b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs @@ -371,7 +371,7 @@ public void WebServices_RawRequestWebAPIRestWithJSON() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(restAct, null, false); + webAPI.RequestConstructor(restAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; @@ -425,7 +425,7 @@ public void WebServices_RawRequestWebAPISoap() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(soapAct, null, false); + webAPI.RequestConstructor(soapAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; @@ -471,7 +471,7 @@ public void WebServices_RawRequestWebAPIRestWithXML() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(restAct, null, false); + webAPI.RequestConstructor(restAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; @@ -534,7 +534,7 @@ public void WebServices_RawRequestWebAPIRestWithFormData() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(restAct, null, false); + webAPI.RequestConstructor(restAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; @@ -591,7 +591,7 @@ public void WebServices_RawRequestWebAPIRestWithHeaders() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(restAct, null, false); + webAPI.RequestConstructor(restAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; @@ -634,7 +634,7 @@ public void WebServices_RawRequestWebAPIRestWithAuthentication() } HttpWebClientUtils webAPI = new HttpWebClientUtils(); - webAPI.RequestContstructor(restAct, null, false); + webAPI.RequestConstructor(restAct, null, false); webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; From 0780b76161b46a7b5e55fb1fff48359f2d8c48a5 Mon Sep 17 00:00:00 2001 From: mayurrat Date: Tue, 28 Jan 2025 13:01:29 +0530 Subject: [PATCH 05/19] Handled Build Errors. --- .../ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs index bd60d26f88..7d44facaf5 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs @@ -148,8 +148,8 @@ public override string ObjFileExt public ApplicationAPIUtils.eResponseContentType ResponseContentType { get { return mResponseContentType; } set { if (mResponseContentType != value) { mResponseContentType = value; OnPropertyChanged(nameof(ResponseContentType)); } } } /// -+ /// Gets or sets the content type to be used in the request. -+ /// + /// Gets or sets the content type to be used in the request. + /// ApplicationAPIUtils.eRequestContentType mRequestContentType = ApplicationAPIUtils.eRequestContentType.JSon; [IsSerializedForLocalRepository] public ApplicationAPIUtils.eRequestContentType RequestContentType { get { return mRequestContentType; } set { if (mRequestContentType != value) { mRequestContentType = value; OnPropertyChanged(nameof(RequestContentType)); } } } From ee2b8ed5457811f9a51d44d575253db5ec8bcdae Mon Sep 17 00:00:00 2001 From: mayurrat Date: Tue, 28 Jan 2025 15:39:37 +0530 Subject: [PATCH 06/19] Handled the Review comments --- .../WebServices/ActWebAPIEditPage.xaml.cs | 23 ++++++++----------- .../Webservice/WebServicesTest.cs | 6 ++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs index 0d09a967f8..f5da52f01b 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs @@ -79,22 +79,19 @@ private void InitializeUIByActionType() PanelSoap.Visibility = Visibility.Collapsed; UseWSSecurityHeader.Visibility = Visibility.Collapsed; //Cookie Mode - CookieMode.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.CookieMode, ApplicationAPIUtils.eCookieMode.Session.ToString()), typeof(ApplicationAPIUtils.eCookieMode), false, null); + CookieMode.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.CookieMode, nameof(ApplicationAPIUtils.eCookieMode.Session)), typeof(ApplicationAPIUtils.eCookieMode), false, null); //Request Type - RequestTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()), typeof(ApplicationAPIUtils.eRequestType), false, null); + RequestTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.RequestType, nameof(ApplicationAPIUtils.eRequestType.GET)), typeof(ApplicationAPIUtils.eRequestType), false, null); //HttpVersion content type - HttpVersioncombobox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ReqHttpVersion, ApplicationAPIUtils.eHttpVersion.HTTPV11.ToString()), typeof(ApplicationAPIUtils.eHttpVersion), false, null); + HttpVersioncombobox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ReqHttpVersion, nameof(ApplicationAPIUtils.eHttpVersion.HTTPV11)), typeof(ApplicationAPIUtils.eHttpVersion), false, null); //Request content type - ContentTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eRequestContentType), false, ContentTypeChange); + ContentTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ContentType, nameof(ApplicationAPIUtils.eRequestContentType.JSon)), typeof(ApplicationAPIUtils.eRequestContentType), false, ContentTypeChange); //Response Content Type - ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eResponseContentType.JSon.ToString()), typeof(ApplicationAPIUtils.eResponseContentType), false, ResponseTypeComboBox_SelectionChanged); - //ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, ApplicationAPIUtils.eContentType.JSon.ToString()), - // GetFilteredContentTypes(), - // false, ResponseTypeComboBox_SelectionChanged); + ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, nameof(ApplicationAPIUtils.eResponseContentType.JSon)), typeof(ApplicationAPIUtils.eResponseContentType), false, ResponseTypeComboBox_SelectionChanged); //Request Template file: TemplateFileNameFileBrowser.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.TemplateFileNameFileBrowser), true, true, UCValueExpression.eBrowserType.File, "txt; *.xml; *.json;", new RoutedEventHandler(BrowseTemplateFileButton_Click)); @@ -125,13 +122,13 @@ public void BindUiControls() URLPasswordUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.URLPass), true, false, UCValueExpression.eBrowserType.Folder); //Network Credential selection radio button: - NetworkCredentialsRadioButton.Init(typeof(ApplicationAPIUtils.eNetworkCredentials), NetworkCeredentials, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.NetworkCredentialsRadioButton, ApplicationAPIUtils.eNetworkCredentials.Default.ToString()), NetworkCreds_SelectionChanged); + NetworkCredentialsRadioButton.Init(typeof(ApplicationAPIUtils.eNetworkCredentials), NetworkCeredentials, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.NetworkCredentialsRadioButton, nameof(ApplicationAPIUtils.eNetworkCredentials.Default)), NetworkCreds_SelectionChanged); //Request Body Selection radio button: - RequestBodyTypeRadioButton.Init(typeof(ApplicationAPIUtils.eRequestBodyType), BodySelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.RequestBodyTypeRadioButton, ApplicationAPIUtils.eRequestBodyType.FreeText.ToString()), RequestBodyType_Selection); + RequestBodyTypeRadioButton.Init(typeof(ApplicationAPIUtils.eRequestBodyType), BodySelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.RequestBodyTypeRadioButton, nameof(ApplicationAPIUtils.eRequestBodyType.FreeText)), RequestBodyType_Selection); //CertficiateRadioButtons : - CertificateTypeRadioButton.Init(typeof(ApplicationAPIUtils.eCretificateType), CertificateSelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()), CertificateSelection_Changed); + CertificateTypeRadioButton.Init(typeof(ApplicationAPIUtils.eCretificateType), CertificateSelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.CertificateTypeRadioButton, nameof(ApplicationAPIUtils.eCretificateType.AllSSL)), CertificateSelection_Changed); //Response validation checkbox: GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(DoNotFailActionOnBadRespose, CheckBox.IsCheckedProperty, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.DoNotFailActionOnBadRespose, "False")); @@ -155,10 +152,10 @@ public void BindUiControls() GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(DoNotCertificateImportFile, CheckBox.IsCheckedProperty, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.ImportCetificateFile, "False")); //Security: - SecurityTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()), typeof(ApplicationAPIUtils.eSercurityType), false, null); + SecurityTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.SecurityType, nameof(ApplicationAPIUtils.eSercurityType.None)), typeof(ApplicationAPIUtils.eSercurityType), false, null); //Authorization: - AuthTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()), typeof(ApplicationAPIUtils.eAuthType), false, AuthorizationBox); + AuthTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthorizationType, nameof(ApplicationAPIUtils.eAuthType.NoAuthentication)), typeof(ApplicationAPIUtils.eAuthType), false, AuthorizationBox); //Authorization AuthUserUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthUsername), true, false, UCValueExpression.eBrowserType.Folder); diff --git a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs index 96b84e4286..1921cd623c 100644 --- a/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs +++ b/Ginger/GingerCoreNETUnitTest/Webservice/WebServicesTest.cs @@ -573,7 +573,7 @@ public void WebServices_RawRequestWebAPIRestWithHeaders() restAct.HttpHeaders.Add(aiv); //Build REST Request: - restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "http://usstlattstl01:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c"); + restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.EndPointURL, "http://dummyhost:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c"); restAct.AddOrUpdateInputParamValue(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.RequestType, ApplicationAPIUtils.eRequestType.GET.ToString()); restAct.AddOrUpdateInputParamValue(ActWebAPIRest.Fields.ContentType, ApplicationAPIUtils.eRequestContentType.FormData.ToString()); @@ -595,10 +595,10 @@ public void WebServices_RawRequestWebAPIRestWithHeaders() webAPI.CreateRawRequestContent(); string rawRequestContent = webAPI.RequestFileContent; - StringAssert.Contains(rawRequestContent, "GET http://usstlattstl01:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c HTTP/1.0"); + StringAssert.Contains(rawRequestContent, "GET http://dummyhost:8002/api/v1/executions?executionIds=33b2dea1-c24a-494c-97d4-0bd47e59620c HTTP/1.0"); StringAssert.Contains(rawRequestContent, "IncludeRequestDetails: true"); StringAssert.Contains(rawRequestContent, "Accept: application/json"); - StringAssert.Contains(rawRequestContent, "Host: usstlattstl01:8002"); + StringAssert.Contains(rawRequestContent, "Host: dummyhost:8002"); } [TestMethod] From 3a11f97f9a82fbb60702eaf132c436afaea0d2c8 Mon Sep 17 00:00:00 2001 From: mayurrat Date: Tue, 28 Jan 2025 19:27:43 +0530 Subject: [PATCH 07/19] Handled Review Comments and added code to support multiple Response Content type in Accept header --- .../WebServices/ActWebAPIEditPage.xaml.cs | 2 +- .../Actions/Webservices/ActWebAPIBase.cs | 2 +- .../APIModelLib/ApplicationAPIUtils.cs | 6 +- .../APIModelLib/EnumExtensions.cs | 33 ---------- .../WebServicesDriver/HttpWebClientUtils.cs | 63 ++++++++++++++++--- 5 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs diff --git a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs index f5da52f01b..daefc04616 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs @@ -620,7 +620,7 @@ private void AddRow(object sender, RoutedEventArgs e) } private void ResponseTypeComboBox_SelectionChanged(object sender, RoutedEventArgs e) { - if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eResponseContentType.JSon.ToString()) + if (mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eResponseContentType.JSon.ToString() || mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType) == ApplicationAPIUtils.eResponseContentType.JSonWithoutCharset.ToString()) { JSON.Visibility = Visibility.Visible; } diff --git a/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs b/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs index 1bb72a4e72..d26edbd029 100644 --- a/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs +++ b/Ginger/GingerCoreCommon/Actions/Webservices/ActWebAPIBase.cs @@ -221,7 +221,7 @@ public static bool ParseNodesToReturnParams(ActWebAPIBase mAct, string ResponseM string ResponseContentType = mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); bool jsonParsinFailed = false; - if (ResponseContentType == ApplicationAPIUtils.eResponseContentType.JSon.ToString()) + if (ResponseContentType == ApplicationAPIUtils.eResponseContentType.JSon.ToString() || ResponseContentType == ApplicationAPIUtils.eResponseContentType.JSonWithoutCharset.ToString()) { if (!ParseJsonNodesToReturnParams(mAct, ResponseMessage)) { diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs index c6aff722e9..6d7b8b8bfa 100644 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs +++ b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIUtils.cs @@ -120,7 +120,7 @@ public enum eRequestContentType public enum eResponseContentType { - [EnumValueDescription("application/json")] + [EnumValueDescription("application/json; charset=utf-8")] JSon, [EnumValueDescription("text/plain")] TextPlain, @@ -133,7 +133,9 @@ public enum eResponseContentType [EnumValueDescription("application/pdf")] PDF, [EnumValueDescription("*/*")] - Any + Any, + [EnumValueDescription("application/json")] + JSonWithoutCharset } public enum eCookieMode diff --git a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs b/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs deleted file mode 100644 index 516d563fbd..0000000000 --- a/Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/EnumExtensions.cs +++ /dev/null @@ -1,33 +0,0 @@ -#region License -/* -Copyright © 2014-2024 European Support Limited - -Licensed under the Apache License, Version 2.0 (the "License") -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#endregion - -using System; -using System.Reflection; - -namespace Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib -{ - public static class EnumExtensions - { - public static string GetEnumValueDescription(this Enum value) - { - FieldInfo field = value.GetType().GetField(value.ToString()); - EnumValueDescriptionAttribute attribute = (EnumValueDescriptionAttribute)field.GetCustomAttribute(typeof(EnumValueDescriptionAttribute)); - return attribute == null ? value.ToString() : attribute.ValueDescription; - } - } -} diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs index 6ca844f048..a6fc34af9d 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs @@ -18,7 +18,6 @@ limitations under the License. using amdocs.ginger.GingerCoreNET; using Amdocs.Ginger.Common; -using Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib; using Amdocs.Ginger.CoreNET.Platform; using Amdocs.Ginger.Repository; using GingerCore.Actions.WebServices; @@ -51,7 +50,8 @@ public class HttpWebClientUtils static Dictionary SessionCokiesDic = []; HttpResponseMessage Response = null; string BodyString = null; - string ContentType; + string ContentType; + string Accept; public string ResponseMessage = null; public string RequestFileContent = null; public string ResponseFileContent = null; @@ -115,6 +115,10 @@ private void AddHeadersToClient() { ContentType = value; } + else if (param == "Accept") + { + Accept = value; + } else if (param.ToUpper() == "DATE") { @@ -620,10 +624,6 @@ public bool ParseRespondToOutputParams() mAct.AddOrUpdateReturnParamActual("Respond", "Respond returned as null"); } - - - - string prettyResponse = XMLDocExtended.PrettyXml(ResponseMessage); mAct.AddOrUpdateReturnParamActual("Response:", prettyResponse); @@ -907,8 +907,55 @@ private void SetCookies(HttpClientHandler handler) private void SetResponseContentType() { - ApplicationAPIUtils.eResponseContentType responseContentType = (ApplicationAPIUtils.eResponseContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(responseContentType.GetEnumValueDescription())); + if (Accept == null) + { + ApplicationAPIUtils.eResponseContentType responseContentType = (ApplicationAPIUtils.eResponseContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(GetResponseContentTypeText(responseContentType))); + } + else + { + if (Accept.Contains(',')) + { + foreach (var acceptHeader in Accept.Split(',')) + { + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader.Trim())); + } + } + else + { + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Accept.Trim())); + } + } + } + private static string GetResponseContentTypeText(ApplicationAPIUtils.eResponseContentType eContentType) + { + switch (eContentType) + { + case ApplicationAPIUtils.eResponseContentType.JSon: + case ApplicationAPIUtils.eResponseContentType.JSonWithoutCharset: + return "application/json"; + + case ApplicationAPIUtils.eResponseContentType.XwwwFormUrlEncoded: + return "application/x-www-form-urlencoded"; + + case ApplicationAPIUtils.eResponseContentType.FormData: + return "multipart/form-data"; //update to correct value + + case ApplicationAPIUtils.eResponseContentType.TextPlain: + return "text/plain; charset=utf-8"; + + case ApplicationAPIUtils.eResponseContentType.XML: + return "application/xml"; + + case ApplicationAPIUtils.eResponseContentType.PDF: + return "application/pdf"; + + case ApplicationAPIUtils.eResponseContentType.Any: + return "*/*"; + + default: + throw new InvalidOperationException($"Unsupported ResponseContentType: {eContentType}"); + } } private void SetHTTPVersion() From 810f92869ed7d704a36c8b47cd1ca1da3b12c0dc Mon Sep 17 00:00:00 2001 From: mayurrat Date: Tue, 28 Jan 2025 20:21:52 +0530 Subject: [PATCH 08/19] Response Content Type default value set to Any and Handled CodRabbitAi suggestion Comments and --- .../WebServices/ActWebAPIEditPage.xaml.cs | 2 +- .../WebServicesDriver/HttpWebClientUtils.cs | 53 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs index daefc04616..a108c134f7 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/WebServices/ActWebAPIEditPage.xaml.cs @@ -91,7 +91,7 @@ private void InitializeUIByActionType() ContentTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ContentType, nameof(ApplicationAPIUtils.eRequestContentType.JSon)), typeof(ApplicationAPIUtils.eRequestContentType), false, ContentTypeChange); //Response Content Type - ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, nameof(ApplicationAPIUtils.eResponseContentType.JSon)), typeof(ApplicationAPIUtils.eResponseContentType), false, ResponseTypeComboBox_SelectionChanged); + ResponseTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIRest.Fields.ResponseContentType, nameof(ApplicationAPIUtils.eResponseContentType.Any)), typeof(ApplicationAPIUtils.eResponseContentType), false, ResponseTypeComboBox_SelectionChanged); //Request Template file: TemplateFileNameFileBrowser.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.TemplateFileNameFileBrowser), true, true, UCValueExpression.eBrowserType.File, "txt; *.xml; *.json;", new RoutedEventHandler(BrowseTemplateFileButton_Click)); diff --git a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs index a6fc34af9d..e5df2fdd77 100644 --- a/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs +++ b/Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs @@ -50,8 +50,8 @@ public class HttpWebClientUtils static Dictionary SessionCokiesDic = []; HttpResponseMessage Response = null; string BodyString = null; - string ContentType; - string Accept; + string ContentTypeHeader; + string AcceptHeader; public string ResponseMessage = null; public string RequestFileContent = null; public string ResponseFileContent = null; @@ -79,7 +79,7 @@ public bool RequestConstructor(ActWebAPIBase act, string ProxySettings, bool use SetSecurityType(); AddHeadersToClient(); - return act.GetType() == typeof(ActWebAPISoap) ? RequestConstracotSOAP((ActWebAPISoap)act) : RequestConstructorREST(Handler); + return act.GetType() == typeof(ActWebAPISoap) ? RequestConstructorSOAP((ActWebAPISoap)act) : RequestConstructorREST(Handler); } private void SetAutoDecompression(HttpClientHandler handler) @@ -113,11 +113,11 @@ private void AddHeadersToClient() { if (param == "Content-Type") { - ContentType = value; + ContentTypeHeader = value; } else if (param == "Accept") { - Accept = value; + AcceptHeader = value; } else if (param.ToUpper() == "DATE") { @@ -734,12 +734,11 @@ private void SetRequestContent(HttpMethod RequestMethod) ApplicationAPIUtils.eRequestContentType requestContentType = (ApplicationAPIUtils.eRequestContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ContentType); // If the Content-Type is not set using Client Headers then it will be taken through ActWebAPIRest.Fields.ContentType - if (ContentType == null) + if (ContentTypeHeader == null) { - ContentType = GetRequestContentTypeText(requestContentType); + ContentTypeHeader = GetRequestContentTypeText(requestContentType); } - - if ((RequestMethod.ToString() == ApplicationAPIUtils.eRequestType.GET.ToString())) + if (RequestMethod.ToString() == nameof(ApplicationAPIUtils.eRequestType.GET)) { if (requestContentType == ApplicationAPIUtils.eRequestContentType.XwwwFormUrlEncoded) { @@ -756,7 +755,7 @@ private void SetRequestContent(HttpMethod RequestMethod) } else { - Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", ContentType); + Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", ContentTypeHeader); } } else @@ -806,17 +805,17 @@ private void SetRequestContent(HttpMethod RequestMethod) var lastIndexOfUtf8 = _byteOrderMarkUtf8.Length - 1; BodyString = BodyString.Remove(0, lastIndexOfUtf8); } - RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); + RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentTypeHeader); break; case ApplicationAPIUtils.eRequestContentType.JSonWithoutCharset: BodyString = GetRequestBodyString(); - RequestMessage.Content = new StringContent(BodyString, new MediaTypeHeaderValue(ContentType)); + RequestMessage.Content = new StringContent(BodyString, new MediaTypeHeaderValue(ContentTypeHeader)); break; case ApplicationAPIUtils.eRequestContentType.JSon: BodyString = GetRequestBodyString(); - RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); + RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentTypeHeader); break; default: @@ -837,22 +836,22 @@ private static string GetRequestContentTypeText(ApplicationAPIUtils.eRequestCont case ApplicationAPIUtils.eRequestContentType.FormData: return "multipart/form-data"; //update to correct value - + case ApplicationAPIUtils.eRequestContentType.TextPlain: return "text/plain; charset=utf-8"; - + case ApplicationAPIUtils.eRequestContentType.XML: return "application/xml"; - + case ApplicationAPIUtils.eRequestContentType.JSonWithoutCharset: return "application/json"; - + case ApplicationAPIUtils.eRequestContentType.PDF: return "application/pdf"; - + default: throw new InvalidOperationException($"Unsupported RequestBodyType: {eContentType}"); - } + } } private string GetRequestBodyString() @@ -907,23 +906,23 @@ private void SetCookies(HttpClientHandler handler) private void SetResponseContentType() { - if (Accept == null) + if (AcceptHeader == null) { ApplicationAPIUtils.eResponseContentType responseContentType = (ApplicationAPIUtils.eResponseContentType)mAct.GetInputParamCalculatedValue(ActWebAPIRest.Fields.ResponseContentType); Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(GetResponseContentTypeText(responseContentType))); } else { - if (Accept.Contains(',')) + if (AcceptHeader.Contains(',')) { - foreach (var acceptHeader in Accept.Split(',')) + foreach (var acceptHeader in AcceptHeader.Split(',')) { Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader.Trim())); } } else { - Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Accept.Trim())); + Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(AcceptHeader.Trim())); } } } @@ -983,7 +982,7 @@ private List> ConstructURLEncoded(ActWebAPIRest act return KeyValues; } - private bool RequestConstracotSOAP(ActWebAPISoap act) + private bool RequestConstructorSOAP(ActWebAPISoap act) { //Set default parameters for SOAP Actions RequestMessage = new HttpRequestMessage(HttpMethod.Post, Client.BaseAddress); @@ -996,11 +995,11 @@ private bool RequestConstracotSOAP(ActWebAPISoap act) if (ContetnTypeHeader != null) { - ContentType = ContetnTypeHeader.ValueForDriver; + ContentTypeHeader = ContetnTypeHeader.ValueForDriver; } else { - ContentType = "text/xml"; + ContentTypeHeader = "text/xml"; } string RequestBodyType = mAct.GetInputParamCalculatedValue(ActWebAPIBase.Fields.RequestBodyTypeRadioButton); @@ -1040,7 +1039,7 @@ private bool RequestConstracotSOAP(ActWebAPISoap act) Reporter.ToLog(eLogLevel.DEBUG, "RequestBody: " + BodyString); - RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentType); + RequestMessage.Content = new StringContent(BodyString, Encoding.UTF8, ContentTypeHeader); return true; } From 89f35236c1a36eb868a20381bd1e94268d16b27b Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 16:49:59 +0530 Subject: [PATCH 09/19] Refactor SeleniumDriver.cs for readability and performance Improved code readability, maintainability, and performance by: - Using StringComparison for case-insensitive checks - Converting instance methods to static where applicable - Replacing if-else statements with switch expressions - Simplifying proxy and URL handling - Enhancing element handling and JavaScript execution - Removing unused code and redundant initializations - Adding detailed and consistent logging - Using shorthand syntax for array initializations - Clarifying file operations with FileStream --- .../Web/Selenium/SeleniumDriver.cs | 458 +++++++----------- 1 file changed, 171 insertions(+), 287 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 6342212105..b8fa1bbcd3 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -717,7 +717,6 @@ public override void StartDriver() #endregion - #region EDGE case eBrowserType.Edge: if (OpenIEModeInEdge) @@ -1103,7 +1102,7 @@ private void configChromeDriverAndStart(ChromeOptions options) catch (Exception ex) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory")) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.Contains("no such file or directory", StringComparison.CurrentCultureIgnoreCase)) { Reporter.ToLog(eLogLevel.ERROR, "Error while launching chromedriver", ex); Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium..."); @@ -1148,7 +1147,7 @@ private void AddCustomDriverPath(DriverService driverService) } } } - private bool GetIsRunningInDocker() + private static bool GetIsRunningInDocker() { var env = System.Environment.GetEnvironmentVariable("GINGER_EXE_ENV"); return env == "docker"; @@ -1161,21 +1160,17 @@ private string UpdateDriver(eBrowserType browserType) Reporter.ToLog(eLogLevel.INFO, $"Failed to Download latest {mBrowserType} driver. Attempting to Update {mBrowserType} driver to latest using System Proxy Settings...."); DriverOptions driverOptions = null; - if (mBrowserType == eBrowserType.Chrome) - { - driverOptions = new ChromeOptions(); - } - else if (mBrowserType == eBrowserType.Edge) + driverOptions = mBrowserType switch { - driverOptions = new EdgeOptions(); - } - else if (mBrowserType == eBrowserType.FireFox) - { - driverOptions = new FirefoxOptions(); - } - else + eBrowserType.Chrome => new ChromeOptions(), + eBrowserType.Edge => new EdgeOptions(), + eBrowserType.FireFox => new FirefoxOptions(), + _ => null + }; + + if (driverOptions == null) { - //Other browsers not supported, return without update + // Other browsers not supported, return without update return ""; } @@ -1261,7 +1256,7 @@ public string GetDriversPathPerOS() } else { - string error = string.Format("The '{0}' OS is not supported by Ginger Selenium", RuntimeInformation.OSDescription); + Reporter.ToLog(eLogLevel.ERROR, string.Format("The '{0}' OS is not supported by Ginger Selenium", RuntimeInformation.OSDescription)); return null; } } @@ -1282,7 +1277,7 @@ private string DriverServiceFileNameWithPath(string fileName) /// /// driver name /// - private string DriverServiceFileName(string fileName) + private static string DriverServiceFileName(string fileName) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -1309,13 +1304,10 @@ private void SetProxy(dynamic options) if (mProxy == null) { return; - - } var proxy = new Proxy(); - options.Proxy = proxy; switch (mProxy.Kind) @@ -1345,17 +1337,14 @@ private void SetProxy(dynamic options) case ProxyKind.AutoDetect: options.Proxy.Kind = ProxyKind.AutoDetect; - break; case ProxyKind.System: options.Proxy.Kind = ProxyKind.System; - break; default: options.Proxy.Kind = ProxyKind.System; - break; } } @@ -1585,7 +1574,7 @@ private void GotoURL(Act act, string sURL) return; } - if (sURL.ToLower().StartsWith("www")) + if (sURL.StartsWith("www", StringComparison.CurrentCultureIgnoreCase)) { sURL = "http://" + sURL; } @@ -1697,181 +1686,145 @@ public override void RunAction(Act act) private void DoRunAction(Act act) { - Type ActType = act.GetType(); - //find Act handler, code is more readable than if/else... + // Get the type of the act + Type actType = act.GetType(); - if (ActType == typeof(ActUIElement)) + // Use switch expression based on the type of act + switch (act) { - HandleActUIElement((ActUIElement)act); - return; - } + case ActUIElement uiElement: + HandleActUIElement(uiElement); + break; - if (ActType == typeof(ActGotoURL)) - { - GotoURL((ActGotoURL)act, act.GetInputParamCalculatedValue("Value")); - return; - } - if (ActType == typeof(ActGenElement)) - { - GenElementHandler((ActGenElement)act); - return; - } - if (ActType == typeof(ActSmartSync)) - { - SmartSyncHandler((ActSmartSync)act); - return; - } - if (ActType == typeof(ActWebSmartSync)) - { - WebSmartSyncHandler((ActWebSmartSync)act); - return; - } - if (ActType == typeof(ActTextBox)) - { - ActTextBoxHandler((ActTextBox)act); - return; - } - if (ActType == typeof(ActPWL)) - { - PWLElementHandler((ActPWL)act); - return; - } - if (ActType == typeof(ActHandleBrowserAlert)) - { - HandleBrowserAlert((ActHandleBrowserAlert)act); - return; - } - if (ActType == typeof(ActVisualTesting)) - { - HandleActVisualTesting((ActVisualTesting)act); - return; - } + case ActGotoURL gotoUrl: + GotoURL(gotoUrl, act.GetInputParamCalculatedValue("Value")); + break; - //TODO: please create small function for each Act + case ActGenElement genElement: + GenElementHandler(genElement); + break; - if (ActType == typeof(ActPassword)) - { - ActPasswordHandler((ActPassword)act); - return; - } + case ActSmartSync smartSync: + SmartSyncHandler(smartSync); + break; - if (ActType == typeof(ActLink)) - { - ActLinkHandler((ActLink)act); - return; - } + case ActWebSmartSync webSmartSync: + WebSmartSyncHandler(webSmartSync); + break; - if (ActType == typeof(ActButton)) - { - ActButtonHandler((ActButton)act); - return; - } + case ActTextBox textBox: + ActTextBoxHandler(textBox); + break; - if (ActType == typeof(ActCheckbox)) - { - ActCheckboxHandler((ActCheckbox)act); - return; - } + case ActPWL pwl: + PWLElementHandler(pwl); + break; - if (ActType == typeof(ActDropDownList)) - { - ActDropDownListHandler((ActDropDownList)act); - return; - } + case ActHandleBrowserAlert handleBrowserAlert: + HandleBrowserAlert(handleBrowserAlert); + break; - if (ActType == typeof(ActRadioButton)) - { - ActRadioButtonHandler((ActRadioButton)act); - return; - } + case ActVisualTesting visualTesting: + HandleActVisualTesting(visualTesting); + break; - if (ActType == typeof(ActMultiselectList)) - { - ActMultiselectList el = (ActMultiselectList)act; - string csv = act.GetInputParamValue("Value"); string[] parts = csv.Split('|'); //TODO: make sure the values passed are separated by '|' - List optionList = new List(parts); - switch (el.ActMultiselectListAction) - { - case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByIndex: - SelectMultiselectListOptionsByIndex(el, optionList.ConvertAll(s => Int32.Parse(s))); // list has to get converted to list - break; - case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByText: - SelectMultiselectListOptionsByText(el, optionList); - break; - case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByValue: - SelectMultiselectListOptionsByValue(el, optionList); - break; - case ActMultiselectList.eActMultiselectListAction.ClearAllSelectedValues: - DeSelectMultiselectListOptions(el); - break; - } + case ActPassword password: + ActPasswordHandler(password); + break; - return; - } + case ActLink link: + ActLinkHandler(link); + break; + case ActButton button: + ActButtonHandler(button); + break; - if (ActType == typeof(ActHello)) - { - //TODO: return hellow from... - return; - } + case ActCheckbox checkbox: + ActCheckboxHandler(checkbox); + break; - if (ActType == typeof(ActScreenShot)) - { - ScreenshotHandler((ActScreenShot)act); - return; - } + case ActDropDownList dropdown: + ActDropDownListHandler(dropdown); + break; - if (ActType == typeof(ActSubmit)) - { - ActsubmitHandler((ActSubmit)act); - return; - } + case ActRadioButton radioButton: + ActRadioButtonHandler(radioButton); + break; - if (ActType == typeof(ActLabel)) - { - ActLabelHandler((ActLabel)act); - return; - } + case ActMultiselectList multiselectList: + string csv = act.GetInputParamValue("Value"); + string[] parts = csv.Split('|'); // Make sure values are separated by '|' + List optionList = [.. parts]; - if (ActType == typeof(ActWebSitePerformanceTiming)) - { - ActWebSitePerformanceTiming ABPT = (ActWebSitePerformanceTiming)act; - ActWebSitePerformanceTimingHandler(ABPT); - return; - } + switch (multiselectList.ActMultiselectListAction) + { + case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByIndex: + SelectMultiselectListOptionsByIndex(multiselectList, optionList.ConvertAll(int.Parse)); + break; - if (ActType == typeof(ActSwitchWindow)) - { - ActSwitchWindowHandler((ActSwitchWindow)act); - return; - } + case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByText: + SelectMultiselectListOptionsByText(multiselectList, optionList); + break; - if (ActType == typeof(ActBrowserElement)) - { - ActBrowserElementHandler((ActBrowserElement)act); - return; - } + case ActMultiselectList.eActMultiselectListAction.SetSelectedValueByValue: + SelectMultiselectListOptionsByValue(multiselectList, optionList); + break; - if (ActType == typeof(ActAgentManipulation)) - { - ActAgentManipulationHandler((ActAgentManipulation)act); - return; - } - if (act is ActAccessibilityTesting actAccessibilityTesting) - { - ActAccessibility(actAccessibilityTesting); - return; + case ActMultiselectList.eActMultiselectListAction.ClearAllSelectedValues: + DeSelectMultiselectListOptions(multiselectList); + break; + } + break; + + case ActHello hello: + // TODO: return hello from... + break; + + case ActScreenShot screenShot: + ScreenshotHandler(screenShot); + break; + + case ActSubmit submit: + ActsubmitHandler(submit); + break; + + case ActLabel label: + ActLabelHandler(label); + break; + + case ActWebSitePerformanceTiming websitePerformanceTiming: + ActWebSitePerformanceTimingHandler(websitePerformanceTiming); + break; + + case ActSwitchWindow switchWindow: + ActSwitchWindowHandler(switchWindow); + break; + + case ActBrowserElement browserElement: + ActBrowserElementHandler(browserElement); + break; + + case ActAgentManipulation agentManipulation: + ActAgentManipulationHandler(agentManipulation); + break; + + case ActAccessibilityTesting accessibilityTesting: + ActAccessibility(accessibilityTesting); + break; + + default: + act.Error = "Run Action Failed due to unrecognized action type - " + actType.ToString(); + act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; + break; } - act.Error = "Run Action Failed due to unrecognized action type - " + ActType.ToString(); - act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; } private void ActAccessibility(ActAccessibilityTesting act) { string gotoUrl = string.Empty; IWebElement e = null; - if ((act.GetInputParamValue(ActAccessibilityTesting.Fields.Target) == ActAccessibilityTesting.eTarget.Element.ToString())) + if (act.GetInputParamValue(ActAccessibilityTesting.Fields.Target) == nameof(ActAccessibilityTesting.eTarget.Element)) { if (!string.IsNullOrEmpty(act.LocateValueCalculated) && act.LocateBy != eLocateBy.NA) { @@ -5948,11 +5901,11 @@ private ElementInfo GetRootElement() private void SwitchFrameFromCurrent(ElementInfo ElementInfo) { - string[] spliter = new string[] { "/" }; + string[] spliter = ["/"]; string[] elementsTypesPath = ElementInfo.XPath.Split(spliter, StringSplitOptions.RemoveEmptyEntries); string elementType = elementsTypesPath[^1]; - int index = elementType.IndexOf("["); + int index = elementType.IndexOf('['); if (index != -1) { elementType = elementType[..index]; @@ -5987,7 +5940,7 @@ private void SwitchFrameFromCurrent(ElementInfo ElementInfo) private void SwitchAllFramePathes(ElementInfo ElementInfo) { - string[] spliter = new string[] { "," }; + string[] spliter = [","]; string[] iframesPathes = ElementInfo.Path.Split(spliter, StringSplitOptions.RemoveEmptyEntries); foreach (string iframePath in iframesPathes) { @@ -6020,12 +5973,12 @@ List IWindowExplorer.GetElementChildren(ElementInfo ElementInfo) private string GeneratePath(string xpath) { - string[] spliter = new string[] { "/" }; + string[] spliter = [","]; string[] elementsTypesPath = xpath.Split(spliter, StringSplitOptions.RemoveEmptyEntries); string elementType = elementsTypesPath[^1]; string path = string.Empty; - int index = elementType.IndexOf("["); + int index = elementType.IndexOf('['); if (index != -1) { elementType = elementType[..index]; @@ -6048,15 +6001,15 @@ private void SwitchFrame(string path, string xpath, bool otherThenGetElementChil string elementType = string.Empty; if (!string.IsNullOrEmpty(xpath)) { - string[] xpathSpliter = new string[] { "/" }; + string[] xpathSpliter = [","]; string[] elementsTypesPath = xpath.Split(xpathSpliter, StringSplitOptions.RemoveEmptyEntries); - if (!elementsTypesPath.Any()) + if (elementsTypesPath.Length == 0) { return; } elementType = elementsTypesPath[^1]; - int index = elementType.IndexOf("["); + int index = elementType.IndexOf('['); if (index != -1) { elementType = elementType[..index]; @@ -6071,7 +6024,7 @@ private void SwitchFrame(string path, string xpath, bool otherThenGetElementChil if (path != null) { - string[] spliter = new string[] { "," }; + string[] spliter = [","]; string[] iframesPathes = path.Split(spliter, StringSplitOptions.RemoveEmptyEntries); foreach (string iframePath in iframesPathes) { @@ -6190,11 +6143,11 @@ private string GenerateElementID(object EL) private string GenetratePath(string path, string xpath, string tagName) { - string[] spliter = new string[] { "/" }; + string[] spliter = ["/"]; string[] elementsTypesPath = xpath.Split(spliter, StringSplitOptions.RemoveEmptyEntries); string elementType = elementsTypesPath[^1]; - int index = elementType.IndexOf("["); + int index = elementType.IndexOf('['); if (index != -1) { elementType = elementType[..index]; @@ -6219,11 +6172,11 @@ private string GenetratePath(string path, string xpath, string tagName) private string GenerateXpath(string path, string xpath, string tagName, int id, int totalSameTags) { - string[] spliter = new string[] { "/" }; + string[] spliter = ["/"]; string[] elementsTypesPath = xpath.Split(spliter, StringSplitOptions.RemoveEmptyEntries); string elementType = elementsTypesPath[^1]; - int index = elementType.IndexOf("["); + int index = elementType.IndexOf('['); if (index != -1) { elementType = elementType[..index]; @@ -6247,7 +6200,7 @@ private string GenerateElementTitle(IWebElement EL) string id = EL.GetAttribute("id"); string value = EL.GetAttribute("value"); - if (tagName.ToUpper() == "TABLE") + if (tagName.Equals("TABLE", StringComparison.CurrentCultureIgnoreCase)) { return "Table"; } @@ -6423,9 +6376,9 @@ private void HighlightElement(ElementInfo ElementInfo, bool locateElementByItLoc { ElementInfo.XPath = GenerateXpathForIWebElement((IWebElement)ElementInfo.ElementObject, ""); } - if (ElementInfo is HTMLElementInfo && string.IsNullOrEmpty(((HTMLElementInfo)ElementInfo).RelXpath)) + if (ElementInfo is HTMLElementInfo htmlElementInfo && string.IsNullOrEmpty(htmlElementInfo.RelXpath)) { - ((HTMLElementInfo)ElementInfo).RelXpath = mXPathHelper.GetElementRelXPath(ElementInfo); + htmlElementInfo.RelXpath = mXPathHelper.GetElementRelXPath(ElementInfo); } if (!string.IsNullOrEmpty(ElementInfo.XPath)) { @@ -6504,7 +6457,7 @@ public void UnhighlightLast() IJavaScriptExecutor javascriptDriver = (IJavaScriptExecutor)Driver; foreach (string attribuet in attributesList) { - javascriptDriver.ExecuteScript(attribuet, new object[] { LastHighLightedElement }); + javascriptDriver.ExecuteScript(attribuet, [LastHighLightedElement]); } } } @@ -7162,7 +7115,7 @@ private string TakeElementScreenShot(IWebElement element) byte[] byteImage; using (MemoryStream ms = new MemoryStream()) { - image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); + image.Save(ms, format: System.Drawing.Imaging.ImageFormat.Png); byteImage = ms.ToArray(); } return Convert.ToBase64String(byteImage); @@ -7481,42 +7434,6 @@ void AddJavaScriptToPage(string script) } } - /* void CheckifPageLoaded() - { - //TODO: slow function, try to check alternatives or let the user config wait for - try - { - bool DomElementIncreasing = true; - int CurrentDomElementSize = 0; - int SameSizzeCounter = 0; - while (DomElementIncreasing) - { - Thread.Sleep(300); - - int instanceSize = Driver.FindElements(By.CssSelector("*")).Count; - - if (instanceSize > CurrentDomElementSize) - { - CurrentDomElementSize = instanceSize; - SameSizzeCounter = 0; - continue; - } - else - { - SameSizzeCounter++; - if (SameSizzeCounter == 5) - { - DomElementIncreasing = false; - } - } - } - } - catch - { - // Do nothing... - } - } - */ void CheckifPageLoaded() { WebDriverWait webDriverWait = new WebDriverWait(Driver, TimeSpan.FromSeconds(ImplicitWait)); @@ -7528,10 +7445,9 @@ void CheckifPageLoaded() return ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete") && IsJqueryCompleted; }); - } - String GetInjectJSSCript(string script) + string GetInjectJSSCript(string script) { string ScriptMin = JavaScriptHandler.MinifyJavaScript(script); // Get the Inject code @@ -8054,16 +7970,13 @@ public void HandleBrowserAlert(ActHandleBrowserAlert act) case ActHandleBrowserAlert.eHandleBrowseAlert.AcceptAlertBox: try { - Driver.SwitchTo().Alert().Accept(); - } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting Alert Box - " + e.Message); return; } - break; case ActHandleBrowserAlert.eHandleBrowseAlert.DismissAlertBox: @@ -8098,7 +8011,6 @@ public void HandleBrowserAlert(ActHandleBrowserAlert act) case ActHandleBrowserAlert.eHandleBrowseAlert.SendKeysAlertBox: try { - Driver.SwitchTo().Alert().SendKeys(act.GetInputParamCalculatedValue("Value")); } catch (Exception e) @@ -8120,17 +8032,17 @@ private void SwitchWindow(Act act) St.Reset(); int waitTime = this.ImplicitWait; - if (act is ActSwitchWindow) + if (act is ActSwitchWindow actSwitchWindow) { - if (((ActSwitchWindow)act).WaitTime >= 0) + if (actSwitchWindow.WaitTime >= 0) { - waitTime = ((ActSwitchWindow)act).WaitTime; + waitTime = actSwitchWindow.WaitTime; } } - else if (act is ActUIElement) + else if (act is ActUIElement actUiElement) { // adding to support actuielement switch window action synctime - var syncTime = Convert.ToInt32(((ActUIElement)act).GetInputParamCalculatedValue(ActUIElement.Fields.SyncTime)); + var syncTime = Convert.ToInt32(actUiElement.GetInputParamCalculatedValue(ActUIElement.Fields.SyncTime)); if (syncTime >= 0) { waitTime = syncTime; @@ -8340,7 +8252,7 @@ private void HandleSwitchFrame(Act act) } else if (!string.IsNullOrEmpty(act.GetInputParamCalculatedValue("Value"))) { - if (act.GetInputParamCalculatedValue("Value").Trim().ToUpper() != "DEFAULT") + if (!act.GetInputParamCalculatedValue("Value").Trim().Equals("DEFAULT", StringComparison.CurrentCultureIgnoreCase)) { Driver.SwitchTo().Frame(act.GetInputParamCalculatedValue("Value")); return; @@ -8409,7 +8321,6 @@ public async void ActBrowserElementHandler(ActBrowserElement act) { Reporter.ToLog(eLogLevel.ERROR, ex.Message); } - break; case ActBrowserElement.eControlAction.OpenURLNewTab: @@ -8458,7 +8369,6 @@ public async void ActBrowserElementHandler(ActBrowserElement act) act.Error += ex.Message; Reporter.ToLog(eLogLevel.DEBUG, $"OpenNewTab {ex.Message} ", ex.InnerException); } - break; case ActBrowserElement.eControlAction.GotoURL: @@ -8497,7 +8407,7 @@ public async void ActBrowserElementHandler(ActBrowserElement act) return; } - if ((act.GetInputParamValue(ActBrowserElement.Fields.GotoURLType) == ActBrowserElement.eGotoURLType.NewTab.ToString())) + if (act.GetInputParamValue(ActBrowserElement.Fields.GotoURLType) == nameof(ActBrowserElement.eGotoURLType.NewTab)) { try { @@ -8511,7 +8421,7 @@ public async void ActBrowserElementHandler(ActBrowserElement act) } } - else if ((act.GetInputParamValue(ActBrowserElement.Fields.GotoURLType) == ActBrowserElement.eGotoURLType.NewWindow.ToString())) + else if (act.GetInputParamValue(ActBrowserElement.Fields.GotoURLType) == nameof(ActBrowserElement.eGotoURLType.NewWindow)) { try { @@ -8594,7 +8504,7 @@ public async void ActBrowserElementHandler(ActBrowserElement act) try { object a = null; - if (!script.ToUpper().StartsWith("RETURN")) + if (!script.StartsWith("RETURN", StringComparison.CurrentCultureIgnoreCase)) { script = "return " + script; } @@ -8645,11 +8555,8 @@ public async void ActBrowserElementHandler(ActBrowserElement act) } } } - } - } - break; case ActBrowserElement.eControlAction.GetConsoleLog: string logs = Newtonsoft.Json.JsonConvert.SerializeObject(Driver.Manage().Logs.GetLog(OpenQA.Selenium.LogType.Browser)); @@ -8754,7 +8661,6 @@ public async void ActBrowserElementHandler(ActBrowserElement act) act.Error += ex.Message; Reporter.ToLog(eLogLevel.DEBUG, $"ActBrowserElementHandler {ex.Message} ", ex.InnerException); } - } private void OpenNewWindow() @@ -9455,16 +9361,14 @@ public bool ClickAndValidteHandler(ActUIElement act) { IWebElement clickElement = LocateElement(act); - ActUIElement.eElementAction clickType; - if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ClickType).ToString(), out clickType) == false) + if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ClickType).ToString(), out var clickType) == false) { act.Error = "Unknown Click Type"; return false; } // Validation Element locate by: - eLocateBy validationElementLocateby; - if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ValidationElementLocateBy).ToString(), out validationElementLocateby) == false) + if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ValidationElementLocateBy).ToString(), out var validationElementLocateby) == false) { act.Error = "Unknown Validation Element Locate By"; return false; @@ -9474,8 +9378,7 @@ public bool ClickAndValidteHandler(ActUIElement act) string validationElementLocatorValue = act.GetInputParamValue(ActUIElement.Fields.ValidationElementLocatorValue.ToString()); //Validation Type: - ActUIElement.eElementAction validationType; - if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ValidationType).ToString(), out validationType) == false) + if (Enum.TryParse(act.GetInputParamValue(ActUIElement.Fields.ValidationType).ToString(), out var validationType) == false) { act.Error = "Unknown Validation Type"; return false; @@ -10105,14 +10008,11 @@ ElementInfo IXPath.GetElementParent(ElementInfo ElementInfo, PomSetting pomSetti if (((HTMLElementInfo)ElementInfo).HTMLElementObject != null) { parentElementHtmlNode = ((HTMLElementInfo)ElementInfo).HTMLElementObject.ParentNode; - parentEI = allReadElem.Find(el => el is HTMLElementInfo && ((HTMLElementInfo)el).HTMLElementObject != null && ((HTMLElementInfo)el).HTMLElementObject.Equals(parentElementHtmlNode)); + parentEI = allReadElem.Find(el => el is HTMLElementInfo parentElementInfo && parentElementInfo.HTMLElementObject != null && parentElementInfo.HTMLElementObject.Equals(parentElementHtmlNode)); } else { - if (ElementInfo.ElementObject == null) - { - ElementInfo.ElementObject = Driver.FindElement(By.XPath(ElementInfo.XPath)); - } + ElementInfo.ElementObject ??= Driver.FindElement(By.XPath(ElementInfo.XPath)); parentElementIWebElement = ((IWebElement)ElementInfo.ElementObject).FindElement(By.XPath("..")); parentEI = allReadElem.Find(el => el.ElementObject != null && el.ElementObject.Equals(parentElementIWebElement)); @@ -10153,9 +10053,9 @@ string IXPath.GetElementTagName(ElementInfo EI) { return ((IWebElement)EI.ElementObject).TagName; } - else if (EI is HTMLElementInfo && ((HTMLElementInfo)EI).HTMLElementObject != null) + else if (EI is HTMLElementInfo info && info.HTMLElementObject != null) { - return (((HTMLElementInfo)EI).HTMLElementObject).Name; + return info.HTMLElementObject.Name; } return string.Empty; } @@ -10198,10 +10098,7 @@ string IXPath.GetElementProperty(ElementInfo ElementInfo, string PropertyName) { string elementProperty = null; - if (ElementInfo.ElementObject == null) - { - ElementInfo.ElementObject = Driver.FindElement(By.XPath(ElementInfo.XPath)); - } + ElementInfo.ElementObject ??= Driver.FindElement(By.XPath(ElementInfo.XPath)); if (ElementInfo.ElementObject != null) { @@ -10261,7 +10158,6 @@ private ElementInfo FindFirst(ElementInfo ElementInfo, List IXPath.FindAll(ElementInfo ElementInfo, List conditions) { CurrentFrame = string.Empty; - List list = []; - list = FindAll(ElementInfo, conditions); + List list = FindAll(ElementInfo, conditions); Driver.SwitchTo().DefaultContent(); CurrentFrame = string.Empty; return list; @@ -10345,8 +10240,8 @@ private List FindAll(ElementInfo ElementInfo, List FindAll(ElementInfo ElementInfo, List FindAll(ElementInfo ElementInfo, List($"RequestUrl: {e.RequestUrl}", JsonConvert.SerializeObject(e, Formatting.Indented))); } - } catch (Exception ex) { @@ -11137,7 +11021,7 @@ private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEve if (_BrowserHelper.ShouldMonitorAllUrls() || _BrowserHelper.ShouldMonitorUrl(e.ResponseUrl)) { - if (mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == ActBrowserElement.eRequestTypes.FetchOrXHR.ToString()) + if (mAct.GetOrCreateInputParam(nameof(ActBrowserElement.eRequestTypes)).Value == nameof(ActBrowserElement.eRequestTypes.FetchOrXHR)) { if (e.ResponseResourceType.Equals("XHR", StringComparison.CurrentCultureIgnoreCase) || e.ResponseResourceType.Equals("FETCH", StringComparison.CurrentCultureIgnoreCase)) { From 52d5a40c56ff8ebcea1e456ee0f035ed4b599e00 Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 17:09:24 +0530 Subject: [PATCH 10/19] Updated System.Data.SqlClient to 4.9.0 --- Ginger/Ginger/Ginger.csproj | 2 +- Ginger/GingerConsoleTest/GingerConsoleTest.csproj | 1 + Ginger/GingerControls/GingerControls.csproj | 1 + Ginger/GingerCore/GingerCore.csproj | 1 + Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj | 1 + Ginger/GingerCoreNET/GingerCoreNET.csproj | 2 +- Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj | 1 + Ginger/GingerCoreTest/GingerCoreTest.csproj | 1 + Ginger/GingerHelper/GingerHelper.csproj | 1 + Ginger/GingerPlugIns/GingerPlugIns.csproj | 1 + Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj | 1 + Ginger/GingerRuntime/GingerRuntime.csproj | 1 + Ginger/GingerTest/GingerTest.csproj | 1 + Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj | 1 + .../GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj | 1 + 15 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index 654ccbffb6..d6f443ea9b 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -729,7 +729,7 @@ - + diff --git a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj index 1454875254..9f866c5799 100644 --- a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj +++ b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj @@ -18,6 +18,7 @@ + diff --git a/Ginger/GingerControls/GingerControls.csproj b/Ginger/GingerControls/GingerControls.csproj index fce024816c..2b9caa808d 100644 --- a/Ginger/GingerControls/GingerControls.csproj +++ b/Ginger/GingerControls/GingerControls.csproj @@ -14,6 +14,7 @@ all + diff --git a/Ginger/GingerCore/GingerCore.csproj b/Ginger/GingerCore/GingerCore.csproj index 47b9442ed4..8fbfa45070 100644 --- a/Ginger/GingerCore/GingerCore.csproj +++ b/Ginger/GingerCore/GingerCore.csproj @@ -550,6 +550,7 @@ + 8.0.7 diff --git a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj index 4ff57d4553..cdf5f48564 100644 --- a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj +++ b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj @@ -19,6 +19,7 @@ + diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 365a712782..6ffbd9c3f1 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -333,7 +333,7 @@ - + diff --git a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj index 6e3e0e17b7..5a39668524 100644 --- a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj +++ b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj @@ -96,6 +96,7 @@ + diff --git a/Ginger/GingerCoreTest/GingerCoreTest.csproj b/Ginger/GingerCoreTest/GingerCoreTest.csproj index 6870c75655..b6358daeeb 100644 --- a/Ginger/GingerCoreTest/GingerCoreTest.csproj +++ b/Ginger/GingerCoreTest/GingerCoreTest.csproj @@ -64,6 +64,7 @@ 2.1.2 + 8.0.0 diff --git a/Ginger/GingerHelper/GingerHelper.csproj b/Ginger/GingerHelper/GingerHelper.csproj index b4a8c6dd26..0945b6601f 100644 --- a/Ginger/GingerHelper/GingerHelper.csproj +++ b/Ginger/GingerHelper/GingerHelper.csproj @@ -26,5 +26,6 @@ all + \ No newline at end of file diff --git a/Ginger/GingerPlugIns/GingerPlugIns.csproj b/Ginger/GingerPlugIns/GingerPlugIns.csproj index a4fd554959..08a732d7d4 100644 --- a/Ginger/GingerPlugIns/GingerPlugIns.csproj +++ b/Ginger/GingerPlugIns/GingerPlugIns.csproj @@ -15,6 +15,7 @@ + all diff --git a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj index a11be9ca52..8ccb129cb2 100644 --- a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj +++ b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj @@ -11,6 +11,7 @@ + diff --git a/Ginger/GingerRuntime/GingerRuntime.csproj b/Ginger/GingerRuntime/GingerRuntime.csproj index 97be08313a..11e291b379 100644 --- a/Ginger/GingerRuntime/GingerRuntime.csproj +++ b/Ginger/GingerRuntime/GingerRuntime.csproj @@ -43,6 +43,7 @@ + diff --git a/Ginger/GingerTest/GingerTest.csproj b/Ginger/GingerTest/GingerTest.csproj index 0dde86a99c..6a9d5def51 100644 --- a/Ginger/GingerTest/GingerTest.csproj +++ b/Ginger/GingerTest/GingerTest.csproj @@ -25,6 +25,7 @@ + diff --git a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj index dc4b9fb3d8..241b93469f 100644 --- a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj +++ b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj @@ -23,5 +23,6 @@ all + \ No newline at end of file diff --git a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj index def9aeb895..3768bd9f0d 100644 --- a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj +++ b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj @@ -22,6 +22,7 @@ + From cc4d1acc842861ccb734b99493da841051c67334 Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 17:33:57 +0530 Subject: [PATCH 11/19] Upgraded below dependancies Microsoft.NETCore.App 2.1.30 System.IO.Packaging 9.0.1 System.Linq.Dynamic.Core 1.6.0.1 --- Ginger/Ginger/Ginger.csproj | 3 +++ Ginger/GingerAutoPilot/GingerAutoPilot.csproj | 1 + Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj | 1 + Ginger/GingerConsoleTest/GingerConsoleTest.csproj | 2 ++ Ginger/GingerControls/GingerControls.csproj | 1 + Ginger/GingerCore/GingerCore.csproj | 5 +++-- Ginger/GingerCoreCommon/GingerCoreCommon.csproj | 1 + Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj | 2 ++ Ginger/GingerCoreNET/GingerCoreNET.csproj | 2 ++ Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj | 2 ++ Ginger/GingerCoreTest/GingerCoreTest.csproj | 3 +++ Ginger/GingerHelper/GingerHelper.csproj | 1 + Ginger/GingerPlugIns/GingerPlugIns.csproj | 1 + Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj | 2 ++ Ginger/GingerRuntime/GingerRuntime.csproj | 2 ++ Ginger/GingerTest/GingerTest.csproj | 3 +++ Ginger/GingerUtilsTest/GingerUtilsTest.csproj | 1 + Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj | 2 ++ .../GingerWPFDriverWindowTest.csproj | 2 ++ 19 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index d6f443ea9b..c6515c5fa1 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -718,6 +718,7 @@ + @@ -731,6 +732,8 @@ + + diff --git a/Ginger/GingerAutoPilot/GingerAutoPilot.csproj b/Ginger/GingerAutoPilot/GingerAutoPilot.csproj index 110d20bbb2..a093404038 100644 --- a/Ginger/GingerAutoPilot/GingerAutoPilot.csproj +++ b/Ginger/GingerAutoPilot/GingerAutoPilot.csproj @@ -30,6 +30,7 @@ + diff --git a/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj b/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj index 819b307a77..c80d8a2e3d 100644 --- a/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj +++ b/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj @@ -25,6 +25,7 @@ + diff --git a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj index 9f866c5799..c346d424b1 100644 --- a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj +++ b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj @@ -16,9 +16,11 @@ + + diff --git a/Ginger/GingerControls/GingerControls.csproj b/Ginger/GingerControls/GingerControls.csproj index 2b9caa808d..8e4cf1866e 100644 --- a/Ginger/GingerControls/GingerControls.csproj +++ b/Ginger/GingerControls/GingerControls.csproj @@ -15,6 +15,7 @@ + diff --git a/Ginger/GingerCore/GingerCore.csproj b/Ginger/GingerCore/GingerCore.csproj index 8fbfa45070..b9dae13296 100644 --- a/Ginger/GingerCore/GingerCore.csproj +++ b/Ginger/GingerCore/GingerCore.csproj @@ -514,6 +514,7 @@ 3.1.7 + 7.0.4 @@ -558,10 +559,10 @@ 4.3.0 - 8.0.1 + 9.0.1 - 1.3.7 + 1.6.0.1 4.3.0 diff --git a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj index beeebc1422..45e1562e8d 100644 --- a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj +++ b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj @@ -42,6 +42,7 @@ + diff --git a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj index cdf5f48564..016a768979 100644 --- a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj +++ b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj @@ -17,9 +17,11 @@ + + diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 6ffbd9c3f1..1599592c24 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -311,6 +311,7 @@ + @@ -335,6 +336,7 @@ + diff --git a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj index 5a39668524..5378fab606 100644 --- a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj +++ b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj @@ -93,10 +93,12 @@ + + diff --git a/Ginger/GingerCoreTest/GingerCoreTest.csproj b/Ginger/GingerCoreTest/GingerCoreTest.csproj index b6358daeeb..2e410f829b 100644 --- a/Ginger/GingerCoreTest/GingerCoreTest.csproj +++ b/Ginger/GingerCoreTest/GingerCoreTest.csproj @@ -61,10 +61,13 @@ 2.0.15 + 2.1.2 + + 8.0.0 diff --git a/Ginger/GingerHelper/GingerHelper.csproj b/Ginger/GingerHelper/GingerHelper.csproj index 0945b6601f..1bd06e41e4 100644 --- a/Ginger/GingerHelper/GingerHelper.csproj +++ b/Ginger/GingerHelper/GingerHelper.csproj @@ -27,5 +27,6 @@ + \ No newline at end of file diff --git a/Ginger/GingerPlugIns/GingerPlugIns.csproj b/Ginger/GingerPlugIns/GingerPlugIns.csproj index 08a732d7d4..3662ce4c54 100644 --- a/Ginger/GingerPlugIns/GingerPlugIns.csproj +++ b/Ginger/GingerPlugIns/GingerPlugIns.csproj @@ -16,6 +16,7 @@ + all diff --git a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj index 8ccb129cb2..10f4439921 100644 --- a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj +++ b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj @@ -9,9 +9,11 @@ + + diff --git a/Ginger/GingerRuntime/GingerRuntime.csproj b/Ginger/GingerRuntime/GingerRuntime.csproj index 11e291b379..5a8335d0c6 100644 --- a/Ginger/GingerRuntime/GingerRuntime.csproj +++ b/Ginger/GingerRuntime/GingerRuntime.csproj @@ -41,9 +41,11 @@ + + diff --git a/Ginger/GingerTest/GingerTest.csproj b/Ginger/GingerTest/GingerTest.csproj index 6a9d5def51..db214b22e6 100644 --- a/Ginger/GingerTest/GingerTest.csproj +++ b/Ginger/GingerTest/GingerTest.csproj @@ -21,11 +21,14 @@ + + + diff --git a/Ginger/GingerUtilsTest/GingerUtilsTest.csproj b/Ginger/GingerUtilsTest/GingerUtilsTest.csproj index 5da2816898..be023b106a 100644 --- a/Ginger/GingerUtilsTest/GingerUtilsTest.csproj +++ b/Ginger/GingerUtilsTest/GingerUtilsTest.csproj @@ -11,6 +11,7 @@ + diff --git a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj index 241b93469f..33fd2fe902 100644 --- a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj +++ b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj @@ -18,11 +18,13 @@ + all + \ No newline at end of file diff --git a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj index 3768bd9f0d..ad913977ec 100644 --- a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj +++ b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj @@ -20,9 +20,11 @@ + + From bc8e91b997ce32e6d66f1974dcb20899faac709c Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 17:42:33 +0530 Subject: [PATCH 12/19] Updated below dependancies System.IdentityModel.Tokens.Jwt 8.3.1 System.Text.Json 9.0.1 --- Ginger/Ginger/Ginger.csproj | 2 ++ Ginger/GingerConsoleTest/GingerConsoleTest.csproj | 2 ++ Ginger/GingerCore/GingerCore.csproj | 2 ++ Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj | 2 ++ Ginger/GingerCoreNET/GingerCoreNET.csproj | 2 ++ Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj | 2 ++ Ginger/GingerCoreTest/GingerCoreTest.csproj | 2 ++ Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj | 2 ++ Ginger/GingerRuntime/GingerRuntime.csproj | 2 ++ Ginger/GingerTest/GingerTest.csproj | 2 ++ Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj | 2 ++ .../GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj | 2 ++ 12 files changed, 24 insertions(+) diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index c6515c5fa1..4225208034 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -732,9 +732,11 @@ + + diff --git a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj index c346d424b1..1ba47443e2 100644 --- a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj +++ b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj @@ -20,8 +20,10 @@ + + diff --git a/Ginger/GingerCore/GingerCore.csproj b/Ginger/GingerCore/GingerCore.csproj index b9dae13296..6db674aaf9 100644 --- a/Ginger/GingerCore/GingerCore.csproj +++ b/Ginger/GingerCore/GingerCore.csproj @@ -558,6 +558,7 @@ 4.3.0 + 9.0.1 @@ -577,6 +578,7 @@ 4.3.1 + 8.0.0 diff --git a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj index 016a768979..34172d0e75 100644 --- a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj +++ b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj @@ -21,8 +21,10 @@ + + diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 1599592c24..508817fe2b 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -336,10 +336,12 @@ + + diff --git a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj index 5378fab606..dde01c1cb9 100644 --- a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj +++ b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj @@ -98,8 +98,10 @@ + + diff --git a/Ginger/GingerCoreTest/GingerCoreTest.csproj b/Ginger/GingerCoreTest/GingerCoreTest.csproj index 2e410f829b..b7ccfbc078 100644 --- a/Ginger/GingerCoreTest/GingerCoreTest.csproj +++ b/Ginger/GingerCoreTest/GingerCoreTest.csproj @@ -66,6 +66,7 @@ 2.1.2 + @@ -75,6 +76,7 @@ all + diff --git a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj index 10f4439921..6dcea2047b 100644 --- a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj +++ b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj @@ -13,8 +13,10 @@ + + diff --git a/Ginger/GingerRuntime/GingerRuntime.csproj b/Ginger/GingerRuntime/GingerRuntime.csproj index 5a8335d0c6..36f05ce5e8 100644 --- a/Ginger/GingerRuntime/GingerRuntime.csproj +++ b/Ginger/GingerRuntime/GingerRuntime.csproj @@ -45,9 +45,11 @@ + + diff --git a/Ginger/GingerTest/GingerTest.csproj b/Ginger/GingerTest/GingerTest.csproj index db214b22e6..48c42ba220 100644 --- a/Ginger/GingerTest/GingerTest.csproj +++ b/Ginger/GingerTest/GingerTest.csproj @@ -27,8 +27,10 @@ + + diff --git a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj index 33fd2fe902..9de581341a 100644 --- a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj +++ b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj @@ -25,6 +25,8 @@ + + \ No newline at end of file diff --git a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj index ad913977ec..ea06c74949 100644 --- a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj +++ b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj @@ -24,6 +24,7 @@ + @@ -31,5 +32,6 @@ all + \ No newline at end of file From e04ffbbd7c1d53d009dd86592aa34f569b645033 Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 23:45:41 +0530 Subject: [PATCH 13/19] Updated below dependancies BouncyCastle.Cryptography 2.5.0 MimeKit 4.10.0 --- .../GingerOpsEnvWizardLib/AddGingerOpsEnvPage.xaml.cs | 2 +- Ginger/Ginger/Ginger.csproj | 3 ++- Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj | 2 +- Ginger/GingerConsoleTest/GingerConsoleTest.csproj | 1 + Ginger/GingerControls/GingerControls.csproj | 1 + Ginger/GingerCore/GingerCore.csproj | 4 ++++ Ginger/GingerCoreCommon/GingerCoreCommon.csproj | 1 + Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj | 6 ++++++ Ginger/GingerCoreNET/GingerCoreNET.csproj | 7 +++++++ Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj | 6 ++++++ Ginger/GingerCoreTest/GingerCoreTest.csproj | 6 ++++++ Ginger/GingerHelper/GingerHelper.csproj | 3 +++ Ginger/GingerPlugIns/GingerPlugIns.csproj | 3 +++ Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj | 6 ++++++ Ginger/GingerRuntime/GingerRuntime.csproj | 6 ++++++ Ginger/GingerTest/GingerTest.csproj | 6 ++++++ Ginger/GingerUtilsTest/GingerUtilsTest.csproj | 1 + Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj | 6 ++++++ .../GingerWPFDriverWindowTest.csproj | 6 ++++++ 19 files changed, 73 insertions(+), 3 deletions(-) diff --git a/Ginger/Ginger/Environments/GingerOpsEnvWizardLib/AddGingerOpsEnvPage.xaml.cs b/Ginger/Ginger/Environments/GingerOpsEnvWizardLib/AddGingerOpsEnvPage.xaml.cs index bf57e60a4c..99da78c07a 100644 --- a/Ginger/Ginger/Environments/GingerOpsEnvWizardLib/AddGingerOpsEnvPage.xaml.cs +++ b/Ginger/Ginger/Environments/GingerOpsEnvWizardLib/AddGingerOpsEnvPage.xaml.cs @@ -148,7 +148,7 @@ public async void xArchitectureComboBox_SelectionChanged(object sender, Selectio } - if (xEnvironmentComboBox.ItemsSource.IsNullOrEmpty()) + if (xEnvironmentComboBox.ItemsSource?.Count==0) { mWizard.mWizardWindow.NextButton(false); } diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index 4225208034..5a6ecf2854 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -720,7 +720,7 @@ - + @@ -732,6 +732,7 @@ + diff --git a/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj b/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj index c80d8a2e3d..b4562ed636 100644 --- a/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj +++ b/Ginger/GingerAutoPilotTest/GingerAutoPilotTest.csproj @@ -26,7 +26,7 @@ - + diff --git a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj index 1ba47443e2..e994b62eb6 100644 --- a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj +++ b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj @@ -20,6 +20,7 @@ + diff --git a/Ginger/GingerControls/GingerControls.csproj b/Ginger/GingerControls/GingerControls.csproj index 8e4cf1866e..039c600a7b 100644 --- a/Ginger/GingerControls/GingerControls.csproj +++ b/Ginger/GingerControls/GingerControls.csproj @@ -15,6 +15,7 @@ + diff --git a/Ginger/GingerCore/GingerCore.csproj b/Ginger/GingerCore/GingerCore.csproj index 6db674aaf9..fd373f6af2 100644 --- a/Ginger/GingerCore/GingerCore.csproj +++ b/Ginger/GingerCore/GingerCore.csproj @@ -518,6 +518,7 @@ 7.0.4 + 2.19.1 @@ -555,6 +556,7 @@ 8.0.7 + 4.3.0 @@ -578,7 +580,9 @@ 4.3.1 + + 8.0.0 diff --git a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj index 45e1562e8d..2b02f55476 100644 --- a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj +++ b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj @@ -44,6 +44,7 @@ + diff --git a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj index 34172d0e75..600ae35d81 100644 --- a/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj +++ b/Ginger/GingerCoreCommonTest/GingerCoreCommonTest.csproj @@ -15,16 +15,22 @@ + + + + + + diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 508817fe2b..1f266236e9 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -231,6 +231,8 @@ + + @@ -317,6 +319,7 @@ + @@ -331,17 +334,21 @@ + + + + diff --git a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj index dde01c1cb9..4f6dd12199 100644 --- a/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj +++ b/Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj @@ -87,6 +87,7 @@ + @@ -94,14 +95,19 @@ + + + + + diff --git a/Ginger/GingerCoreTest/GingerCoreTest.csproj b/Ginger/GingerCoreTest/GingerCoreTest.csproj index b7ccfbc078..c6ae3429ac 100644 --- a/Ginger/GingerCoreTest/GingerCoreTest.csproj +++ b/Ginger/GingerCoreTest/GingerCoreTest.csproj @@ -54,6 +54,7 @@ + 2.0.2 @@ -62,10 +63,13 @@ + 2.1.2 + + @@ -76,7 +80,9 @@ all + + diff --git a/Ginger/GingerHelper/GingerHelper.csproj b/Ginger/GingerHelper/GingerHelper.csproj index 1bd06e41e4..f19fd50215 100644 --- a/Ginger/GingerHelper/GingerHelper.csproj +++ b/Ginger/GingerHelper/GingerHelper.csproj @@ -20,6 +20,7 @@ + @@ -27,6 +28,8 @@ + + \ No newline at end of file diff --git a/Ginger/GingerPlugIns/GingerPlugIns.csproj b/Ginger/GingerPlugIns/GingerPlugIns.csproj index 3662ce4c54..20955828ca 100644 --- a/Ginger/GingerPlugIns/GingerPlugIns.csproj +++ b/Ginger/GingerPlugIns/GingerPlugIns.csproj @@ -13,14 +13,17 @@ AnyCPU + + all + \ No newline at end of file diff --git a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj index 6dcea2047b..61a1ba92a3 100644 --- a/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj +++ b/Ginger/GingerPluginCoreTest/GingerPluginCoreTest.csproj @@ -7,16 +7,22 @@ + + + + + + diff --git a/Ginger/GingerRuntime/GingerRuntime.csproj b/Ginger/GingerRuntime/GingerRuntime.csproj index 36f05ce5e8..c4286aa7f1 100644 --- a/Ginger/GingerRuntime/GingerRuntime.csproj +++ b/Ginger/GingerRuntime/GingerRuntime.csproj @@ -40,16 +40,22 @@ + + + + + + diff --git a/Ginger/GingerTest/GingerTest.csproj b/Ginger/GingerTest/GingerTest.csproj index 48c42ba220..fcd9c7491f 100644 --- a/Ginger/GingerTest/GingerTest.csproj +++ b/Ginger/GingerTest/GingerTest.csproj @@ -16,21 +16,27 @@ + + + + + + diff --git a/Ginger/GingerUtilsTest/GingerUtilsTest.csproj b/Ginger/GingerUtilsTest/GingerUtilsTest.csproj index be023b106a..650c7a7dba 100644 --- a/Ginger/GingerUtilsTest/GingerUtilsTest.csproj +++ b/Ginger/GingerUtilsTest/GingerUtilsTest.csproj @@ -13,6 +13,7 @@ + diff --git a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj index 9de581341a..fcc937c439 100644 --- a/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj +++ b/Ginger/GingerWPFDriverWindow/GingerWPFDriverWindow.csproj @@ -17,16 +17,22 @@ + + + all + + + \ No newline at end of file diff --git a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj index ea06c74949..d3597ce7b4 100644 --- a/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj +++ b/Ginger/GingerWPFDriverWindowTest/GingerWPFDriverWindowTest.csproj @@ -18,12 +18,16 @@ + + + + @@ -32,6 +36,8 @@ all + + \ No newline at end of file From 346afdb3e408d86abd70377e1818308d5c525df4 Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 29 Jan 2025 23:47:07 +0530 Subject: [PATCH 14/19] Updated dependancies --- Ginger/Ginger/Ginger.csproj | 1 + Ginger/GingerConsoleTest/GingerConsoleTest.csproj | 1 + Ginger/GingerControls/GingerControls.csproj | 1 + Ginger/GingerHelper/GingerHelper.csproj | 2 +- Ginger/GingerPlugIns/GingerPlugIns.csproj | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index 5a6ecf2854..850b1a2cf7 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -737,6 +737,7 @@ + diff --git a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj index e994b62eb6..ce8ec4a32d 100644 --- a/Ginger/GingerConsoleTest/GingerConsoleTest.csproj +++ b/Ginger/GingerConsoleTest/GingerConsoleTest.csproj @@ -24,6 +24,7 @@ + diff --git a/Ginger/GingerControls/GingerControls.csproj b/Ginger/GingerControls/GingerControls.csproj index 039c600a7b..465e344dbc 100644 --- a/Ginger/GingerControls/GingerControls.csproj +++ b/Ginger/GingerControls/GingerControls.csproj @@ -20,6 +20,7 @@ + diff --git a/Ginger/GingerHelper/GingerHelper.csproj b/Ginger/GingerHelper/GingerHelper.csproj index f19fd50215..10c9f0b929 100644 --- a/Ginger/GingerHelper/GingerHelper.csproj +++ b/Ginger/GingerHelper/GingerHelper.csproj @@ -30,6 +30,6 @@ - + \ No newline at end of file diff --git a/Ginger/GingerPlugIns/GingerPlugIns.csproj b/Ginger/GingerPlugIns/GingerPlugIns.csproj index 20955828ca..1282ba1f38 100644 --- a/Ginger/GingerPlugIns/GingerPlugIns.csproj +++ b/Ginger/GingerPlugIns/GingerPlugIns.csproj @@ -24,6 +24,6 @@ all - + \ No newline at end of file From 12b1d2546b786a90a657eaed42d88d5aae6bf5cf Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Thu, 30 Jan 2025 16:16:26 +0530 Subject: [PATCH 15/19] suggested changes --- .../GingerCoreCommon/UIElement/ElementInfo.cs | 2 - .../ActionHandlers/ActWebSmartSyncHandler.cs | 36 ++++++++++------ .../Playwright/PlaywrightBrowserElement.cs | 43 +++++++++++++------ .../Web/Playwright/PlaywrightBrowserTab.cs | 33 ++++++++------ 4 files changed, 72 insertions(+), 42 deletions(-) diff --git a/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs b/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs index 0e7aeed609..36958ee702 100644 --- a/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs +++ b/Ginger/GingerCoreCommon/UIElement/ElementInfo.cs @@ -549,8 +549,6 @@ public enum eLocateBy ByCSS, [EnumValueDescription("By XPath")] ByXPath, - [EnumValueDescription("By Attribute")] - ByAttribute, [EnumValueDescription("By Relative XPath")] ByRelXPath, [EnumValueDescription("By X,Y")] diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs index f9e24cbccf..f8fda10cb8 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs @@ -1,21 +1,28 @@ -using DocumentFormat.OpenXml.Drawing.Charts; -using GingerCore; +#region License +/* +Copyright © 2014-2024 European Support Limited + +Licensed under the Apache License, Version 2.0 (the "License") +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#endregion + +using Amdocs.Ginger.Common; using GingerCore.Actions; -using GingerCore.Actions.Common; -using Microsoft.Graph; -using Microsoft.Playwright; -using Microsoft.VisualStudio.Services.WebApi; -using OpenQA.Selenium; -using OpenQA.Selenium.Common; -using OpenQA.Selenium.Support.UI; using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; -using System.Threading; using System.Threading.Tasks; namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.ActionHandlers @@ -114,7 +121,8 @@ public async Task HandleAsync(Act act, float waitUntilTimeout) } catch (Exception ex) { - act.Error = ex.Message + ex.InnerException; + Reporter.ToLog(eLogLevel.DEBUG,$"Error in operation {_actWebSmartSync.SyncOperations}: {ex.Message} {ex.InnerException?.Message}"); + act.Error = ex.Message + ex.InnerException?.Message; } } @@ -359,7 +367,7 @@ private async Task GetFirstMatchingElementAsync() IBrowserElement? firstElement = elements.FirstOrDefault(); if (firstElement == null) { - throw new InvalidDataException("No matching element found."); + throw new InvalidDataException($"Element not found by:{_actWebSmartSync.ElementLocateBy} {_actWebSmartSync.ElementLocateValue}"); } return firstElement; } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs index 4026ab1727..a8d8389efe 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs @@ -16,6 +16,7 @@ limitations under the License. */ #endregion +using Amdocs.Ginger.Common; using Deque.AxeCore.Commons; using Deque.AxeCore.Playwright; using Microsoft.Playwright; @@ -1068,8 +1069,11 @@ public async Task ToBeVisibleAsync(IPlaywrightLocator playwrightLocator, f await Assertions.Expect(playwrightLocator).ToBeVisibleAsync(options); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, $"Error in Element To Be Visible: {ex.Message}"); + return false; + } } /// @@ -1096,8 +1100,11 @@ public async Task ElementIsSelectedAsync(IPlaywrightLocator playwrightLoca await Assertions.Expect(playwrightLocator).ToBeCheckedAsync(options); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, $"Error in Element To Be Checked: {ex.Message}"); + return false; + } } /// @@ -1125,8 +1132,11 @@ public async Task ElementToBeClickableAsync(IPlaywrightLocator playwrightL await Assertions.Expect(playwrightLocator).ToBeEnabledAsync(new LocatorAssertionsToBeEnabledOptions { Timeout = timeOut }); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, $"Error in Element To Be Clickable: {ex.Message}"); + return false; + } } /// @@ -1155,8 +1165,11 @@ public async Task TextMatchesAsync(IPlaywrightLocator playwrightLocator, s await Assertions.Expect(playwrightLocator).ToContainTextAsync(textToMatch, options); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, $"Error in Text Matches: {ex.Message}"); + return false; + } } /// @@ -1187,8 +1200,11 @@ public async Task AttributeMatchesAsync(IPlaywrightLocator playwrightLocat await Assertions.Expect(playwrightLocator).ToHaveAttributeAsync(attributeName, attributeValue, options); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, $"Error in Attribute Matches: {ex.Message}"); + return false; + } } /// @@ -1215,8 +1231,11 @@ public async Task ToBeNotVisibleAsync(IPlaywrightLocator playwrightLocator await Assertions.Expect(playwrightLocator).Not.ToBeVisibleAsync(options); return true; } - catch (TimeoutException) { return false; } - catch (AssertionException) { return false; } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Error in To Be Not Visible: {ex.Message}"); + return false; + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 858daabaf7..7f1e71d197 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -1059,9 +1059,13 @@ public async Task WaitForUrlMatchAsync(string urlPattern, float timeout) await _playwrightPage.WaitForURLAsync(urlPattern, new PageWaitForURLOptions { Timeout = timeout }); return true; } + catch (TimeoutException) + { + return false; + } catch (Exception ex) { - throw new Exception("URL did not match the pattern", ex); + throw new Exception("An error occurred while waiting for the URL to match the pattern", ex); } } @@ -1173,7 +1177,6 @@ private string GetSelector(eLocateBy locateBy, string locateValue) eLocateBy.ByID => $"#{locateValue}", eLocateBy.ByClassName => $".{locateValue}", eLocateBy.ByTagName => locateValue, - eLocateBy.ByAttribute => $"[{locateValue}]", eLocateBy.ByName => $"[name='{locateValue}']", eLocateBy.ByXPath => locateValue, // XPath is used as-is eLocateBy.ByCSSSelector => locateValue, // CSS Selector is used as-is @@ -1182,33 +1185,35 @@ private string GetSelector(eLocateBy locateBy, string locateValue) _ => throw new ArgumentException("Invalid locator type") }; } - + TaskCompletionSource alertDetected = new TaskCompletionSource(); /// /// Waits for an alert to appear within the specified timeout. /// public async Task WaitForAlertAsync(float timeout) { - var alertDetected = new TaskCompletionSource(); - - _playwrightPage.Dialog += (_, dialog) => - { - if (dialog.Type == DialogType.Alert) - { - alertDetected.TrySetResult(true); - } - }; - + _playwrightPage.Dialog += _playwrightPage_Dialog; var delayTask = Task.Delay((int)timeout); var completedTask = await Task.WhenAny(alertDetected.Task, delayTask); if (completedTask == delayTask) { + _playwrightPage.Dialog -= _playwrightPage_Dialog; throw new TimeoutException("Alert did not appear within the specified timeout."); } - + _playwrightPage.Dialog -= _playwrightPage_Dialog; return await alertDetected.Task; } + /// + /// Handles the Playwright dialog event and sets the alertDetected TaskCompletionSource to true if the dialog is of type Alert. + /// + private void _playwrightPage_Dialog(object? sender, IDialog e) + { + if (e.Type == DialogType.Alert) + { + alertDetected.TrySetResult(true); + } + } } } From 1b035c5af3bce793432536116147e01a665e9b69 Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Thu, 30 Jan 2025 18:57:51 +0530 Subject: [PATCH 16/19] Handled the Invalid column prferences error --- Ginger/Ginger/Actions/ActionEditPage.xaml.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Ginger/Ginger/Actions/ActionEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPage.xaml.cs index 2b9271c964..ad3ba8b6dd 100644 --- a/Ginger/Ginger/Actions/ActionEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPage.xaml.cs @@ -1053,6 +1053,8 @@ private void SetActReturnValuesGrid() case "Store To": node.IsSelected = columnPreferences.Contains("StoreTo", StringComparison.OrdinalIgnoreCase); break; + case "All": + break; default: Reporter.ToLog(eLogLevel.ERROR, "Invalid format in column preferences"); break; @@ -1065,7 +1067,6 @@ private void SetActReturnValuesGrid() } } - // Creating the CheckBox for "Description" CheckBox descriptionCheckBox = new CheckBox { Content = "Description", @@ -1182,6 +1183,8 @@ private void ColumnMultiSelectComboBox_ItemCheckBoxClick(object? sender, EventAr columnCount = node.IsSelected ? columnCount + 1 : columnCount; columnPreferences += node.IsSelected ? "StoreTo" : ""; break; + case "All": + break; default: Reporter.ToLog(eLogLevel.ERROR, "Invalid format in column preferences"); break; From df4eca7dc282853211d9bb4cbefc66844ad0238f Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Fri, 31 Jan 2025 12:20:23 +0530 Subject: [PATCH 17/19] codecy chnages --- Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs | 10 ++++++++++ .../CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs | 10 +++++----- .../CoreDrivers/Web/Playwright/PlaywrightDriver.cs | 3 +-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs b/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs index eb806c6e35..c4be63a51b 100644 --- a/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs +++ b/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs @@ -51,6 +51,7 @@ public partial class HTMLReportTemplatePage : GingerUIPage private string mPreviewDummyReportDataPath = string.Empty; private string mPreviewDummyReportPath = string.Empty; + private string mDefaultReportTemplateName = string.Empty; public HTMLReportConfiguration newHTMLReportConfiguration { @@ -353,6 +354,7 @@ private void SetControlsNewTemplate() { SetIsDefualtImage(); NewTemplateNameTextBox.Text = _HTMLReportConfiguration.Name.ToString(); + mDefaultReportTemplateName= _HTMLReportConfiguration.Name.ToString(); TemplateDescriptionTextBox.Text = _HTMLReportConfiguration.Description.ToString(); //htmlDefaultOnRadioBtn.IsChecked = _HTMLReportConfiguration.IsDefault; //htmlDefaultOffRadioBtn.IsChecked = !_HTMLReportConfiguration.IsDefault; @@ -1031,5 +1033,13 @@ private void _HTMLReportConfiguration_PropertyChanged(object sender, System.Comp SetIsDefualtImage(); } } + + private void NewTemplateNameTextBox_LostFocus(object sender, RoutedEventArgs e) + { + if (string.IsNullOrEmpty(NewTemplateNameTextBox.Text)) + { + NewTemplateNameTextBox.Text = mDefaultReportTemplateName; + } + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 7f1e71d197..1c157a58d6 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -1065,7 +1065,7 @@ public async Task WaitForUrlMatchAsync(string urlPattern, float timeout) } catch (Exception ex) { - throw new Exception("An error occurred while waiting for the URL to match the pattern", ex); + throw new OperationCanceledException("An error occurred while waiting for the URL to match the pattern", ex); } } @@ -1134,11 +1134,11 @@ public async Task WaitForElementsCheckedAsync(eLocateBy locateBy, string l await Task.Delay(100); } - throw new Exception("Elements did not become checked within the specified time"); + throw new OperationCanceledException("Elements did not become checked within the specified time"); } catch (Exception ex) { - throw new Exception("Elements did not become checked within the specified time", ex); + throw new OperationCanceledException("Elements did not become checked within the specified time", ex); } } @@ -1163,7 +1163,7 @@ private async Task WaitForElementsStateAsync(eLocateBy locateBy, string lo } catch (Exception ex) { - throw new Exception($"Elements did not reach the desired state(s) within the specified time", ex); + throw new OperationCanceledException($"Elements did not reach the desired state(s) within the specified time", ex); } } @@ -1198,7 +1198,7 @@ public async Task WaitForAlertAsync(float timeout) if (completedTask == delayTask) { _playwrightPage.Dialog -= _playwrightPage_Dialog; - throw new TimeoutException("Alert did not appear within the specified timeout."); + throw new TimeoutException($"Alert did not appear within the specified {timeout}."); } _playwrightPage.Dialog -= _playwrightPage_Dialog; return await alertDetected.Task; diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs index e30ff985dc..42073283bf 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs @@ -299,7 +299,6 @@ public override void RunAction(Act act) float waitUntilTime; if (act.Timeout > 0) { - // waitUntilTime= TimeSpan.FromSeconds(act.Timeout.GetValueOrDefault()); waitUntilTime = act.Timeout.GetValueOrDefault(); } else if(browserOptions.Timeout>0) @@ -310,7 +309,7 @@ public override void RunAction(Act act) { waitUntilTime = 5; } - browserOptions.Timeout = (float)waitUntilTime; + browserOptions.Timeout = waitUntilTime; try { actWebSmartSyncHandler.HandleAsync(act, waitUntilTime*1000).Wait(); From 3aaf29fcbe8055da9d25c86003af45d4285ed259 Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Fri, 31 Jan 2025 12:22:22 +0530 Subject: [PATCH 18/19] unwanted code --- Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs b/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs index c4be63a51b..ee875d27a1 100644 --- a/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs +++ b/Ginger/Ginger/Reports/HTMLReportTemplatePage.xaml.cs @@ -51,7 +51,6 @@ public partial class HTMLReportTemplatePage : GingerUIPage private string mPreviewDummyReportDataPath = string.Empty; private string mPreviewDummyReportPath = string.Empty; - private string mDefaultReportTemplateName = string.Empty; public HTMLReportConfiguration newHTMLReportConfiguration { @@ -354,7 +353,6 @@ private void SetControlsNewTemplate() { SetIsDefualtImage(); NewTemplateNameTextBox.Text = _HTMLReportConfiguration.Name.ToString(); - mDefaultReportTemplateName= _HTMLReportConfiguration.Name.ToString(); TemplateDescriptionTextBox.Text = _HTMLReportConfiguration.Description.ToString(); //htmlDefaultOnRadioBtn.IsChecked = _HTMLReportConfiguration.IsDefault; //htmlDefaultOffRadioBtn.IsChecked = !_HTMLReportConfiguration.IsDefault; @@ -1033,13 +1031,6 @@ private void _HTMLReportConfiguration_PropertyChanged(object sender, System.Comp SetIsDefualtImage(); } } - - private void NewTemplateNameTextBox_LostFocus(object sender, RoutedEventArgs e) - { - if (string.IsNullOrEmpty(NewTemplateNameTextBox.Text)) - { - NewTemplateNameTextBox.Text = mDefaultReportTemplateName; - } - } + } } From 7ce666c88a2b497e7f0493ea1fa2fb9fb6c4a249 Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Fri, 31 Jan 2025 19:13:55 +0530 Subject: [PATCH 19/19] handled comment --- .../ActionHandlers/ActWebSmartSyncHandler.cs | 27 ++++++++++--------- .../Drivers/CoreDrivers/Web/IBrowserTab.cs | 2 +- .../Web/Playwright/PlaywrightBrowserTab.cs | 18 ++++++++++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs index f8fda10cb8..a7bb9306b6 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActWebSmartSyncHandler.cs @@ -27,6 +27,9 @@ limitations under the License. namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.ActionHandlers { + /// + /// Handles various web synchronization operations for the ActWebSmartSync action. + /// internal class ActWebSmartSyncHandler { private ActWebSmartSync _actWebSmartSync; @@ -121,7 +124,7 @@ public async Task HandleAsync(Act act, float waitUntilTimeout) } catch (Exception ex) { - Reporter.ToLog(eLogLevel.DEBUG,$"Error in operation {_actWebSmartSync.SyncOperations}: {ex.Message} {ex.InnerException?.Message}"); + Reporter.ToLog(eLogLevel.DEBUG, $"Error in operation {_actWebSmartSync.SyncOperations}: {ex.Message} {ex.InnerException?.Message}"); act.Error = ex.Message + ex.InnerException?.Message; } } @@ -187,17 +190,12 @@ private async Task HandleElementIsSelectedAsync(Act act, float waitUntilTimeout) /// private async Task HandlePageHasBeenLoadedAsync(Act act, float waitUntilTimeout) { - Stopwatch stopwatch = Stopwatch.StartNew(); - while (stopwatch.Elapsed.TotalSeconds < waitUntilTimeout) + if (await _browserTab.WaitTillLoadedAsync(waitUntilTimeout)) { - var state = await _browserTab.ExecuteJavascriptAsync("document.readyState"); - if (state.Equals("complete", StringComparison.OrdinalIgnoreCase)) - { - return; - } - await Task.Delay(100); + return; } act.Error = "Page has not been loaded within the given time."; + } /// @@ -236,13 +234,18 @@ private async Task HandleTextMatchesAsync(Act act, float waitUntilTimeout) /// private async Task HandleAttributeMatchesAsync(Act act, float waitUntilTimeout) { - IBrowserElement attributeElement = await GetFirstMatchingElementAsync(); + string attributeName = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.AttributeName)); string attributeValue = _actWebSmartSync.GetInputParamCalculatedValue(nameof(ActWebSmartSync.AttributeValue)); - if (string.IsNullOrEmpty(attributeName) || string.IsNullOrEmpty(attributeValue)) + if (string.IsNullOrEmpty(attributeName)) { - throw new InvalidDataException("For AttributeMatches operation, the input value is missing or invalid."); + throw new InvalidDataException("For AttributeMatches operation, the Attribute Name value is missing or invalid."); } + if (string.IsNullOrEmpty(attributeValue)) + { + throw new InvalidDataException("For AttributeMatches operation, the Attribute Value value is missing or invalid."); + } + IBrowserElement attributeElement = await GetFirstMatchingElementAsync(); if (await attributeElement.AttributeMatchesAsync(attributeName, attributeValue, waitUntilTimeout)) { return; diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs index dd8e748714..7b72e0b819 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs @@ -63,7 +63,7 @@ internal interface IBrowserTab public Task InjectJavascriptIframeAsync(string script); - public Task WaitTillLoadedAsync(); + public Task WaitTillLoadedAsync(float timeOut = 0); public Task ConsoleLogsAsync(); diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs index 1c157a58d6..5c8731ca87 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs @@ -33,6 +33,7 @@ limitations under the License. using System.Reflection; using System.Text.Json; using System.Text.Json.Nodes; +using System.Threading; using System.Threading.Tasks; using IPlaywrightElementHandle = Microsoft.Playwright.IElementHandle; using IPlaywrightFrameLocator = Microsoft.Playwright.IFrameLocator; @@ -242,7 +243,7 @@ public Task MouseRightClickAsync(Point point) /// A task representing the asynchronous operation. public Task MoveMouseAsync(Point point) { - ThrowIfClosed(); + ThrowIfClosed(); return _playwrightPage.Mouse.MoveAsync(point.X, point.Y); } @@ -312,10 +313,19 @@ public Task RefreshAsync() /// Waits until the page is fully loaded. /// /// A task representing the asynchronous operation. - public Task WaitTillLoadedAsync() + public async Task WaitTillLoadedAsync(float timeOut = 0) { - ThrowIfClosed(); - return _playwrightPage.WaitForLoadStateAsync(LoadState.Load); + try + { + ThrowIfClosed(); + var options = timeOut > 0 ? new PageWaitForLoadStateOptions { Timeout = timeOut } : null; + await _playwrightPage.WaitForLoadStateAsync(LoadState.Load, options); + return true; + } + catch (Exception) + { + return false; + } } ///