Skip to content

Commit

Permalink
Merge branch 'master' into Enhancement/LiteDBUpgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Maheshkale447 committed Jan 9, 2024
2 parents 815b597 + ed2fb3a commit c7f643b
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1130,22 +1129,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;
///TODO 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)
{
Expand Down
13 changes: 8 additions & 5 deletions Ginger/Ginger/UserControlsLib/UCListView/UcListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,15 @@ 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();
}
}
});
}
Expand Down
25 changes: 24 additions & 1 deletion Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ public ObservableList<OptionalValue> GetListOfParamEnums(SwaggerParameter swagge
return lstOptions;
}


public void SetOptionalValue(ObservableList<AppModelParameter> AppModelParameters, Dictionary<string, string> listExampleValues)
{
if (AppModelParameters.Count > 0)
{
foreach (var item in AppModelParameters)
{
string parameterName = (item.ElementName.TrimStart('<', '{','[').TrimEnd('>', '}',']')).ToLower();

if (!string.IsNullOrEmpty(parameterName) && listExampleValues.TryGetValue(parameterName, out string exampleValue))
{
ObservableList<OptionalValue> tempList = new ObservableList<OptionalValue>
{
new OptionalValue()
{
Value = exampleValue,
IsDefault = true
}
};

item.OptionalValuesList = tempList;
}
}
}
}
}
}
54 changes: 50 additions & 4 deletions Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/OpenApiVer3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -40,8 +42,6 @@ public ObservableList<ApplicationAPIModel> OpenApiThree(SwaggerDocument Swaggerd
{

opendoc = Swaggerdoc;



foreach (var paths in opendoc.Paths)
{
Expand All @@ -56,6 +56,7 @@ public ObservableList<ApplicationAPIModel> OpenApiThree(SwaggerDocument Swaggerd
{

ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key,opendoc);
SetOptionalValue(basicModal.AppModelParameters,GetExamplesFromOpenApiComponents(opendoc.Components));
SwaggerModels.Add(basicModal);
GenerateResponse(Operation, basicModal);
}
Expand Down Expand Up @@ -90,7 +91,8 @@ public ObservableList<ApplicationAPIModel> 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";
AAM.Name += "-JSON";
AAM.Description = "Body Type is JSON";
}

break;
Expand All @@ -110,6 +112,8 @@ public ObservableList<ApplicationAPIModel> OpenApiThree(SwaggerDocument Swaggerd
break;

}

SetOptionalValue(AAM.AppModelParameters, GetExamplesFromOpenApiComponents(opendoc.Components));
}
GenerateResponse(Operation, AAM);
SwaggerModels.Add(AAM);
Expand All @@ -124,7 +128,49 @@ public ObservableList<ApplicationAPIModel> OpenApiThree(SwaggerDocument Swaggerd
return SwaggerModels;
}


public static Dictionary<string, string> GetExamplesFromOpenApiComponents(OpenApiComponents apiComponents)
{

Dictionary<string, string> exampleValues = new Dictionary<string, string>();
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.ERROR, "Example values could not be fetched, please check the API", ex);
}

return exampleValues;
}

}
}
50 changes: 50 additions & 0 deletions Ginger/GingerAutoPilot/APIModelLib/SwaggerApi/SwaggerVer2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SwaggerVer2 : OpenApiBase
public ObservableList<ApplicationAPIModel> SwaggerTwo(SwaggerDocument Swaggerdoc, ObservableList<ApplicationAPIModel> SwaggerModels)
{
swagTwo = Swaggerdoc;

foreach (var paths in swagTwo.Paths)
{
SwaggerPathItem SPi = paths.Value;
Expand All @@ -49,6 +50,7 @@ public ObservableList<ApplicationAPIModel> SwaggerTwo(SwaggerDocument Swaggerdoc
{

ApplicationAPIModel basicModal = GenerateBasicModel(Operation, so.Key, ref supportBody, paths.Key, swagTwo);
SetOptionalValue(basicModal.AppModelParameters, GetExamplesFromDefinitions(swagTwo));
SwaggerModels.Add(basicModal);
GenerateResponse(Operation, basicModal);
}
Expand Down Expand Up @@ -106,6 +108,8 @@ public ObservableList<ApplicationAPIModel> SwaggerTwo(SwaggerDocument Swaggerdoc
break;

}

SetOptionalValue(AAM.AppModelParameters, GetExamplesFromDefinitions(swagTwo));
}
GenerateResponse(Operation, AAM);
SwaggerModels.Add(AAM);
Expand Down Expand Up @@ -162,6 +166,8 @@ public ObservableList<ApplicationAPIModel> SwaggerTwo(SwaggerDocument Swaggerdoc
break;

}

SetOptionalValue(AAM.AppModelParameters, GetExamplesFromDefinitions(swagTwo));
}
GenerateResponse(Operation, AAM);

Expand All @@ -176,6 +182,50 @@ public ObservableList<ApplicationAPIModel> SwaggerTwo(SwaggerDocument Swaggerdoc
}
return SwaggerModels;
}
public static Dictionary<string, string> GetExamplesFromDefinitions(SwaggerDocument apidoc)
{

Dictionary<string, string> exampleValues = new Dictionary<string, string>();
try
{
if (apidoc.Definitions != null && apidoc.Definitions.Count != 0)
{
foreach (var schemaEntry in apidoc.Definitions)
{
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.ToLower();
var actualDefinition = item.Value.Example?.ToString();
if (actualDefinition != null && !exampleValues.ContainsKey(actualName.ToLower()))
{

exampleValues.Add(actualName,actualDefinition.ToString());
}

}
}
else if (schemaDefinition.Example != null)
{
if (!exampleValues.ContainsKey(schemaName.ToLower()))
{
exampleValues.Add(schemaName.ToLower(), schemaDefinition.Example.ToString());
}
}
}
}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Example values could not be fetched, please check the API", ex);
}

return exampleValues;
}

}
}
29 changes: 29 additions & 0 deletions Ginger/GingerAutoPilotTest/SwaggetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ApplicationAPIModel> requests = new ObservableList<ApplicationAPIModel>();
ObservableList<OptionalValue> optionalValueContainer;
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"));
}
}
}
25 changes: 10 additions & 15 deletions Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AppWindow> GetCurrentAppWindows()
Expand All @@ -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)
{
Expand Down Expand Up @@ -4929,27 +4929,22 @@ public override List<Bitmap> 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<Bitmap> winPopup = new List<Bitmap>();
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;
}

Expand Down
Loading

0 comments on commit c7f643b

Please sign in to comment.