Migrate Playwright suite to .NET UI tests and deprecate TS project
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Helpers;
|
||||
|
||||
internal static class UiNavigationHelper
|
||||
{
|
||||
public static async Task NavigateToSearchPageAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/search");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await UiAuthHelper.LoginAsync(page);
|
||||
await EnsureAuthenticatedOrThrowAsync(page);
|
||||
await WaitForBlazorReadyAsync(page);
|
||||
}
|
||||
|
||||
public static async Task NavigateToSearchesDashboardAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/searches");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await UiAuthHelper.LoginAsync(page);
|
||||
await EnsureAuthenticatedOrThrowAsync(page);
|
||||
await WaitForBlazorReadyAsync(page);
|
||||
}
|
||||
|
||||
public static async Task NavigateToQueueAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/search/queue");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await UiAuthHelper.LoginAsync(page);
|
||||
await EnsureAuthenticatedOrThrowAsync(page);
|
||||
await WaitForBlazorReadyAsync(page);
|
||||
}
|
||||
|
||||
public static async Task NavigateToRefreshStatusAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/refresh-status");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await UiAuthHelper.LoginAsync(page);
|
||||
await EnsureAuthenticatedOrThrowAsync(page);
|
||||
await WaitForBlazorReadyAsync(page);
|
||||
}
|
||||
|
||||
public static async Task NavigateToDataSyncAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/data-sync/requests");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await UiAuthHelper.LoginAsync(page);
|
||||
await EnsureAuthenticatedOrThrowAsync(page);
|
||||
await WaitForBlazorReadyAsync(page);
|
||||
}
|
||||
|
||||
public static async Task NavigateToLoginAsync(IPage page)
|
||||
{
|
||||
await page.GotoAsync("/login");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
}
|
||||
|
||||
private static async Task WaitForBlazorReadyAsync(IPage page)
|
||||
{
|
||||
var timeoutMs = 15_000;
|
||||
try
|
||||
{
|
||||
await page.Locator(".rz-dropdown").First.WaitForAsync(new LocatorWaitForOptions
|
||||
{
|
||||
State = WaitForSelectorState.Visible,
|
||||
Timeout = timeoutMs
|
||||
});
|
||||
return;
|
||||
}
|
||||
catch (PlaywrightException)
|
||||
{
|
||||
// Try additional readiness markers.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await page.Locator(".rz-data-grid").First.WaitForAsync(new LocatorWaitForOptions
|
||||
{
|
||||
State = WaitForSelectorState.Visible,
|
||||
Timeout = timeoutMs
|
||||
});
|
||||
return;
|
||||
}
|
||||
catch (PlaywrightException)
|
||||
{
|
||||
// Try text marker as final fallback.
|
||||
}
|
||||
|
||||
await page.GetByText("Search Details").First.WaitForAsync(new LocatorWaitForOptions
|
||||
{
|
||||
State = WaitForSelectorState.Visible,
|
||||
Timeout = timeoutMs
|
||||
});
|
||||
await page.WaitForTimeoutAsync(1_000);
|
||||
}
|
||||
|
||||
private static async Task EnsureAuthenticatedOrThrowAsync(IPage page)
|
||||
{
|
||||
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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user