Migrate UI tests to Playwright dotta
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Support;
|
||||
|
||||
public sealed class PlaywrightFixture : IAsyncLifetime
|
||||
{
|
||||
private IPlaywright? _playwright;
|
||||
private IBrowser? _browser;
|
||||
private IPlaywright? _playwright;
|
||||
|
||||
public IBrowser Browser => _browser ?? throw new InvalidOperationException("Browser is not initialized.");
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_playwright = await Microsoft.Playwright.Playwright.CreateAsync();
|
||||
_playwright = await Playwright.CreateAsync();
|
||||
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
|
||||
{
|
||||
Headless = UiTestSettings.Headless,
|
||||
@@ -21,11 +19,8 @@ public sealed class PlaywrightFixture : IAsyncLifetime
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
if (_browser is not null)
|
||||
{
|
||||
await _browser.CloseAsync();
|
||||
}
|
||||
if (_browser is not null) await _browser.CloseAsync();
|
||||
|
||||
_playwright?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace JdeScoping.Ui.Tests.Support;
|
||||
public abstract class SearchFlowTestBase(PlaywrightFixture fixture) : UiTestBase(fixture)
|
||||
{
|
||||
private static bool StrictMode =>
|
||||
string.Equals(Environment.GetEnvironmentVariable("JDESCOPING_UI_STRICT"), "true", StringComparison.OrdinalIgnoreCase);
|
||||
string.Equals(Environment.GetEnvironmentVariable("JDESCOPING_UI_STRICT"), "true",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
protected Task RunSearchSubmissionAsync(
|
||||
string searchType,
|
||||
@@ -23,34 +24,23 @@ public abstract class SearchFlowTestBase(PlaywrightFixture fixture) : UiTestBase
|
||||
await Assertions.Expect(page.Locator(".rz-dropdown-label").First).ToContainTextAsync(searchType);
|
||||
|
||||
if (!StrictMode)
|
||||
{
|
||||
// Default mode is smoke-only against local docker where source systems can be offline.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(minDate) && !string.IsNullOrWhiteSpace(maxDate))
|
||||
{
|
||||
await UiSearchFormHelper.SetDateRangeAsync(page, minDate, maxDate);
|
||||
}
|
||||
|
||||
if (autocompleteItems is not null)
|
||||
{
|
||||
foreach (var item in autocompleteItems)
|
||||
{
|
||||
await UiSearchFormHelper.AddAutocompleteItemAsync(page, item.PanelHeader, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (uploads is not null)
|
||||
{
|
||||
foreach (var upload in uploads)
|
||||
{
|
||||
await UiSearchFormHelper.UploadFileAsync(page, upload.PanelHeader, TestDataPaths.Get(upload.FileName));
|
||||
}
|
||||
}
|
||||
await UiSearchFormHelper.UploadFileAsync(page, upload.PanelHeader,
|
||||
TestDataPaths.Get(upload.FileName));
|
||||
|
||||
await UiSearchFormHelper.SubmitSearchAsync(page);
|
||||
await UiSearchFormHelper.AssertNoErrorNotificationAsync(page);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,8 @@ namespace JdeScoping.Ui.Tests.Support;
|
||||
|
||||
internal static class TestDataPaths
|
||||
{
|
||||
public static string Get(string fileName) => Path.Combine(AppContext.BaseDirectory, "TestData", fileName);
|
||||
}
|
||||
public static string Get(string fileName)
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "TestData", fileName);
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,4 @@ internal static class UiSearchTypes
|
||||
public const string TimeSpanItem = "Time Span + Item Number";
|
||||
public const string TimeSpanWcOperator = "Time Span + Work Center + Operator";
|
||||
public const string TimeSpanPcOperator = "Time Span + Profit Center + Operator";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Support;
|
||||
|
||||
[Collection(UiTestCollection.Name)]
|
||||
@@ -26,4 +24,4 @@ public abstract class UiTestBase
|
||||
|
||||
await action(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
using Xunit;
|
||||
|
||||
namespace JdeScoping.Ui.Tests.Support;
|
||||
|
||||
[CollectionDefinition(Name)]
|
||||
public sealed class UiTestCollection : ICollectionFixture<PlaywrightFixture>
|
||||
{
|
||||
public const string Name = "UiTests";
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@ internal static class UiTestSettings
|
||||
?? "http://localhost:5294";
|
||||
|
||||
public static bool Headless =>
|
||||
!string.Equals(Environment.GetEnvironmentVariable("JDESCOPING_UI_HEADED"), "true", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
!string.Equals(Environment.GetEnvironmentVariable("JDESCOPING_UI_HEADED"), "true",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
Reference in New Issue
Block a user