Migrate Playwright suite to .NET UI tests and deprecate TS project
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Helpers;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
await page.Locator("input[name='Username']").FillAsync(username);
|
||||
await page.Locator("input[name='Password']").FillAsync(password);
|
||||
await page.Locator("button[type='submit']:has-text('LOGIN')").ClickAsync();
|
||||
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await page.WaitForTimeoutAsync(3_000);
|
||||
await page.GotoAsync("/search");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
|
||||
if (await loginForm.IsVisibleAsync())
|
||||
{
|
||||
var notifications = page.Locator(".rz-notification");
|
||||
var 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);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Login did not complete. URL={page.Url}. Notifications={string.Join(" | ", details)}");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task LogoutAsync(IPage page)
|
||||
{
|
||||
var logoutButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Logout" });
|
||||
if (await logoutButton.IsVisibleAsync())
|
||||
{
|
||||
await logoutButton.ClickAsync();
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user