-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3971 from Ginger-Automation/Feature/ImportKatalon…
…ObjectRepository Feature - Import katalon object repository
- Loading branch information
Showing
20 changed files
with
1,628 additions
and
4 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Ginger/Ginger/External/Katalon/ImportKatalonObjectRepositoryIntro.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
60 changes: 60 additions & 0 deletions
60
Ginger/Ginger/External/Katalon/ImportKatalonObjectRepositoryWizard.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
internal ImportKatalonObjectRepositoryWizard(RepositoryFolder<ApplicationPOMModel> importTargetDirectory) | ||
{ | ||
_importTargetDirectory = importTargetDirectory; | ||
POMViewModels = []; | ||
_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); | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
210 changes: 210 additions & 0 deletions
210
Ginger/Ginger/External/Katalon/ImportPOMFromObjectRepositoryWizardPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
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 = []; | ||
_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, | ||
} | ||
] | ||
}; | ||
|
||
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; | ||
} | ||
} | ||
|
||
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) | ||
{ | ||
case EventType.Active: | ||
_ = ImportPOMsAsync(); | ||
break; | ||
default: | ||
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) | ||
{ | ||
return; | ||
} | ||
|
||
_wizard.POMViewModels.Add(new(conversionResult.POM, conversionResult.Platform)); | ||
} | ||
} | ||
} |
Oops, something went wrong.