Migrate UI tests to Playwright dotta
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Helpers;
|
||||
|
||||
internal static class UiAuthHelper
|
||||
@@ -7,11 +5,8 @@ internal static class UiAuthHelper
|
||||
public static async Task LoginAsync(IPage page, string username = "testuser", string password = "testpass")
|
||||
{
|
||||
var loginForm = page.GetByText("Authentication Required");
|
||||
var formVisible = await loginForm.IsVisibleAsync();
|
||||
if (!formVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool formVisible = await loginForm.IsVisibleAsync();
|
||||
if (!formVisible) return;
|
||||
|
||||
await page.Locator("input[name='Username']").FillAsync(username);
|
||||
await page.Locator("input[name='Password']").FillAsync(password);
|
||||
@@ -25,15 +20,12 @@ internal static class UiAuthHelper
|
||||
if (await loginForm.IsVisibleAsync())
|
||||
{
|
||||
var notifications = page.Locator(".rz-notification");
|
||||
var count = await notifications.CountAsync();
|
||||
int count = await notifications.CountAsync();
|
||||
var details = new List<string>();
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var text = (await notifications.Nth(i).InnerTextAsync()).Trim();
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
details.Add(text);
|
||||
}
|
||||
string text = (await notifications.Nth(i).InnerTextAsync()).Trim();
|
||||
if (!string.IsNullOrWhiteSpace(text)) details.Add(text);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
@@ -50,4 +42,4 @@ internal static class UiAuthHelper
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Helpers;
|
||||
|
||||
internal static class UiNavigationHelper
|
||||
@@ -98,9 +96,7 @@ internal static class UiNavigationHelper
|
||||
{
|
||||
var meResponse = await page.Context.APIRequest.GetAsync("/api/auth/me");
|
||||
if (meResponse.Status != 200)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"UI test host did not establish authenticated session after login. /api/auth/me status={meResponse.Status}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Helpers;
|
||||
|
||||
internal static class UiSearchFormHelper
|
||||
@@ -7,12 +5,15 @@ internal static class UiSearchFormHelper
|
||||
public static async Task SelectSearchTypeAsync(IPage page, string searchType)
|
||||
{
|
||||
await page.Locator(".rz-dropdown").First.ClickAsync();
|
||||
await page.GetByRole(AriaRole.Option, new PageGetByRoleOptions { Name = searchType, Exact = true }).ClickAsync();
|
||||
await page.GetByRole(AriaRole.Option, new PageGetByRoleOptions { Name = searchType, Exact = true })
|
||||
.ClickAsync();
|
||||
await page.WaitForTimeoutAsync(500);
|
||||
}
|
||||
|
||||
public static Task EnterSearchNameAsync(IPage page, string name) =>
|
||||
page.Locator("input[placeholder=' ']").First.FillAsync(name);
|
||||
public static Task EnterSearchNameAsync(IPage page, string name)
|
||||
{
|
||||
return page.Locator("input[placeholder=' ']").First.FillAsync(name);
|
||||
}
|
||||
|
||||
public static async Task SetDateRangeAsync(IPage page, string minimumMmDdYyyy, string maximumMmDdYyyy)
|
||||
{
|
||||
@@ -27,10 +28,7 @@ internal static class UiSearchFormHelper
|
||||
await page.WaitForTimeoutAsync(500);
|
||||
|
||||
var listItem = page.Locator(".rz-autocomplete-list .rz-autocomplete-list-item").First;
|
||||
if (await listItem.IsVisibleAsync())
|
||||
{
|
||||
await listItem.ClickAsync();
|
||||
}
|
||||
if (await listItem.IsVisibleAsync()) await listItem.ClickAsync();
|
||||
|
||||
await panel.GetByRole(AriaRole.Button, new LocatorGetByRoleOptions { Name = "Add" }).ClickAsync();
|
||||
await page.WaitForTimeoutAsync(250);
|
||||
@@ -51,13 +49,15 @@ internal static class UiSearchFormHelper
|
||||
State = WaitForSelectorState.Visible,
|
||||
Timeout = 10_000
|
||||
});
|
||||
await page.Locator(".rz-dialog-wrapper button").GetByText("Submit", new LocatorGetByTextOptions { Exact = true }).ClickAsync();
|
||||
await page.Locator(".rz-dialog-wrapper button")
|
||||
.GetByText("Submit", new LocatorGetByTextOptions { Exact = true }).ClickAsync();
|
||||
await page.WaitForTimeoutAsync(1_000);
|
||||
}
|
||||
|
||||
public static async Task AssertNoErrorNotificationAsync(IPage page)
|
||||
{
|
||||
var error = page.Locator(".rz-notification-error");
|
||||
await Assertions.Expect(error).Not.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 5_000 });
|
||||
await Assertions.Expect(error).Not
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 5_000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user