Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix/39866 TA selecting in POM Page #4029

Open
wants to merge 6 commits into
base: Releases/Official-Release
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 99 additions & 18 deletions Ginger/Ginger/ApplicationModelsLib/POMModels/POMEditPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.UIElement;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Mobile;
using Amdocs.Ginger.Repository;
using Ginger.Actions.UserControls;
using Ginger.Agents;
Expand Down Expand Up @@ -67,7 +68,7 @@ public Agent Agent
set
{
mAgent = value;
mPomAllElementsPage.SetAgent(mAgent);
mPomAllElementsPage?.SetAgent(mAgent);
if (mAgent != null)
{
mPOM.LastUsedAgent = mAgent.Guid;
Expand Down Expand Up @@ -121,16 +122,34 @@ public POMEditPage(ApplicationPOMModel POM, eRIPageViewMode editMode, bool ignor
xPageURLTextBox.Init(null, mPOM, nameof(mPOM.PageURL));

xTAlabel.Content = $"{GingerDicser.GetTermResValue(eTermResKey.TargetApplication)}:";

mAppPlatform = WorkSpace.Instance.Solution.GetTargetApplicationPlatform(POM.TargetApplicationKey);
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xAgentControlUC, ucAgentControl.SelectedAgentProperty, this, nameof(Agent));
ObservableList<Agent> optionalAgentsList = SupportedAgents();
foreach (Agent agent in optionalAgentsList)
{
if (agent.AgentOperations == null)
{
AgentOperations agentOperations = new AgentOperations(agent);
agent.AgentOperations = agentOperations;
}
}
if (DefaultAgentGuid == null)
{
xAgentControlUC.Init(optionalAgentsList, mPOM.LastUsedAgent);
}
else
{
xAgentControlUC.Init(optionalAgentsList, (Guid)DefaultAgentGuid);
}
FillTargetAppsComboBox();
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xTargetApplicationComboBox, ComboBox.SelectedValueProperty, mPOM, nameof(ApplicationPOMModel.TargetApplicationKey));
xTagsViewer.Init(mPOM.TagsKeys);

BitmapSource source = null;
if (mPOM.ScreenShotImage != null)
{
source = Ginger.General.GetImageStream(Ginger.General.Base64StringToImage(mPOM.ScreenShotImage.ToString()));
}

mScreenShotViewPage = new ScreenShotViewPage(mPOM.Name, source);
xScreenShotFrame.ClearAndSetContent(mScreenShotViewPage);

Expand All @@ -140,16 +159,7 @@ public POMEditPage(ApplicationPOMModel POM, eRIPageViewMode editMode, bool ignor

UIElementTabTextBlockUpdate();

mAppPlatform = WorkSpace.Instance.Solution.GetTargetApplicationPlatform(POM.TargetApplicationKey);
ObservableList<Agent> optionalAgentsList = GingerCore.General.ConvertListToObservableList((from x in WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems<Agent>() where x.Platform == mAppPlatform select x).ToList());
foreach (Agent agent in optionalAgentsList)
{
if (agent.AgentOperations == null)
{
AgentOperations agentOperations = new AgentOperations(agent);
agent.AgentOperations = agentOperations;
}
}

GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xAgentControlUC, ucAgentControl.SelectedAgentProperty, this, nameof(Agent));
xAgentControlUC.Init(optionalAgentsList, mPOM.LastUsedAgent);

Expand Down Expand Up @@ -218,27 +228,98 @@ private void FillTargetAppsComboBox()
Reporter.ToUser(eUserMsgKey.MissingTargetApplication, "The mapped " + mPOM.Key.ItemName + " Target Application was not found, please select new Target Application");
}
}
SupportedTargetApplication();
xTargetApplicationComboBox.SelectedValuePath = nameof(ApplicationPlatform.Key);
xTargetApplicationComboBox.DisplayMemberPath = nameof(ApplicationPlatform.AppName);
CollectionChangedEventManager.AddHandler(source: WorkSpace.Instance.Solution.ApplicationPlatforms, handler: ApplicationPlatforms_CollectionChanged);

}
/// <summary>
/// Sets the supported target applications for the current POM based on the agent's configuration and platform type.
/// </summary>
private void SupportedTargetApplication()
{
xTargetApplicationComboBox.ItemsSource = null;
var targetPlatform = WorkSpace.Instance.Solution.GetTargetApplicationPlatform(mPOM.TargetApplicationKey);

if (targetPlatform != ePlatformType.NA)
{
xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.ApplicationPlatforms.Where(x => x.Platform == targetPlatform).ToList();
if (targetPlatform == ePlatformType.Mobile && MobileWebApptypeFlag)
{
xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.ApplicationPlatforms.Where(x => x.Platform is ePlatformType.Mobile or ePlatformType.Web).ToList();
}
else
{
xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.ApplicationPlatforms.Where(x => x.Platform == targetPlatform).ToList();
}
}
else
{
xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.ApplicationPlatforms.Where(x => ApplicationPOMModel.PomSupportedPlatforms.Contains(x.Platform)).ToList();
}
}

xTargetApplicationComboBox.SelectedValuePath = nameof(ApplicationPlatform.Key);
xTargetApplicationComboBox.DisplayMemberPath = nameof(ApplicationPlatform.AppName);
CollectionChangedEventManager.AddHandler(source: WorkSpace.Instance.Solution.ApplicationPlatforms, handler: ApplicationPlatforms_CollectionChanged);
private bool MobileWebApptypeFlag = false;
private Guid? DefaultAgentGuid;
/// <summary>
/// Returns a list of supported agents based on the application platform and agent type.
/// </summary>
/// <returns>ObservableList of supported agents.</returns>
private ObservableList<Agent> SupportedAgents()
{
ObservableList<Agent> optionalAgentsList;

var agents = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems<Agent>();

if (mAppPlatform == ePlatformType.Mobile && MobileAgentAppTypeValidation())
{
optionalAgentsList = GingerCore.General.ConvertListToObservableList(agents.Where(x => x.Platform is ePlatformType.Mobile or ePlatformType.Web).ToList());
}
else
{
optionalAgentsList = GingerCore.General.ConvertListToObservableList(agents.Where(x => x.Platform == mAppPlatform).ToList());
}

return optionalAgentsList;
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Validates if the last used agent is of type Web for Mobile platform.
/// </summary>
/// <returns>True if the last used agent is of type Web, otherwise false.</returns>
private bool MobileAgentAppTypeValidation()
{
MobileWebApptypeFlag = false;
DefaultAgentGuid = null;

var lastAgentID = mPOM.LastUsedAgent;
var agents = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems<Agent>();
var lastUsedAgent = mAgent ?? agents.FirstOrDefault(x => x.Guid == lastAgentID);
bool isDefaultUsed = false;

if (lastUsedAgent == null)
{
lastUsedAgent = agents.FirstOrDefault(x => x.Platform == mAppPlatform);
isDefaultUsed = true;
}

if (lastUsedAgent != null)
{
var appType = lastUsedAgent.DriverConfiguration
.FirstOrDefault(p => string.Equals(p.Parameter, "AppType", StringComparison.OrdinalIgnoreCase))?.Value ?? string.Empty;
MobileWebApptypeFlag = string.Equals(appType, eAppType.Web.ToString(), StringComparison.OrdinalIgnoreCase);

if (isDefaultUsed && MobileWebApptypeFlag)
{
DefaultAgentGuid = lastUsedAgent.Guid;
}
}

return MobileWebApptypeFlag;
}
private void ApplicationPlatforms_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.ApplicationPlatforms.Where(x => ApplicationPOMModel.PomSupportedPlatforms.Contains(x.Platform)).ToList();
SupportedTargetApplication();
}

private void xTargetApplicationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
Loading