-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
685 additions
and
53 deletions.
There are no files selected for viewing
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
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 System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.AutoFill | ||
{ | ||
public class PwAutoFill | ||
{ | ||
public static TPage InitializePage<TPage>(IPage page) | ||
where TPage : PwPageBase | ||
{ | ||
var newPage = (TPage)Activator.CreateInstance(typeof(TPage), page)!; | ||
InitializeControls(newPage, newPage.Page, null); | ||
return newPage; | ||
} | ||
|
||
public static void InitializeControls(object instance, IPage page, ILocator? parent) | ||
{ | ||
var properties = instance | ||
.GetType() | ||
.GetProperties(BindingFlags.Instance | BindingFlags.Public) | ||
.Where(p => p.CanWrite && typeof(PwControlBase).IsAssignableFrom(p.PropertyType) && !p.GetCustomAttributes<SkipAutoFillAttribute>().Any()); | ||
|
||
foreach (var property in properties) | ||
{ | ||
var locator = LocatorForProperty(property, page, parent); | ||
var value = Activator.CreateInstance(property.PropertyType, locator)!; | ||
InitializeControls(value, page, locator); | ||
property.SetValue(instance, value); | ||
} | ||
} | ||
|
||
public static ILocator LocatorForProperty(PropertyInfo property, IPage page, ILocator? parent) | ||
{ | ||
var selector = property | ||
.GetCustomAttributes<SelectorAttribute>() | ||
.Select(x => x.Selector.ToString()) | ||
.FirstOrDefault(); | ||
|
||
if (string.IsNullOrEmpty(selector)) | ||
return GetByTestId(page, parent, property.Name); | ||
|
||
var selectors = selector.Split(" ", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); | ||
return selectors | ||
.Aggregate( | ||
parent, | ||
(current, s) => s.StartsWith("##") | ||
? GetByTestId(page, current, s[2..]) | ||
: GetLocator(page, current, s) | ||
)!; | ||
} | ||
|
||
private static ILocator GetByTestId(IPage page, ILocator? parent, string tid) => parent == null ? page.GetByTestId(tid) : parent.GetByTestId(tid); | ||
private static ILocator GetLocator(IPage page, ILocator? parent, string loc) => parent == null ? page.Locator(loc) : parent.Locator(loc); | ||
} | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
DbViewer.Tests/FrontTests/Controls/BusinessObjectFilter.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,28 @@ | ||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.Pages; | ||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
using SKBKontur.SeleniumTesting.Controls; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.Controls | ||
{ | ||
public class BusinessObjectFilter : PwControlBase | ||
{ | ||
public BusinessObjectFilter(ILocator locator) | ||
: base(locator) | ||
{ | ||
} | ||
|
||
public PwLabel FormCaption { get; set; } | ||
public Select OperatorSelect { get; set; } | ||
public Select EnumSelect { get; set; } | ||
public Select BooleanSelect { get; set; } | ||
public PwInput Input { get; set; } | ||
public Validation InputValidation { get; set; } | ||
public Validation DateTimeValidation { get; set; } | ||
public DatePicker Date { get; set; } | ||
public PwInput Time { get; set; } | ||
public PwInput DateTimeInTicks { get; set; } | ||
} | ||
} |
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,21 @@ | ||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.AutoFill; | ||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.Controls | ||
{ | ||
public class BusinessObjectGroup : PwControlBase | ||
{ | ||
public BusinessObjectGroup(ILocator locator) | ||
: base(locator) | ||
{ | ||
} | ||
|
||
public PwLabel Name { get; set; } | ||
public PwLabel IndexedLabel { get; set; } | ||
|
||
[Selector("##ObjectsList ##ObjectItem")] | ||
public PwControlList<BusinessObjectItem> ObjectsList { get; set; } | ||
} | ||
} |
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,16 @@ | ||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.Controls | ||
{ | ||
public class BusinessObjectItem : PwControlBase | ||
{ | ||
public BusinessObjectItem(ILocator locator) | ||
: base(locator) | ||
{ | ||
} | ||
|
||
public PwLink ObjectLink { get; set; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
DbViewer.Tests/FrontTests/Controls/BusinessObjectTableRow.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,25 @@ | ||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.Controls | ||
{ | ||
public class BusinessObjectTableRow : PwControlBase | ||
{ | ||
public BusinessObjectTableRow(ILocator locator) | ||
: base(locator) | ||
{ | ||
} | ||
|
||
public PwLink Details { get; set; } | ||
public PwLink Delete { get; set; } | ||
public PwLabel Id { get; set; } | ||
public PwLabel ScopeId { get; set; } | ||
|
||
public PwLabel FindColumn(string tid) | ||
{ | ||
return null; | ||
// return this.Find<Label>().ByTid(tid); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Playwright; | ||
|
||
using SkbKontur.DbViewer.Tests.FrontTests.AutoFill; | ||
using SkbKontur.DbViewer.Tests.FrontTests.Playwright; | ||
|
||
using SKBKontur.SeleniumTesting.Controls; | ||
|
||
namespace SkbKontur.DbViewer.Tests.FrontTests.Controls | ||
{ | ||
public class FilterModal : PwControlBase | ||
{ | ||
public FilterModal(ILocator locator) | ||
: base(locator) | ||
{ | ||
} | ||
|
||
public Task<BusinessObjectFilter> GetFilter(string name) | ||
{ | ||
return ObjectFilters.Where(x => x.Locator.Page.GetByTestId(name)).Single(); | ||
} | ||
|
||
[Selector("##ObjectFilters ##Filter")] | ||
public PwControlList<BusinessObjectFilter> ObjectFilters { get; set; } | ||
|
||
public Button Apply { get; set; } | ||
public PwLink Clear { get; set; } | ||
public PwInput Id { get; set; } | ||
public PwInput ScopeId { get; set; } | ||
} | ||
} |
Oops, something went wrong.