From e60279c233389f541b75538023d8c45cb04c6db7 Mon Sep 17 00:00:00 2001 From: amanpras Date: Thu, 4 Jan 2024 15:56:51 +0530 Subject: [PATCH 01/10] Issue of POM text search in act 37171 --- .../UCListView/UcListView.xaml.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs b/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs index 900f1c91b4..4aaa136232 100644 --- a/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs @@ -298,12 +298,20 @@ private void SetListSelectedItemAsSourceCurrentItem() { this.Dispatcher.Invoke(() => { - if (mObjList.CurrentItem != xListView.SelectedItem) + if(mObjList.CurrentItem != null && xListView.Items.Count > 0) { - xListView.SelectedItem = mObjList.CurrentItem; - int index = xListView.Items.IndexOf(mObjList.CurrentItem); - xListView.SelectedIndex = index; - ScrollToViewCurrentItem(); + if (mObjList.CurrentItem != xListView.SelectedItem) + { + xListView.SelectedItem = mObjList.CurrentItem; + int index = xListView.Items.IndexOf(mObjList.CurrentItem); + xListView.SelectedIndex = index; + ScrollToViewCurrentItem(); + if(index >= 0 && index < xListView.Items.Count) + { + xListView.SelectedIndex = index; + ScrollToViewCurrentItem(); + } + } } }); } From 81c1fc017e3c89f3624dc5a853d38f3bf6939b1d Mon Sep 17 00:00:00 2001 From: amanpras Date: Thu, 4 Jan 2024 15:59:05 +0530 Subject: [PATCH 02/10] Import optional values from swagger example --- .../APIModelLib/SwaggerApi/OpenApiBase.cs | 17 +++++- .../APIModelLib/SwaggerApi/OpenApiVer3.cs | 58 +++++++++++++++++-- .../APIModelLib/SwaggerApi/SwaggerVer2.cs | 49 ++++++++++++++++ Ginger/GingerAutoPilotTest/SwaggetTests.cs | 29 ++++++++++ 4 files changed, 148 insertions(+), 5 deletions(-) diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs index e60036c8bb..d21ba16401 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs @@ -306,6 +306,21 @@ public ObservableList GetListOfParamEnums(SwaggerParameter swagge return lstOptions; } - + public void SetOptionalValue(ObservableList AppModelParameters, Dictionary listExampleValues) + { + if (AppModelParameters.Count > 0) + { + foreach (var item in AppModelParameters) + { + string parameterName = (item.ElementName.TrimStart('<', '{','[').TrimEnd('>', '}',']')).ToLower(); + + if (parameterName != null && listExampleValues.TryGetValue(parameterName, out string exampleValue)) + { + ObservableList tempList = new ObservableList() { new OptionalValue(exampleValue) { } }; + item.OptionalValuesList = tempList; + } + } + } + } } } \ No newline at end of file diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs index 1179cd3da3..2cf613fe78 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs @@ -18,6 +18,7 @@ limitations under the License. using Amdocs.Ginger.Common.APIModelLib; using Amdocs.Ginger.Repository; +using GingerCore.Variables; using Newtonsoft.Json; using NJsonSchema; using NSwag; @@ -28,6 +29,7 @@ limitations under the License. using System.Net; using System.Net.Mime; using System.Reflection; +using System.Reflection.Metadata; namespace Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib.SwaggerApi { @@ -40,8 +42,8 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd { opendoc = Swaggerdoc; - - + + var listExampleValues = GetExamplesFromOpenApiComponents(opendoc.Components); foreach (var paths in opendoc.Paths) { @@ -56,6 +58,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd { ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key,opendoc); + SetOptionalValue(basicModal.AppModelParameters,listExampleValues); SwaggerModels.Add(basicModal); GenerateResponse(Operation, basicModal); } @@ -80,6 +83,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listExampleValues); AAM.Name += "-UrlEncoded"; AAM.Description = "Body Type is UrlEncoded "; } @@ -90,7 +94,9 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - AAM.Name += "-JSON"; AAM.Description = "Body Type is JSON"; + SetOptionalValue(AAM.AppModelParameters, listExampleValues); + AAM.Name += "-JSON"; + AAM.Description = "Body Type is JSON"; } break; @@ -100,6 +106,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listExampleValues); AAM.Name += "-XML"; AAM.Description = "Body Type is XML"; } @@ -124,7 +131,50 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd return SwaggerModels; } - + public static Dictionary GetExamplesFromOpenApiComponents(OpenApiComponents apiComponents) + { + + //ObservableList exampleValues = new ObservableList(); + Dictionary exampleValues = new Dictionary(); + try + { + if (apiComponents.Schemas != null && apiComponents.Schemas.Count != 0) + { + foreach (var schemaEntry in apiComponents.Schemas) + { + string schemaName = schemaEntry.Key; + var schemaDefinition = schemaEntry.Value; + + if (schemaDefinition.ActualProperties != null && schemaDefinition.ActualProperties.Count > 0) + { + foreach (var item in schemaDefinition.ActualProperties) + { + var actualName = item.Key; + var actualDefinition = item.Value.Example?.ToString(); + if (actualDefinition != null && !exampleValues.ContainsKey(actualName.ToLower())) + { + exampleValues.Add(actualName.ToLower(), actualDefinition); + } + + } + } + else if (schemaDefinition.Example != null) + { + if (!exampleValues.ContainsKey(schemaName.ToLower())) + { + exampleValues.Add(schemaName.ToLower(), schemaDefinition.Example.ToString()); + } + } + } + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.INFO, "Example value was null in one of the tag", ex); + } + + return exampleValues; + } } } \ No newline at end of file diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs index 27baffa81e..c3bdc21509 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs @@ -36,6 +36,8 @@ public class SwaggerVer2 : OpenApiBase public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc, ObservableList SwaggerModels) { swagTwo = Swaggerdoc; + var listofExamples = GetExamplesFromDefinitions(swagTwo); + foreach (var paths in swagTwo.Paths) { SwaggerPathItem SPi = paths.Value; @@ -49,6 +51,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc { ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key, swagTwo); + SetOptionalValue(basicModal.AppModelParameters, listofExamples); SwaggerModels.Add(basicModal); GenerateResponse(Operation, basicModal); } @@ -80,6 +83,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listofExamples); + } if (Operation.ActualConsumes.Count() > 1) { @@ -93,6 +98,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -127,9 +133,11 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc { case "application/x-www-form-urlencoded": GenerateFormParameters(AAM, Operation); + SetOptionalValue(AAM.AppModelParameters, listofExamples); break; case "multipart/form-data": GenerateFormParameters(AAM, Operation, true); + SetOptionalValue(AAM.AppModelParameters, listofExamples); break; case "application/json": AAM.ContentType = ApplicationAPIUtils.eContentType.JSon; @@ -137,6 +145,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -151,6 +160,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); + SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -176,6 +186,45 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc } return SwaggerModels; } + public static Dictionary GetExamplesFromDefinitions(SwaggerDocument apidoc) + { + + //ObservableList exampleValues = new ObservableList(); + Dictionary exampleValues = new Dictionary(); + try + { + if (apidoc.Definitions != null && apidoc.Definitions.Count != 0) + { + foreach (var schemaEntry in apidoc.Definitions) + { + string schemaName = schemaEntry.Key; + var schemaDefinition = schemaEntry.Value; + + // Check if the schema has properties and 'ActualProperty' property + if (schemaDefinition.ActualProperties != null && schemaDefinition.ActualProperties.Count > 0) + { + foreach (var item in schemaDefinition.ActualProperties) + { + var actualName = item.Key; + var actualDefinition = item.Value.Example; + if (actualDefinition != null) + { + + exampleValues.Add(actualName,actualDefinition.ToString()); + } + + } + } + } + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.INFO, "Example value was null in one of the tag", ex); + } + + return exampleValues; + } } } \ No newline at end of file diff --git a/Ginger/GingerAutoPilotTest/SwaggetTests.cs b/Ginger/GingerAutoPilotTest/SwaggetTests.cs index bbb9957f8e..4fcde1ce6d 100644 --- a/Ginger/GingerAutoPilotTest/SwaggetTests.cs +++ b/Ginger/GingerAutoPilotTest/SwaggetTests.cs @@ -19,6 +19,7 @@ limitations under the License. using Amdocs.Ginger.Common; using Amdocs.Ginger.Common.Repository.ApplicationModelLib.APIModelLib.SwaggerApi; using Amdocs.Ginger.Repository; +using GingerCore.GeneralLib; using GingerTestHelper; using Microsoft.VisualStudio.TestTools.UnitTesting; using NuGet.Frameworks; @@ -177,5 +178,33 @@ public void Swagger2YamlCheckHeaderAndParamsCount() } + + [TestMethod] + [Timeout(60000)] + public void ApiModelsOptionalValuesModelParamTest() + { + //Arrange + SwaggerParser parserForBillingAccount = new SwaggerParser(); + string createPaymentProfileFileName = TestResources.GetTestResourcesFile(@"Swagger" + Path.DirectorySeparatorChar + "petstore_versionthree.json"); + ObservableList requests = new ObservableList(); + ObservableList optionalValueContainer = new ObservableList(); + ApplicationAPIModel RequestToTest; + + //Act + requests = parserForBillingAccount.ParseDocument(createPaymentProfileFileName, requests); + RequestToTest = requests.Where(x => x.Name == @"Create user-JSON").ElementAt(0); + optionalValueContainer = RequestToTest.AppModelParameters.ElementAt(4).OptionalValuesList; + + //Assert + Assert.IsTrue(optionalValueContainer.Any(item => item.Value == "john@email.com")); + + + //Act + RequestToTest = requests.Where(x => x.Name == @"Place an order for a pet-XML").ElementAt(0); + optionalValueContainer = RequestToTest.AppModelParameters.ElementAt(1).OptionalValuesList; + + //Assert + Assert.IsTrue(optionalValueContainer.Any(item => item.Value == "198772")); + } } } \ No newline at end of file From fcc62c2e136462929498fc0e0da7018e4bbbbdb5 Mon Sep 17 00:00:00 2001 From: amanpras Date: Thu, 4 Jan 2024 18:39:11 +0530 Subject: [PATCH 03/10] improvements --- .../APIModelLib/SwaggerApi/OpenApiBase.cs | 8 ++++++-- .../APIModelLib/SwaggerApi/OpenApiVer3.cs | 1 - .../APIModelLib/SwaggerApi/SwaggerVer2.cs | 15 ++++++++++----- Ginger/GingerAutoPilotTest/SwaggetTests.cs | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs index d21ba16401..686299a4bd 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs @@ -314,9 +314,13 @@ public void SetOptionalValue(ObservableList AppModelParameter { string parameterName = (item.ElementName.TrimStart('<', '{','[').TrimEnd('>', '}',']')).ToLower(); - if (parameterName != null && listExampleValues.TryGetValue(parameterName, out string exampleValue)) + if (!string.IsNullOrEmpty(parameterName) && listExampleValues.TryGetValue(parameterName, out string exampleValue)) { - ObservableList tempList = new ObservableList() { new OptionalValue(exampleValue) { } }; + ObservableList tempList = new ObservableList + { + new OptionalValue(exampleValue) + }; + item.OptionalValuesList = tempList; } } diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs index 2cf613fe78..207f135842 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs @@ -134,7 +134,6 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd public static Dictionary GetExamplesFromOpenApiComponents(OpenApiComponents apiComponents) { - //ObservableList exampleValues = new ObservableList(); Dictionary exampleValues = new Dictionary(); try { diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs index c3bdc21509..d5157c707a 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs @@ -189,7 +189,6 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc public static Dictionary GetExamplesFromDefinitions(SwaggerDocument apidoc) { - //ObservableList exampleValues = new ObservableList(); Dictionary exampleValues = new Dictionary(); try { @@ -200,14 +199,13 @@ public static Dictionary GetExamplesFromDefinitions(SwaggerDocum string schemaName = schemaEntry.Key; var schemaDefinition = schemaEntry.Value; - // Check if the schema has properties and 'ActualProperty' property if (schemaDefinition.ActualProperties != null && schemaDefinition.ActualProperties.Count > 0) { foreach (var item in schemaDefinition.ActualProperties) { - var actualName = item.Key; - var actualDefinition = item.Value.Example; - if (actualDefinition != null) + var actualName = item.Key.ToLower(); + var actualDefinition = item.Value.Example?.ToString(); + if (actualDefinition != null && !exampleValues.ContainsKey(actualName.ToLower())) { exampleValues.Add(actualName,actualDefinition.ToString()); @@ -215,6 +213,13 @@ public static Dictionary GetExamplesFromDefinitions(SwaggerDocum } } + else if (schemaDefinition.Example != null) + { + if (!exampleValues.ContainsKey(schemaName.ToLower())) + { + exampleValues.Add(schemaName.ToLower(), schemaDefinition.Example.ToString()); + } + } } } } diff --git a/Ginger/GingerAutoPilotTest/SwaggetTests.cs b/Ginger/GingerAutoPilotTest/SwaggetTests.cs index 4fcde1ce6d..ecacd6893e 100644 --- a/Ginger/GingerAutoPilotTest/SwaggetTests.cs +++ b/Ginger/GingerAutoPilotTest/SwaggetTests.cs @@ -187,7 +187,7 @@ public void ApiModelsOptionalValuesModelParamTest() SwaggerParser parserForBillingAccount = new SwaggerParser(); string createPaymentProfileFileName = TestResources.GetTestResourcesFile(@"Swagger" + Path.DirectorySeparatorChar + "petstore_versionthree.json"); ObservableList requests = new ObservableList(); - ObservableList optionalValueContainer = new ObservableList(); + ObservableList optionalValueContainer; ApplicationAPIModel RequestToTest; //Act From eb37fde18a7f5acbd922c1c799e6b6a1a48b14f6 Mon Sep 17 00:00:00 2001 From: amanpras Date: Thu, 4 Jan 2024 18:42:07 +0530 Subject: [PATCH 04/10] improvements --- Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs b/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs index 4aaa136232..a78c66c556 100644 --- a/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs @@ -306,11 +306,6 @@ private void SetListSelectedItemAsSourceCurrentItem() int index = xListView.Items.IndexOf(mObjList.CurrentItem); xListView.SelectedIndex = index; ScrollToViewCurrentItem(); - if(index >= 0 && index < xListView.Items.Count) - { - xListView.SelectedIndex = index; - ScrollToViewCurrentItem(); - } } } }); From e3bea5ced7fdbfd906590d65ffb48a0ec1926884 Mon Sep 17 00:00:00 2001 From: amanpras Date: Fri, 5 Jan 2024 00:19:09 +0530 Subject: [PATCH 05/10] improvements --- .../APIModelLib/SwaggerApi/OpenApiBase.cs | 6 +++++- .../APIModelLib/SwaggerApi/OpenApiVer3.cs | 11 ++++------- .../APIModelLib/SwaggerApi/SwaggerVer2.cs | 16 ++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs index 686299a4bd..dbf751c9d1 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs @@ -318,7 +318,11 @@ public void SetOptionalValue(ObservableList AppModelParameter { ObservableList tempList = new ObservableList { - new OptionalValue(exampleValue) + new OptionalValue() + { + Value = exampleValue, + IsDefault = true + } }; item.OptionalValuesList = tempList; diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs index 207f135842..3241236157 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs @@ -43,8 +43,6 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd opendoc = Swaggerdoc; - var listExampleValues = GetExamplesFromOpenApiComponents(opendoc.Components); - foreach (var paths in opendoc.Paths) { SwaggerPathItem SPi = paths.Value; @@ -58,7 +56,7 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd { ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key,opendoc); - SetOptionalValue(basicModal.AppModelParameters,listExampleValues); + SetOptionalValue(basicModal.AppModelParameters,GetExamplesFromOpenApiComponents(opendoc.Components)); SwaggerModels.Add(basicModal); GenerateResponse(Operation, basicModal); } @@ -83,7 +81,6 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listExampleValues); AAM.Name += "-UrlEncoded"; AAM.Description = "Body Type is UrlEncoded "; } @@ -94,7 +91,6 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listExampleValues); AAM.Name += "-JSON"; AAM.Description = "Body Type is JSON"; } @@ -106,7 +102,6 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listExampleValues); AAM.Name += "-XML"; AAM.Description = "Body Type is XML"; } @@ -117,6 +112,8 @@ public ObservableList OpenApiThree(SwaggerDocument Swaggerd break; } + + SetOptionalValue(AAM.AppModelParameters, GetExamplesFromOpenApiComponents(opendoc.Components)); } GenerateResponse(Operation, AAM); SwaggerModels.Add(AAM); @@ -169,7 +166,7 @@ public static Dictionary GetExamplesFromOpenApiComponents(OpenAp } catch (Exception ex) { - Reporter.ToLog(eLogLevel.INFO, "Example value was null in one of the tag", ex); + Reporter.ToLog(eLogLevel.ERROR, "Example values could not be fetched, please check the API", ex); } return exampleValues; diff --git a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs index d5157c707a..9bb0116204 100644 --- a/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs +++ b/Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs @@ -36,7 +36,6 @@ public class SwaggerVer2 : OpenApiBase public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc, ObservableList SwaggerModels) { swagTwo = Swaggerdoc; - var listofExamples = GetExamplesFromDefinitions(swagTwo); foreach (var paths in swagTwo.Paths) { @@ -51,7 +50,7 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc { ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key, swagTwo); - SetOptionalValue(basicModal.AppModelParameters, listofExamples); + SetOptionalValue(basicModal.AppModelParameters, GetExamplesFromDefinitions(swagTwo)); SwaggerModels.Add(basicModal); GenerateResponse(Operation, basicModal); } @@ -83,8 +82,6 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listofExamples); - } if (Operation.ActualConsumes.Count() > 1) { @@ -98,7 +95,6 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -112,6 +108,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; } + + SetOptionalValue(AAM.AppModelParameters, GetExamplesFromDefinitions(swagTwo)); } GenerateResponse(Operation, AAM); SwaggerModels.Add(AAM); @@ -133,11 +131,9 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc { case "application/x-www-form-urlencoded": GenerateFormParameters(AAM, Operation); - SetOptionalValue(AAM.AppModelParameters, listofExamples); break; case "multipart/form-data": GenerateFormParameters(AAM, Operation, true); - SetOptionalValue(AAM.AppModelParameters, listofExamples); break; case "application/json": AAM.ContentType = ApplicationAPIUtils.eContentType.JSon; @@ -145,7 +141,6 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateJsonBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -160,7 +155,6 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc if (Operation.RequestBody != null) { AAM.AppModelParameters.Append(GenerateXMLBody(AAM, Operation.RequestBody.Content.ElementAt(0).Value.Schema)); - SetOptionalValue(AAM.AppModelParameters, listofExamples); } if (Operation.ActualConsumes.Count() > 1) { @@ -172,6 +166,8 @@ public ObservableList SwaggerTwo(SwaggerDocument Swaggerdoc break; } + + SetOptionalValue(AAM.AppModelParameters, GetExamplesFromDefinitions(swagTwo)); } GenerateResponse(Operation, AAM); @@ -225,7 +221,7 @@ public static Dictionary GetExamplesFromDefinitions(SwaggerDocum } catch (Exception ex) { - Reporter.ToLog(eLogLevel.INFO, "Example value was null in one of the tag", ex); + Reporter.ToLog(eLogLevel.ERROR, "Example values could not be fetched, please check the API", ex); } return exampleValues; From e7e0f4ed1e1c79bdc3cdcbf9cde0e628fc79cdc4 Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 5 Jan 2024 19:14:03 +0530 Subject: [PATCH 06/10] Screen shot Optimization --- .../Common/WindowExplorerPage.xaml.cs | 28 +++--- .../UIAutomation/UIAComWrapperHelper.cs | 25 +++--- Ginger/GingerCore/Drivers/ASCF/ASCFDriver.cs | 8 +- .../InternalBrowserWindow.xaml.cs | 6 +- .../Drivers/JavaDriverLib/JavaDriver.cs | 6 +- .../Drivers/MainFrame/MainFrameDriver.cs | 34 +++---- .../GingerCore/Drivers/PBDriver/PBDriver.cs | 20 +++-- .../Drivers/WindowsLib/WindowsDriver.cs | 11 ++- Ginger/GingerCoreCommon/Actions/Act.cs | 7 +- .../UI/VisualTesting/MagickAnalyzer.cs | 30 ++++--- .../UI/VisualTesting/UIElementsAnalyzer.cs | 38 ++++---- .../Web/Selenium/SeleniumDriver.cs | 90 +++++++++++++++---- 12 files changed, 192 insertions(+), 111 deletions(-) diff --git a/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs b/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs index 89f8ae908a..e96e5ff954 100644 --- a/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs +++ b/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs @@ -1120,7 +1120,7 @@ public void ShowScreenShot() /// UnComment later after complete Implementation of functionalities over all platforms. //if(IsWebMobJavaPlatform) mWindowExplorerDriver.UnHighLightElements(); - + try { LoadPageSourceDoc = mWindowExplorerDriver.SupportedViews().Contains(eTabView.PageSource); @@ -1130,22 +1130,24 @@ public void ShowScreenShot() return; } - Bitmap ScreenShotBitmap = ((IVisualTestingDriver)((AgentOperations)mApplicationAgent.Agent.AgentOperations).Driver).GetScreenShot(); - mScreenShotViewPage = new ScreenShotViewPage("", ScreenShotBitmap, (mWindowExplorerDriver as DriverBase).ScreenShotInitialZoom()); + using (Bitmap ScreenShotBitmap = ((IVisualTestingDriver)((AgentOperations)mApplicationAgent.Agent.AgentOperations).Driver).GetScreenShot()) + { + mScreenShotViewPage = new ScreenShotViewPage("", ScreenShotBitmap, (mWindowExplorerDriver as DriverBase).ScreenShotInitialZoom()); - mScreenShotViewPage.ImageMouseCursor = Cursors.Hand; - /// UnComment to allow Element detection on hover - //if (mPlatform.PlatformType() == ePlatformType.Web) - //{ - // mScreenShotViewPage.xMainImage.MouseMove += XMainImage_MouseMove; - //} + mScreenShotViewPage.ImageMouseCursor = Cursors.Hand; + /// UnComment to allow Element detection on hover + //if (mPlatform.PlatformType() == ePlatformType.Web) + //{ + // mScreenShotViewPage.xMainImage.MouseMove += XMainImage_MouseMove; + //} - mScreenShotViewPage.xMainImage.MouseLeftButtonDown += XMainImage_MouseLeftButtonDown; + mScreenShotViewPage.xMainImage.MouseLeftButtonDown += XMainImage_MouseLeftButtonDown; - xScreenShotFrame.ClearAndSetContent(mScreenShotViewPage); - //xDeviceImage.Source = General.ToBitmapSource(ScreenShotBitmap); + xScreenShotFrame.ClearAndSetContent(mScreenShotViewPage); + //xDeviceImage.Source = General.ToBitmapSource(ScreenShotBitmap); - xScreenShotFrame.Visibility = Visibility.Visible; + xScreenShotFrame.Visibility = Visibility.Visible; + } } catch (Exception exc) { diff --git a/Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs b/Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs index dedec18e38..00a50d753b 100644 --- a/Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs +++ b/Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs @@ -4854,8 +4854,10 @@ public override void TakeScreenShot(ActScreenShot act) { if (CurrentWindow != null) { - Bitmap tempBmp = GetCurrentWindowBitmap(); - act.AddScreenShot(tempBmp); + using (Bitmap tempBmp = GetCurrentWindowBitmap()) + { + act.AddScreenShot(tempBmp); + } } } return; @@ -4873,8 +4875,7 @@ public override void TakeScreenShot(ActScreenShot act) public override Bitmap GetCurrentWindowBitmap() { - Bitmap bmp = WindowToBitmap(CurrentWindow); - return bmp; + return WindowToBitmap(CurrentWindow); } public List GetCurrentAppWindows() @@ -4900,8 +4901,7 @@ public override Bitmap GetAppWindowAsBitmap(AppWindow aw) //****************** try { UIAuto.AutomationElement tempWindow = (UIAuto.AutomationElement)((UIAElementInfo)aw.RefObject).ElementObject; - Bitmap bmp = WindowToBitmap(tempWindow); - return bmp; + return WindowToBitmap(tempWindow); } catch (Exception ex) { @@ -4929,27 +4929,22 @@ public override List GetAppDialogAsBitmap(AppWindow aw) ///******** for (int i = 0; i < AEList.Count; i++) { UIAuto.AutomationElement ele = AEList[i]; - Bitmap bmp = WindowToBitmap(ele); - bList.Add(bmp); + bList.Add(WindowToBitmap(ele)); } for (int i = 0; i < AEList1.Count; i++) { UIAuto.AutomationElement ele = AEList1[i]; - Bitmap bmp = WindowToBitmap(ele); - bList.Add(bmp); + bList.Add(WindowToBitmap(ele)); + } for (int i = 0; i < AEListWindows.Count; i++) { - List winPopup = new List(); if (AEListWindows[i].Current.BoundingRectangle.X != 0 && AEListWindows[i].Current.BoundingRectangle.Y != 0) { - Bitmap bmp = WindowToBitmap(AEListWindows[i]); - winPopup.Add(bmp); //adding screenshot of element type "window" + bList.Add(WindowToBitmap(AEListWindows[i]));//adding screenshot of element type "window" } - bList.AddRange(winPopup); } - return bList; } diff --git a/Ginger/GingerCore/Drivers/ASCF/ASCFDriver.cs b/Ginger/GingerCore/Drivers/ASCF/ASCFDriver.cs index 1f1dad3afd..7d5386d8a3 100644 --- a/Ginger/GingerCore/Drivers/ASCF/ASCFDriver.cs +++ b/Ginger/GingerCore/Drivers/ASCF/ASCFDriver.cs @@ -432,13 +432,15 @@ public override void RunAction(Act act) { act.AddScreenShot(screenShot); } + screenShots.Clear(); } else { - Bitmap tempBmp = TakeScreenShot(actSS); - act.AddScreenShot(tempBmp); + using (Bitmap tempBmp = TakeScreenShot(actSS)) + { + act.AddScreenShot(tempBmp); + } } - break; case "ActGetMsgboxText": ActGetMsgboxText actmsg = (ActGetMsgboxText)act; diff --git a/Ginger/GingerCore/Drivers/InternalBrowserLib/InternalBrowserWindow.xaml.cs b/Ginger/GingerCore/Drivers/InternalBrowserLib/InternalBrowserWindow.xaml.cs index d4354b1d00..3357c8c1fe 100644 --- a/Ginger/GingerCore/Drivers/InternalBrowserLib/InternalBrowserWindow.xaml.cs +++ b/Ginger/GingerCore/Drivers/InternalBrowserLib/InternalBrowserWindow.xaml.cs @@ -1201,8 +1201,10 @@ public Bitmap GetScreenShot() internal void AddScreenShot(Act act) { - Bitmap tempBmp = GetScreenShot(); - act.AddScreenShot(tempBmp); + using (Bitmap tempBmp = GetScreenShot()) + { + act.AddScreenShot(tempBmp); + } } internal void GotoURL(string p) diff --git a/Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs b/Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs index 2911de57f4..9c9cb45113 100644 --- a/Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs +++ b/Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs @@ -1844,8 +1844,10 @@ public PayLoad TakeScreenShots(ActScreenShot actScreenShot) } TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); - Bitmap btmp = (Bitmap)tc.ConvertFrom(screenShotbytes); - actScreenShot.AddScreenShot(btmp); + using (Bitmap btmp = (Bitmap)tc.ConvertFrom(screenShotbytes)) + { + actScreenShot.AddScreenShot(btmp); + } } catch (Exception ex) { diff --git a/Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs b/Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs index ca47171a3d..ea1c600c07 100644 --- a/Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs +++ b/Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs @@ -514,24 +514,26 @@ public override bool IsRunning() public void TakeScreenShot(Act act) { - int width = (int)mDriverWindow.Width; - int height = (int)mDriverWindow.Height; - RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); - renderTargetBitmap.Render(mDriverWindow); - - PngBitmapEncoder pngImage = new PngBitmapEncoder(); - pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); - string FileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png"; - using (Stream fileStream = File.Create(FileName)) - { - pngImage.Save(fileStream); - fileStream.Close(); - } + int width = (int)mDriverWindow.Width; + int height = (int)mDriverWindow.Height; + RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); + renderTargetBitmap.Render(mDriverWindow); + + PngBitmapEncoder pngImage = new PngBitmapEncoder(); + pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); + string FileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png"; + using (Stream fileStream = File.Create(FileName)) + { + pngImage.Save(fileStream); + fileStream.Close(); + } - Bitmap bmp = (Bitmap)Image.FromFile(FileName); - //TODO: Remove the temporary File created + using (Bitmap bmp = (Bitmap)Image.FromFile(FileName)) + { + //TODO: Remove the temporary File created - act.AddScreenShot(bmp); + act.AddScreenShot(bmp); + } } #endregion GingerFunctions diff --git a/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs b/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs index 8e8ac66adf..17a7c80763 100644 --- a/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs +++ b/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs @@ -232,10 +232,12 @@ public override void RunAction(Act act) List bList; foreach (AppWindow aw in list) { - Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw); - if (bmp != null) + using (Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw)) { - act.AddScreenShot(bmp); + if (bmp != null) + { + act.AddScreenShot(bmp); + } } bList = mUIAutomationHelper.GetAppDialogAsBitmap(aw); foreach (Bitmap tempbmp in bList) @@ -249,8 +251,10 @@ public override void RunAction(Act act) { if (mUIAutomationHelper.GetCurrentWindow() != null) { - Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - act.AddScreenShot(bmp); + using (Bitmap bmpcurrentwin = mUIAutomationHelper.GetCurrentWindowBitmap()) + { + act.AddScreenShot(bmpcurrentwin); + } } } return; @@ -1250,8 +1254,10 @@ public bool CanStartAnotherInstance(out string errorMessage) /// Application Screenshot in Bitmap format public Bitmap GetScreenShot(Tuple setScreenSize = null, bool IsFullPageScreenshot = false) { - Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - return bmp; + //Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); + //return bmp; + return mUIAutomationHelper.GetCurrentWindowBitmap(); + } /// diff --git a/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs b/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs index 0013014612..1de393304b 100644 --- a/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs +++ b/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs @@ -224,8 +224,10 @@ public override void RunAction(Act act) //Disabling the capturing all windows for Windows driver until we fix show window issue if (mUIAutomationHelper.GetCurrentWindow() != null) { - Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - act.AddScreenShot(bmp); + using (Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap()) + { + act.AddScreenShot(bmp); + } } //if not running well. need to add return same as PBDrive } @@ -1571,8 +1573,9 @@ private void HandleWindowsGenericWidgetControlAction(ActGenElement actWinC) public Bitmap GetScreenShot(Tuple setScreenSize = null, bool IsFullPageScreenshot = false) { - Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - return bmp; + //Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); + //return bmp; + return mUIAutomationHelper.GetCurrentWindowBitmap(); } ObservableList IWindowExplorer.GetElements(ElementLocator EL) diff --git a/Ginger/GingerCoreCommon/Actions/Act.cs b/Ginger/GingerCoreCommon/Actions/Act.cs index 1c07ac43c2..46cb52b5e2 100644 --- a/Ginger/GingerCoreCommon/Actions/Act.cs +++ b/Ginger/GingerCoreCommon/Actions/Act.cs @@ -987,8 +987,11 @@ public void AddScreenShot(Bitmap bmp, string Name = "") { try { - ScreenShots.Add(SaveScreenshotToTempFile(bmp)); - ScreenShotsNames.Add(Name); + using (bmp) + { + ScreenShots.Add(SaveScreenshotToTempFile(bmp)); + ScreenShotsNames.Add(Name); + } } catch (Exception ex) { diff --git a/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/MagickAnalyzer.cs b/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/MagickAnalyzer.cs index b3d76ff526..b5e6581cae 100644 --- a/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/MagickAnalyzer.cs +++ b/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/MagickAnalyzer.cs @@ -39,26 +39,28 @@ void IVisualAnalyzer.SetAction(IVisualTestingDriver driver, ActVisualTesting act void IVisualAnalyzer.Compare() { - MagickImage magickBaseImg = new MagickImage(General.ImageToByteArray(mAct.baseImage, System.Drawing.Imaging.ImageFormat.Bmp));//Not tested after code change - MagickImage magickTargetImg = new MagickImage(General.ImageToByteArray(mAct.targetImage, System.Drawing.Imaging.ImageFormat.Bmp));//Not tested after code change + MagickImage magickBaseImg = new MagickImage(General.ImageToByteArray(mAct.baseImage, System.Drawing.Imaging.ImageFormat.Bmp));//Not tested after code change + MagickImage magickTargetImg = new MagickImage(General.ImageToByteArray(mAct.targetImage, System.Drawing.Imaging.ImageFormat.Bmp));//Not tested after code change - MagickImage diffImg = new MagickImage(); + MagickImage diffImg = new MagickImage(); - double percentageDifference; + double percentageDifference; - ErrorMetric eErrorMetric = ErrorMetric.Fuzz; - Enum.TryParse(mAct.GetOrCreateInputParam(ActVisualTesting.Fields.ErrorMetric).Value, out eErrorMetric); - percentageDifference = magickBaseImg.Compare(magickTargetImg, eErrorMetric, diffImg, Channels.Red); - percentageDifference = percentageDifference * 100; - percentageDifference = Math.Round(percentageDifference, 2); + ErrorMetric eErrorMetric = ErrorMetric.Fuzz; + Enum.TryParse(mAct.GetOrCreateInputParam(ActVisualTesting.Fields.ErrorMetric).Value, out eErrorMetric); + percentageDifference = magickBaseImg.Compare(magickTargetImg, eErrorMetric, diffImg, Channels.Red); + percentageDifference = percentageDifference * 100; + percentageDifference = Math.Round(percentageDifference, 2); - TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); - Bitmap ImgToSave = (Bitmap)tc.ConvertFrom(diffImg.ToByteArray()); - mAct.CompareResult = ImgToSave;//Not tested after code change + TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); + using (Bitmap ImgToSave = (Bitmap)tc.ConvertFrom(diffImg.ToByteArray())) + { + mAct.CompareResult = ImgToSave;//Not tested after code change - mAct.AddOrUpdateReturnParamActual("Percentage Difference", percentageDifference + ""); + mAct.AddOrUpdateReturnParamActual("Percentage Difference", percentageDifference + ""); - mAct.AddScreenShot(ImgToSave, "Compare Result"); + mAct.AddScreenShot(ImgToSave, "Compare Result"); + } } public void CreateBaseline() diff --git a/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/UIElementsAnalyzer.cs b/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/UIElementsAnalyzer.cs index 4e3e5162fb..76fcb14830 100644 --- a/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/UIElementsAnalyzer.cs +++ b/Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/UIElementsAnalyzer.cs @@ -56,36 +56,38 @@ void IVisualAnalyzer.Compare() IEnumerable listwithnomatch = from x in VE1.Elements where x.Text != "" && x.MatchingElement == null select x; // Create compare bitmap for VE1 - Bitmap bmp = new Bitmap(VE1.Bitmap); - // mark element with no match - foreach (VisualElement VE in listwithnomatch) + using (Bitmap bmp = new Bitmap(VE1.Bitmap)) { - using (Graphics gr = Graphics.FromImage(bmp)) + // mark element with no match + foreach (VisualElement VE in listwithnomatch) { - gr.SmoothingMode = SmoothingMode.AntiAlias; + using (Graphics gr = Graphics.FromImage(bmp)) + { + gr.SmoothingMode = SmoothingMode.AntiAlias; - //TODO: check the -3 or + 6 will not go out of bitmap - Rectangle rect = new Rectangle(VE.X - 3, VE.Y - 3, VE.Width + 6, VE.Height + 6); + //TODO: check the -3 or + 6 will not go out of bitmap + Rectangle rect = new Rectangle(VE.X - 3, VE.Y - 3, VE.Width + 6, VE.Height + 6); - gr.FillRectangle(Brushes.Transparent, rect); - using (Pen thick_pen = new Pen(Color.HotPink, 2)) - { - gr.DrawRectangle(thick_pen, rect); + gr.FillRectangle(Brushes.Transparent, rect); + using (Pen thick_pen = new Pen(Color.HotPink, 2)) + { + gr.DrawRectangle(thick_pen, rect); + } } } - } - mAct.CompareResult = bmp; + mAct.CompareResult = bmp; - // Add output of mismatch - mAct.AddOrUpdateReturnParamActual("Mismatch elements in target", listwithnomatch.Count() + ""); + // Add output of mismatch + mAct.AddOrUpdateReturnParamActual("Mismatch elements in target", listwithnomatch.Count() + ""); - //TODO: if output each mismatch then do output + //TODO: if output each mismatch then do output - mAct.AddScreenShot(bmp, "Compare Result"); + mAct.AddScreenShot(bmp, "Compare Result"); + //TODO: add small bitmap of mismatch elem - //TODO: add small bitmap of mismatch elem + } } } diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 115e50374c..515f75a8b4 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -684,7 +684,7 @@ public override void StartDriver() ieOptions.IgnoreZoomLevel = true; driverService = InternetExplorerDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = HideConsoleWindow; - Driver = new InternetExplorerDriver((InternetExplorerDriverService)driverService, ieOptions, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut))); + Driver = new InternetExplorerDriver((InternetExplorerDriverService)driverService, ieOptions, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut))); } else @@ -1546,8 +1546,7 @@ private void ScreenshotHandler(ActScreenShot act) } else if (act.WindowsToCapture == Act.eWindowsToCapture.FullPage) { - Bitmap img = GetScreenShot(true); - act.AddScreenShot(img, Driver.Title); + AddScreenshotIntoAct(act,true); } else if (act.WindowsToCapture == Act.eWindowsToCapture.FullPageWithUrlAndTimestamp) { @@ -1579,21 +1578,42 @@ private void ScreenshotHandler(ActScreenShot act) private void TakeFullPageWithDesktopScreenScreenShot(Act act) { List bitmapsToMerge = new(); - Bitmap browserHeaderScreenshot = GetBrowserHeaderScreenShot(); - if (browserHeaderScreenshot != null) + try { - bitmapsToMerge.Add(browserHeaderScreenshot); - } + using (Bitmap browserHeaderScreenshot = GetBrowserHeaderScreenShot()) + { + if (browserHeaderScreenshot != null) + { + bitmapsToMerge.Add(browserHeaderScreenshot); + } + } - Bitmap browserFullPageScreenshot = GetScreenShot(true); - bitmapsToMerge.Add(browserFullPageScreenshot); - Bitmap taskbarScreenshot = TargetFrameworkHelper.Helper.GetTaskbarScreenshot(); - bitmapsToMerge.Add(taskbarScreenshot); + using (Bitmap browserFullPageScreenshot = GetScreenShot(true)) + { + if (browserFullPageScreenshot != null) + { + bitmapsToMerge.Add(browserFullPageScreenshot); + } + } - string filepath = TargetFrameworkHelper.Helper.MergeVerticallyAndSaveBitmaps(bitmapsToMerge.ToArray()); - act.ScreenShotsNames.Add(Driver.Title); - act.ScreenShots.Add(filepath); + using (Bitmap taskbarScreenshot = TargetFrameworkHelper.Helper.GetTaskbarScreenshot()) + { + if (taskbarScreenshot != null) + { + bitmapsToMerge.Add(taskbarScreenshot); + } + } + + string filepath = TargetFrameworkHelper.Helper.MergeVerticallyAndSaveBitmaps(bitmapsToMerge.ToArray()); + + act.ScreenShotsNames.Add(Driver.Title); + act.ScreenShots.Add(filepath); + } + finally + { + bitmapsToMerge.Clear(); + } } private Bitmap GetBrowserHeaderScreenShot() @@ -1631,7 +1651,7 @@ private Bitmap GetBrowserHeaderScreenShot() private void AddCurrentScreenShot(ActScreenShot act) { Screenshot ss = ((ITakesScreenshot)Driver).GetScreenshot(); - act.AddScreenShot(ss.AsByteArray, Driver.Title); + act.AddScreenShot(ss.AsByteArray, Driver.Title); } @@ -8785,6 +8805,46 @@ public Bitmap GetScreenShot(bool IsFullPageScreenshot = false) return bitmapImage; } + + public void AddScreenshotIntoAct(ActScreenShot act,bool IsFullPageScreenshot = false) + { + + if (!IsFullPageScreenshot) + { + // return screenshot of what's visible currently in the viewport + var screenshot = ((ITakesScreenshot)Driver).GetScreenshot(); + act.AddScreenShot(screenshot.AsByteArray, Driver.Title); + } + switch (mBrowserTpe) + { + case eBrowserType.FireFox: + var screenShot = ((FirefoxDriver)Driver).GetFullPageScreenshot(); + act.AddScreenShot(screenShot.AsByteArray, Driver.Title); + break; + case eBrowserType.Edge: + case eBrowserType.Chrome: + if (Driver is InternetExplorerDriver) + { + using (Bitmap bitmapImage = CaptureFullPageScreenshot()) + { + act.AddScreenShot(bitmapImage, Driver.Title); + } + } + else + { + var screenshot = ((OpenQA.Selenium.Chromium.ChromiumDriver)Driver).GetFullPageScreenshot(); + act.AddScreenShot(screenshot.AsByteArray, Driver.Title); + } + break; + default: + using (Bitmap bitmapImage = CaptureFullPageScreenshot()) + { + act.AddScreenShot(bitmapImage, Driver.Title); + } + break; + } + } + private Bitmap ScreenshotToImage(Screenshot screenshot) { TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); From 3225f37add1ea7739b90b0d4e383c3f4e47d15e5 Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 5 Jan 2024 19:53:22 +0530 Subject: [PATCH 07/10] Review comment Resolved --- .../WindowExplorer/Common/WindowExplorerPage.xaml.cs | 5 ++--- .../Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs b/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs index e96e5ff954..9d0dbaea48 100644 --- a/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs +++ b/Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs @@ -1119,8 +1119,7 @@ public void ShowScreenShot() /// UnComment later after complete Implementation of functionalities over all platforms. //if(IsWebMobJavaPlatform) - mWindowExplorerDriver.UnHighLightElements(); - + mWindowExplorerDriver.UnHighLightElements(); try { LoadPageSourceDoc = mWindowExplorerDriver.SupportedViews().Contains(eTabView.PageSource); @@ -1135,7 +1134,7 @@ public void ShowScreenShot() mScreenShotViewPage = new ScreenShotViewPage("", ScreenShotBitmap, (mWindowExplorerDriver as DriverBase).ScreenShotInitialZoom()); mScreenShotViewPage.ImageMouseCursor = Cursors.Hand; - /// UnComment to allow Element detection on hover + ///TODO UnComment to allow Element detection on hover //if (mPlatform.PlatformType() == ePlatformType.Web) //{ // mScreenShotViewPage.xMainImage.MouseMove += XMainImage_MouseMove; diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 515f75a8b4..60ceacd330 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -1610,6 +1610,11 @@ private void TakeFullPageWithDesktopScreenScreenShot(Act act) act.ScreenShotsNames.Add(Driver.Title); act.ScreenShots.Add(filepath); } + catch(Exception ex) + { + act.Error = "Failed to create Selenuim WebDriver browser page screenshot. Error= " + ex.Message; + return; + } finally { bitmapsToMerge.Clear(); From 6a5e73d5d513bf6241aaad45bfc102824271a5bb Mon Sep 17 00:00:00 2001 From: prashelke Date: Fri, 5 Jan 2024 20:14:25 +0530 Subject: [PATCH 08/10] Resolved Codacy issue --- Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs | 2 -- Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs | 2 -- 2 files changed, 4 deletions(-) diff --git a/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs b/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs index 17a7c80763..d1bd68e4c2 100644 --- a/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs +++ b/Ginger/GingerCore/Drivers/PBDriver/PBDriver.cs @@ -1254,8 +1254,6 @@ public bool CanStartAnotherInstance(out string errorMessage) /// Application Screenshot in Bitmap format public Bitmap GetScreenShot(Tuple setScreenSize = null, bool IsFullPageScreenshot = false) { - //Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - //return bmp; return mUIAutomationHelper.GetCurrentWindowBitmap(); } diff --git a/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs b/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs index 1de393304b..93c70c32e9 100644 --- a/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs +++ b/Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs @@ -1573,8 +1573,6 @@ private void HandleWindowsGenericWidgetControlAction(ActGenElement actWinC) public Bitmap GetScreenShot(Tuple setScreenSize = null, bool IsFullPageScreenshot = false) { - //Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); - //return bmp; return mUIAutomationHelper.GetCurrentWindowBitmap(); } From 9e5a9e917a60ba1a80c0ef8e7108b0c7ece86f27 Mon Sep 17 00:00:00 2001 From: prashelke Date: Tue, 9 Jan 2024 16:36:58 +0530 Subject: [PATCH 09/10] Screen-shot Optimization related changes --- Ginger/GingerCoreCommon/Actions/Act.cs | 12 +++++++-- .../DiameterLib/DiameterUtils.cs | 25 ++++++++++++++++--- .../Mobile/Appium/GenericAppiumDriver.cs | 22 ++++++++++++---- Ginger/GingerCoreNET/GeneralLib/General.cs | 7 +++++- .../PlatformsInfo/Webserviceplatforminfo.cs | 1 + .../GingerCoreNET/RunLib/CLILib/CLIHelper.cs | 20 +++++++-------- 6 files changed, 66 insertions(+), 21 deletions(-) diff --git a/Ginger/GingerCoreCommon/Actions/Act.cs b/Ginger/GingerCoreCommon/Actions/Act.cs index 46cb52b5e2..b64f65fcdf 100644 --- a/Ginger/GingerCoreCommon/Actions/Act.cs +++ b/Ginger/GingerCoreCommon/Actions/Act.cs @@ -1002,9 +1002,10 @@ public void AddScreenShot(Bitmap bmp, string Name = "") public void AddScreenShot(string Base64String, string Name = "") { + byte[] bytes = Convert.FromBase64String(Base64String); try { - byte[] bytes = Convert.FromBase64String(Base64String); + string filePath = GetScreenShotRandomFileName(); using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) { @@ -1019,9 +1020,12 @@ public void AddScreenShot(string Base64String, string Name = "") Error = "Failed to save the screenshot bitmap to temp file. Error= " + ex.Message; Reporter.ToLog(eLogLevel.ERROR, Error, ex); } + finally + { + Array.Clear(bytes); + } } - public void AddScreenShot(byte[] bytes, string Name) { try @@ -1038,6 +1042,10 @@ public void AddScreenShot(byte[] bytes, string Name) { Error += "Unable to add Screen shot " + ex.Message; } + finally + { + Array.Clear(bytes); + } } diff --git a/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs b/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs index c269f0da20..845524ab33 100644 --- a/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs +++ b/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs @@ -587,13 +587,14 @@ private byte[] ConvertMessageToBytes() } private bool ConvertMessageAvpListToBytes(MemoryStream memoryStream) { + byte[] avpAsBytes = null; Reporter.ToLog(eLogLevel.DEBUG, $"Starting to convert avp list into bytes"); try { foreach (DiameterAVP avp in Message.AvpList) { - byte[] avpAsBytes = ConvertAvpToBytes(avp); + avpAsBytes = ConvertAvpToBytes(avp); if (avpAsBytes != null) { Reporter.ToLog(eLogLevel.DEBUG, $"Converted AVP {avp.Name} to bytes successfully"); @@ -612,6 +613,10 @@ private bool ConvertMessageAvpListToBytes(MemoryStream memoryStream) Reporter.ToLog(eLogLevel.ERROR, $"Failed to convert AVPs to bytes {ex.Message}{Environment.NewLine}{ex.StackTrace}"); return false; } + finally + { + Array.Clear(avpAsBytes); + } } private bool ConvertMessageEndToEndToBytes(MemoryStream memoryStream, int endToEndIdentifierOffset) { @@ -730,10 +735,11 @@ private byte GetCommandFlags(DiameterMessage message) } private void WriteInt32ToStream(MemoryStream stream, int value, int offset) { + byte[] bytes = System.BitConverter.GetBytes(value); try { Reporter.ToLog(eLogLevel.DEBUG, $"Writing value: {value} to memory stream"); - byte[] bytes = System.BitConverter.GetBytes(value); + WriteBytesToStream(stream, data: bytes, seekPosition: offset); } catch (InvalidOperationException ex) @@ -741,13 +747,18 @@ private void WriteInt32ToStream(MemoryStream stream, int value, int offset) Reporter.ToLog(eLogLevel.ERROR, $"Error while trying to write 4 bytes with value: {value} to memory stream. Error: {ex.Message}{Environment.NewLine}{ex.StackTrace}"); throw; } + finally + { + Array.Clear(bytes); + } } private void WriteThreeBytesToStream(MemoryStream stream, int value, int offset) { + byte[] bytes = System.BitConverter.GetBytes(value); try { Reporter.ToLog(eLogLevel.DEBUG, $"Writing value: {value} to memory stream"); - byte[] bytes = System.BitConverter.GetBytes(value); + WriteBytesToStream(stream, data: bytes, seekPosition: offset, offsetInData: 1, byteCount: 3); } catch (InvalidOperationException ex) @@ -755,6 +766,10 @@ private void WriteThreeBytesToStream(MemoryStream stream, int value, int offset) Reporter.ToLog(eLogLevel.ERROR, $"Error while trying to write 4 bytes with value: {value} to memory stream. Error: {ex.Message}{Environment.NewLine}{ex.StackTrace}"); throw; } + finally + { + Array.Clear(bytes); + } } private void WriteBytesToStream(MemoryStream stream, byte[] data, int seekPosition, int offsetInData = 0, int byteCount = 0) { @@ -774,6 +789,10 @@ private void WriteBytesToStream(MemoryStream stream, byte[] data, int seekPositi Reporter.ToLog(eLogLevel.ERROR, $"Error while trying to write bytes to memory stream. Error: {ex.Message}{Environment.NewLine}{ex.StackTrace}"); throw; } + finally + { + Array.Clear(data); + } } private byte[] ConvertAvpToBytes(DiameterAVP avp) { diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index f6d825638d..5343f83837 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -1094,14 +1094,26 @@ public bool isValidPhotoExtention(string photo) } public string CameraAndBarcodeSimulationRequest(Bitmap picture, ImageFormat format, string contentType, string fileName, string action) { - MemoryStream ms = new MemoryStream(); string encodeString = "0"; - if (picture != null) + Byte[] bytes = null; + try + { + using (MemoryStream ms = new MemoryStream()) + { + + if (picture != null) + { + picture.Save(ms, format); + bytes = ms.ToArray(); + encodeString = Convert.ToBase64String(bytes); + } + } + } + finally { - picture.Save(ms, format); - Byte[] bytes = ms.ToArray(); - encodeString = Convert.ToBase64String(bytes); + Array.Clear(bytes); } + Dictionary sensorSimulationMap = new Dictionary { { "uploadMedia", encodeString }, diff --git a/Ginger/GingerCoreNET/GeneralLib/General.cs b/Ginger/GingerCoreNET/GeneralLib/General.cs index b05a145e10..d60151f840 100644 --- a/Ginger/GingerCoreNET/GeneralLib/General.cs +++ b/Ginger/GingerCoreNET/GeneralLib/General.cs @@ -475,10 +475,11 @@ public static string RemoveSpecialCharactersInColumnHeader(string columnHeader) public static string CreateTempTextFile(string content) { + byte[] bytes = null; try { string filePath = System.IO.Path.GetTempFileName(); - byte[] bytes = System.Text.Encoding.Default.GetBytes(content); + bytes = System.Text.Encoding.Default.GetBytes(content); File.WriteAllBytes(filePath, bytes); return filePath; } @@ -487,6 +488,10 @@ public static string CreateTempTextFile(string content) Reporter.ToLog(eLogLevel.ERROR, "Failed to create temp text file", ex); return null; } + finally + { + Array.Clear(bytes); + } } public static byte[] ImageToByteArray(Image img, System.Drawing.Imaging.ImageFormat format) diff --git a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs index cb01e0c59f..18c22a531d 100644 --- a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs +++ b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs @@ -130,6 +130,7 @@ public static string SaveToFile(string fileType, string fileContent, string save { byte[] bytes = Encoding.Default.GetBytes(fileContent); File.WriteAllBytes(fullFileName, bytes); + Array.Clear(bytes); } } diff --git a/Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs b/Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs index 54161ee484..e74da870e9 100644 --- a/Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs +++ b/Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs @@ -492,7 +492,7 @@ private void SelectEnv() if (WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems().Any()) { mRunsetExecutor.RunsetExecutionEnvironment = WorkSpace.Instance.SolutionRepository.GetFirstRepositoryItem(); - Reporter.ToLog(eLogLevel.INFO, "Auto Selected the default Environment: '" + mRunsetExecutor.RunsetExecutionEnvironment.Name + "'"); + Reporter.ToLog(eLogLevel.INFO, $"Auto Selected the default Environment: '{ mRunsetExecutor.RunsetExecutionEnvironment.Name }'"); } else { @@ -516,7 +516,7 @@ private void DownloadSolutionFromSourceControl() internal void SetSourceControlBranch(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlBranch: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlBranch: '{ value }'"); WorkSpace.Instance.UserProfile.SolutionSourceControlBranch = value; } @@ -603,7 +603,7 @@ internal void SetEncryptionKey(string value) internal void PasswordEncrypted(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "PasswordEncrypted: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"PasswordEncrypted: '{ value }'"); string pswd = WorkSpace.Instance.UserProfile.SourceControlPass; if (value == "Y" || value == "true" || value == "True") { @@ -634,13 +634,13 @@ internal void SourceControlProxyPort(string value) WorkSpace.Instance.UserProfile.SolutionSourceControlConfigureProxy = true; } - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlProxyPort: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlProxyPort: '{ value }'"); WorkSpace.Instance.UserProfile.SolutionSourceControlProxyPort = value; } internal void SourceControlProxyServer(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlProxyServer: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlProxyServer: '{ value }'"); if (string.IsNullOrEmpty(value)) { WorkSpace.Instance.UserProfile.SolutionSourceControlConfigureProxy = false; @@ -659,7 +659,7 @@ internal void SourceControlProxyServer(string value) internal void SetSourceControlUser(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlUser: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlUser: '{ value }'"); if (WorkSpace.Instance.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && value == "") { value = "Test"; @@ -671,16 +671,16 @@ internal void SetSourceControlUser(string value) internal void SetSourceControlURL(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlUrl: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlUrl: '{ value }'"); if (WorkSpace.Instance.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.SVN) { if (!value.ToUpper().Contains("/SVN") && !value.ToUpper().Contains("/SVN/")) { - value = value + "svn/"; + value = $"{value}svn/"; } if (!value.ToUpper().EndsWith("/")) { - value = value + "/"; + value = $"{value}/"; } } WorkSpace.Instance.UserProfile.SourceControlURL = value; @@ -689,7 +689,7 @@ internal void SetSourceControlURL(string value) internal void SetSourceControlType(string value) { - Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlType: '" + value + "'"); + Reporter.ToLog(eLogLevel.DEBUG, $"Selected SourceControlType: '{ value }'"); if (value.Equals("GIT")) { WorkSpace.Instance.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.GIT; From ba67a56d88d071adec608ade06617482f235cdd6 Mon Sep 17 00:00:00 2001 From: prashelke Date: Tue, 9 Jan 2024 16:42:17 +0530 Subject: [PATCH 10/10] Review Code changes --- Ginger/GingerCoreCommon/Actions/Act.cs | 11 +++++++++-- Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs | 10 ++++++++-- .../CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs | 5 ++++- Ginger/GingerCoreNET/GeneralLib/General.cs | 5 ++++- .../Platforms/PlatformsInfo/Webserviceplatforminfo.cs | 5 ++++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Ginger/GingerCoreCommon/Actions/Act.cs b/Ginger/GingerCoreCommon/Actions/Act.cs index b64f65fcdf..30fbe40f0a 100644 --- a/Ginger/GingerCoreCommon/Actions/Act.cs +++ b/Ginger/GingerCoreCommon/Actions/Act.cs @@ -1022,7 +1022,11 @@ public void AddScreenShot(string Base64String, string Name = "") } finally { - Array.Clear(bytes); + if(bytes != null) + { + Array.Clear(bytes); + } + } } @@ -1044,7 +1048,10 @@ public void AddScreenShot(byte[] bytes, string Name) } finally { - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } } diff --git a/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs b/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs index 845524ab33..3e32754c0d 100644 --- a/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs +++ b/Ginger/GingerCoreNET/DiameterLib/DiameterUtils.cs @@ -749,7 +749,10 @@ private void WriteInt32ToStream(MemoryStream stream, int value, int offset) } finally { - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } } private void WriteThreeBytesToStream(MemoryStream stream, int value, int offset) @@ -768,7 +771,10 @@ private void WriteThreeBytesToStream(MemoryStream stream, int value, int offset) } finally { - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } } private void WriteBytesToStream(MemoryStream stream, byte[] data, int seekPosition, int offsetInData = 0, int byteCount = 0) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 5343f83837..f762a51003 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -1111,7 +1111,10 @@ public string CameraAndBarcodeSimulationRequest(Bitmap picture, ImageFormat form } finally { - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } Dictionary sensorSimulationMap = new Dictionary diff --git a/Ginger/GingerCoreNET/GeneralLib/General.cs b/Ginger/GingerCoreNET/GeneralLib/General.cs index d60151f840..3be982686f 100644 --- a/Ginger/GingerCoreNET/GeneralLib/General.cs +++ b/Ginger/GingerCoreNET/GeneralLib/General.cs @@ -490,7 +490,10 @@ public static string CreateTempTextFile(string content) } finally { - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } } diff --git a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs index 18c22a531d..74396207dd 100644 --- a/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs +++ b/Ginger/GingerCoreNET/Run/Platforms/PlatformsInfo/Webserviceplatforminfo.cs @@ -130,7 +130,10 @@ public static string SaveToFile(string fileType, string fileContent, string save { byte[] bytes = Encoding.Default.GetBytes(fileContent); File.WriteAllBytes(fullFileName, bytes); - Array.Clear(bytes); + if (bytes != null) + { + Array.Clear(bytes); + } } }