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

Feature - Import katalon object repository #3971

Merged
merged 8 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Introduction
Import Katalon Object-Repositories as Ginger Page Object Models.

You need to select the folder containing the Katalon Object-Repositories.
You will be shown the list of Page Object Models that will be imported.
You can provide the Target Application and URL for each Page Object Model.
Clicking on 'Finish' will import the Page Object Models.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Repository;
using Ginger.WizardLib;
using GingerWPF.WizardLib;
using System.ComponentModel;

namespace Ginger.External.Katalon
{
public sealed class ImportKatalonObjectRepositoryWizard : WizardBase, INotifyPropertyChanged
{
private readonly RepositoryFolder<ApplicationPOMModel> _importTargetDirectory;

private string _selectedDirectory;

public ObservableList<KatalonConvertedPOMViewModel> POMViewModels { get; }


public string SelectedDirectory
{
get => _selectedDirectory;
set
{
_selectedDirectory = value;
PropertyChanged?.Invoke(sender: this, new PropertyChangedEventArgs(propertyName: nameof(SelectedDirectory)));
}
}

public override string Title => "Import POM From Katalon Object-Repository";

public event PropertyChangedEventHandler? PropertyChanged;

Check warning on line 30 in Ginger/Ginger/External/Katalon/ImportKatalonObjectRepositoryWizard.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/External/Katalon/ImportKatalonObjectRepositoryWizard.cs#L30

Remove the unused event 'PropertyChanged' or invoke it.

internal ImportKatalonObjectRepositoryWizard(RepositoryFolder<ApplicationPOMModel> importTargetDirectory)
{
_importTargetDirectory = importTargetDirectory;
POMViewModels = [];
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
_selectedDirectory = string.Empty;
AddPages();
}

private void AddPages()
{
AddPage(Name: "Introduction", Title: "Introduction", SubTitle: "Agents Introduction", Page: new WizardIntroPage("/External/Katalon/ImportKatalonObjectRepositoryIntro.md"));
AddPage(Name: "SelectFolder", Title: "Select Folder", SubTitle: "Select Object-Repository folder", Page: new SelectObjectRepositoryFolderWizardPage(wizard: this));
AddPage(Name: "ImportPOM", Title: "Import POM", SubTitle: "View imported POM list", new ImportPOMFromObjectRepositoryWizardPage(wizard: this));
}

public override void Finish()
{
foreach (KatalonConvertedPOMViewModel pomViewModel in POMViewModels)
{
if (!pomViewModel.Active)
{
continue;
}
pomViewModel.CommitChanges();
_importTargetDirectory.AddRepositoryItem(pomViewModel.POM);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Page x:Class="Ginger.External.Katalon.ImportPOMFromObjectRepositoryWizardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Ginger="clr-namespace:Ginger"
xmlns:GingerCore="clr-namespace:GingerCore;assembly=GingerCore"
xmlns:local="clr-namespace:Ginger.External.Katalon"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ImportPOMFromObjectRepositoryWizardPage">
<Page.Resources>
<DataTemplate
x:Key="TargetApplicationCellTemplate">
<ComboBox
SelectedValue="{Binding
Path=TargetApplication,
UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding TargetApplicationOptions}"
Style="{StaticResource $FlatEditInputComboBoxStyle}" />
</DataTemplate>
</Page.Resources>
<Grid
Background="{StaticResource $BackgroundColor_White}">
<Ginger:ucGrid
x:Name="ImportedPOMGrid"
ShowAdd="Collapsed"
ShowClearAll="Collapsed"
ShowRefresh="Collapsed"
ShowEdit="Collapsed"
ShowDelete="Collapsed"
ShowUpDown="Collapsed"
ShowTagsFilter="Collapsed">
<Ginger:ucGrid.Title>
Imported Application POM
</Ginger:ucGrid.Title>
</Ginger:ucGrid>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.Enums;
using Amdocs.Ginger.CoreNET.External.Katalon.Conversion;
using Ginger.UserControls;
using GingerWPF.WizardLib;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Ginger.External.Katalon
{
/// <summary>
/// Interaction logic for ImportPOMFromObjectRepositoryWizardPage.xaml
/// </summary>
public partial class ImportPOMFromObjectRepositoryWizardPage : Page, IWizardPage
{
private readonly ImportKatalonObjectRepositoryWizard _wizard;
private readonly ObservableList<KatalonObjectRepositoryToPOMConverter.Result> _conversionResults;

public ImportPOMFromObjectRepositoryWizardPage(ImportKatalonObjectRepositoryWizard wizard)
{
InitializeComponent();

_wizard = wizard;
_conversionResults = [];
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
_conversionResults.CollectionChanged += ConversionResults_CollectionChanged;

InitImportedPOMGrid();
}

private void InitImportedPOMGrid()
{
GridViewDef view = new(GridViewDef.DefaultViewName)
{
GridColsView =
[
new()
{
Field = nameof(KatalonConvertedPOMViewModel.Active),
Header = "Active",
WidthWeight = 10,
StyleType = GridColView.eGridColStyleType.CheckBox,
},
new()
{
Field = nameof(KatalonConvertedPOMViewModel.Name),
Header = "Name",
ReadOnly = true,
WidthWeight = 20,
StyleType = GridColView.eGridColStyleType.Text,
},
new()
{
Field = nameof(KatalonConvertedPOMViewModel.TargetApplication),
Header = "Target Application",
WidthWeight = 20,
StyleType = GridColView.eGridColStyleType.Template,
CellTemplate = (DataTemplate)FindResource("TargetApplicationCellTemplate"),
},
new()
{
Field = nameof(KatalonConvertedPOMViewModel.URL),
Header = "URL",
WidthWeight = 20,
StyleType = GridColView.eGridColStyleType.Text,
}
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
]
};

ImportedPOMGrid.AddToolbarTool(
"@CheckAllRow_16x16.png",
"Select All",
ImportedPOMGrid_Toolbar_SelectAllForSync);
ImportedPOMGrid.AddToolbarTool(
"@UnCheckAllRow_16x16.png",
"Unselect All",
ImportedPOMGrid_Toolbar_UnselectAllForSync);
ImportedPOMGrid.AddToolbarTool(
eImageType.Application,
"Set highlighted Target Application for all",
ImportedPOMGrid_Toolbar_SyncTargetApplication);
ImportedPOMGrid.AddToolbarTool(
eImageType.Browser,
"Set highlighted URL for all",
ImportedPOMGrid_Toolbar_SyncURL);

ImportedPOMGrid.SetAllColumnsDefaultView(view);
ImportedPOMGrid.InitViewItems();
ImportedPOMGrid.DataSourceList = _wizard.POMViewModels;
}

private void ImportedPOMGrid_Toolbar_SelectAllForSync(object? sender, RoutedEventArgs e)
{
IEnumerable<KatalonConvertedPOMViewModel> visibleItems = ImportedPOMGrid
.GetFilteredItems()
.Cast<KatalonConvertedPOMViewModel>();

foreach (KatalonConvertedPOMViewModel item in visibleItems)
{
item.Active = true;
}
}

private void ImportedPOMGrid_Toolbar_UnselectAllForSync(object? sender, RoutedEventArgs e)
{
IEnumerable<KatalonConvertedPOMViewModel> visibleItems = ImportedPOMGrid
.GetFilteredItems()
.Cast<KatalonConvertedPOMViewModel>();

foreach (KatalonConvertedPOMViewModel item in visibleItems)
{
item.Active = false;
}
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
}

private void ImportedPOMGrid_Toolbar_SyncTargetApplication(object? sender, RoutedEventArgs e)
{
IEnumerable<KatalonConvertedPOMViewModel> visibleItems = ImportedPOMGrid
.GetFilteredItems()
.Cast<KatalonConvertedPOMViewModel>();

KatalonConvertedPOMViewModel highlightedItem = (KatalonConvertedPOMViewModel)ImportedPOMGrid.CurrentItem;

foreach (KatalonConvertedPOMViewModel item in visibleItems)
{
if (!item.Active)
{
continue;
}

bool highlightedTargetAppIsValid = item
.TargetApplicationOptions
.Any(t => string.Equals(t, highlightedItem.TargetApplication));

if (highlightedTargetAppIsValid)
{
item.TargetApplication = highlightedItem.TargetApplication;
}
}
}

private void ImportedPOMGrid_Toolbar_SyncURL(object? sender, RoutedEventArgs e)
{
IEnumerable<KatalonConvertedPOMViewModel> visibleItems = ImportedPOMGrid
.GetFilteredItems()
.Cast<KatalonConvertedPOMViewModel>();

KatalonConvertedPOMViewModel highlightedItem = (KatalonConvertedPOMViewModel)ImportedPOMGrid.CurrentItem;

foreach (KatalonConvertedPOMViewModel item in visibleItems)
{
if (!item.Active)
{
continue;
}

item.URL = highlightedItem.URL;
}
}

public void WizardEvent(WizardEventArgs e)
{
switch (e.EventType)

Check failure on line 167 in Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml.cs#L167

Add a 'default' clause to this 'switch' statement.

Check notice on line 167 in Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml.cs#L167

Replace this 'switch' statement with 'if' statements to increase readability.
{
case EventType.Active:
_ = ImportPOMsAsync();
break;
}
}

private async Task ImportPOMsAsync()
{
try
{
_wizard.POMViewModels.ClearAll();
_conversionResults.ClearAll();
ImportedPOMGrid.DisableGridColoumns();
await KatalonObjectRepositoryToPOMConverter.ConvertAsync(_wizard.SelectedDirectory, _conversionResults);
ImportedPOMGrid.EnableGridColumns();
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Error while importing Katalon Object-Repository as Ginger POM", ex);
}
}

private void ConversionResults_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action != NotifyCollectionChangedAction.Add)
{
return;
}

if (e.NewItems == null ||
e.NewItems.Count <= 0 ||
e.NewItems[0] is not KatalonObjectRepositoryToPOMConverter.Result conversionResult)
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

_wizard.POMViewModels.Add(new(conversionResult.POM, conversionResult.Platform));
}
}
}
Loading
Loading