diff --git a/DbViewer.Tests/DbViewer.Tests.csproj b/DbViewer.Tests/DbViewer.Tests.csproj index bc0b37ad..7025c767 100644 --- a/DbViewer.Tests/DbViewer.Tests.csproj +++ b/DbViewer.Tests/DbViewer.Tests.csproj @@ -10,6 +10,7 @@ + diff --git a/DbViewer.Tests/FrontTests/AutoFill/PwAutoFill.cs b/DbViewer.Tests/FrontTests/AutoFill/PwAutoFill.cs new file mode 100644 index 00000000..643b9add --- /dev/null +++ b/DbViewer.Tests/FrontTests/AutoFill/PwAutoFill.cs @@ -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(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().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() + .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); + } +} \ No newline at end of file diff --git a/DbViewer.Tests/FrontTests/BusinessObjectsSearchTests.cs b/DbViewer.Tests/FrontTests/BusinessObjectsSearchTests.cs index db4f32b9..dae6f944 100644 --- a/DbViewer.Tests/FrontTests/BusinessObjectsSearchTests.cs +++ b/DbViewer.Tests/FrontTests/BusinessObjectsSearchTests.cs @@ -1,7 +1,9 @@ -using NUnit.Framework; +using System.Threading.Tasks; + +using NUnit.Framework; -using SkbKontur.DbViewer.Tests.FrontTests.Helpers; using SkbKontur.DbViewer.Tests.FrontTests.Pages; +using SkbKontur.DbViewer.Tests.FrontTests.Playwright; namespace SkbKontur.DbViewer.Tests.FrontTests { @@ -12,46 +14,52 @@ public class BusinessObjectsSearchTests /// Вводим в строке поиска запрос в R# стиле, проверяем ожидаемое количество и название каждого объекта /// [Test] - public void TestSearch() + public async Task TestSearch() { - using var browser = new BrowserForTests(); + await using var browser = new Browser(); + + var businessObjectsPage = await browser.SwitchTo(); + await businessObjectsPage.FilterInput.ClearAndInputText("CI"); + await businessObjectsPage.ObjectGroups.WaitCount(1); + + var pagedObjects = await businessObjectsPage.ObjectGroups.GetItemWithText(x => x.Name, "CQL Paged Objects"); + await pagedObjects.ObjectsList + .Select(x => x.ObjectLink) + .Expect() + .ToHaveTextAsync(new[] {"CqlOrganizationInfo", "CqlUserInfo"}); + + await businessObjectsPage.FilterInput.ClearAndInputText("DocMe"); + await businessObjectsPage.ObjectGroups.WaitCount(2); - var businessObjectsPage = browser.SwitchTo(); - businessObjectsPage.FilterInput.ClearAndInputText("CI"); - businessObjectsPage.ObjectGroups.WaitCount(1); - businessObjectsPage.ObjectGroups - .GetItemWithText(x => x.Name.Text, "CQL Paged Objects").ObjectsList - .Wait(x => x.ObjectLink.Text) - .That(Is.EqualTo(new[] {"CqlOrganizationInfo", "CqlUserInfo"})); + var cqlObjects = await businessObjectsPage.ObjectGroups.GetItemWithText(x => x.Name, "CQL Objects"); + await cqlObjects.ObjectsList + .Select(x => x.ObjectLink) + .Expect() + .ToHaveTextAsync(new[] {"DocumentBindingsMeta"}); - businessObjectsPage.FilterInput.ClearAndInputText("DocMe"); - businessObjectsPage.ObjectGroups.WaitCount(2); - businessObjectsPage.ObjectGroups - .GetItemWithText(x => x.Name.Text, "CQL Objects").ObjectsList - .Wait(x => x.ObjectLink.Text) - .That(Is.EqualTo(new[] {"DocumentBindingsMeta"})); - businessObjectsPage.ObjectGroups - .GetItemWithText(x => x.Name.Text, "CQL Paged Objects").ObjectsList - .Wait(x => x.ObjectLink.Text) - .That(Is.EqualTo(new[] {"CqlDocumentMeta"})); + var cqlPagedObjects = await businessObjectsPage.ObjectGroups.GetItemWithText(x => x.Name, "CQL Paged Objects"); + await cqlPagedObjects.ObjectsList + .Select(x => x.ObjectLink) + .Expect() + .ToHaveTextAsync(new[] {"CqlDocumentMeta"}); } /// /// Проверяем, что у таблицы FtpUser есть плашка indexed /// [Test] - public void TestSearchIndexedField() + public async Task TestSearchIndexedField() { - using var browser = new BrowserForTests(); + await using var browser = new Browser(); - var businessObjects = browser.SwitchTo(); - businessObjects.FilterInput.ClearAndInputText("UsersTable"); - businessObjects.ObjectGroups.WaitCount(1); + var businessObjects = await browser.SwitchTo(); + await businessObjects.FilterInput.ClearAndInputText("UsersTable"); + await businessObjects.ObjectGroups.WaitCount(1); - var objects = businessObjects.ObjectGroups.GetItemWithText(x => x.Name.Text, "Postgres Objects"); - objects.IndexedLabel.WaitPresence(); - objects.ObjectsList.WaitCount(1); - objects.ObjectsList[0].ObjectLink.WaitText("UsersTable"); + var objects = await businessObjects.ObjectGroups.GetItemWithText(x => x.Name, "Postgres Objects"); + await objects.IndexedLabel.WaitPresence(); + await objects.ObjectsList.WaitCount(1); + await objects.ObjectsList[0].ObjectLink.WaitText("UsersTable"); } /// @@ -59,15 +67,15 @@ public void TestSearchIndexedField() /// Проверяем что нам выдает ровно одну ссылку /// [Test] - public void TestSearchLink() + public async Task TestSearchLink() { - using var browser = new BrowserForTests(); + await using var browser = new Browser(); - var businessObjectsPage = browser.SwitchTo(); - businessObjectsPage.FilterInput.ClearAndInputText("DocumentPrintingInfo"); - businessObjectsPage.ObjectGroups.WaitCount(1); - businessObjectsPage.ObjectGroups[0].ObjectsList.WaitCount(1); - businessObjectsPage.FindBusinessObjectLink("CQL Objects", "DocumentPrintingInfo").WaitPresence(); + var businessObjectsPage = await browser.SwitchTo(); + await businessObjectsPage.FilterInput.ClearAndInputText("DocumentPrintingInfo"); + await businessObjectsPage.ObjectGroups.WaitCount(1); + await businessObjectsPage.ObjectGroups[0].ObjectsList.WaitCount(1); + await (await businessObjectsPage.FindBusinessObjectLink("CQL Objects", "DocumentPrintingInfo")).WaitPresence(); } /// @@ -75,14 +83,14 @@ public void TestSearchLink() /// Проверяем, что ссылка ведет туда, куда нам нужно /// [Test] - public void TestLinkShouldReferToShowTablePage() + public async Task TestLinkShouldReferToShowTablePage() { - using var browser = new BrowserForTests(); + await using var browser = new Browser(); - var businessObjectsPage = browser.SwitchTo(); - var link = businessObjectsPage.FindBusinessObjectLink("CQL Objects", "DocumentPrintingInfo"); - var page = link.ClickAndGoTo(); - page.Header.WaitText("DocumentPrintingInfo"); + var businessObjectsPage = await browser.SwitchTo(); + var link = await businessObjectsPage.FindBusinessObjectLink("CQL Objects", "DocumentPrintingInfo"); + var page = await link.ClickAndGoTo(); + await page.Header.WaitText("DocumentPrintingInfo"); } } } \ No newline at end of file diff --git a/DbViewer.Tests/FrontTests/Controls/BusinessObjectGroup.cs b/DbViewer.Tests/FrontTests/Controls/BusinessObjectGroup.cs new file mode 100644 index 00000000..fffd567e --- /dev/null +++ b/DbViewer.Tests/FrontTests/Controls/BusinessObjectGroup.cs @@ -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 ObjectsList { get; set; } + } +} \ No newline at end of file diff --git a/DbViewer.Tests/FrontTests/Controls/BusinessObjectItem.cs b/DbViewer.Tests/FrontTests/Controls/BusinessObjectItem.cs new file mode 100644 index 00000000..8f7478dc --- /dev/null +++ b/DbViewer.Tests/FrontTests/Controls/BusinessObjectItem.cs @@ -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; } + } +} \ No newline at end of file diff --git a/DbViewer.Tests/FrontTests/Controls/BusinessObjectTableRow.cs b/DbViewer.Tests/FrontTests/Controls/BusinessObjectTableRow.cs new file mode 100644 index 00000000..7d2a3fb4 --- /dev/null +++ b/DbViewer.Tests/FrontTests/Controls/BusinessObjectTableRow.cs @@ -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