tests(apphost.tests): added support for end to end testing using playwright
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Aspire.Hosting;
|
||||
using Aspire.Hosting.Testing;
|
||||
|
||||
namespace FiscalOS.AppHost.Tests.Infra;
|
||||
|
||||
public sealed class AspireFixture : IAsyncLifetime
|
||||
{
|
||||
private DistributedApplication _app = null!;
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
var appHost = await DistributedApplicationTestingBuilder
|
||||
.CreateAsync<Projects.FiscalOS_AppHost>();
|
||||
|
||||
_app = await appHost.BuildAsync();
|
||||
|
||||
await _app.StartAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _app.StopAsync();
|
||||
await _app.DisposeAsync();
|
||||
}
|
||||
|
||||
public Uri GetBaseWebUri()
|
||||
{
|
||||
return _app.GetEndpoint(ProjectNames.Web, "https");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
|
||||
namespace FiscalOS.AppHost.Tests.Infra;
|
||||
|
||||
public abstract class BaseTest(
|
||||
AspireFixture aspire,
|
||||
PlaywrightFixture playwright
|
||||
) : IAsyncLifetime, IClassFixture<AspireFixture>, IClassFixture<PlaywrightFixture>
|
||||
{
|
||||
protected AspireFixture AspireFixture { get; } = aspire;
|
||||
protected PlaywrightFixture PlaywrightFixture { get; } = playwright;
|
||||
|
||||
protected IBrowserContext Context { get; private set; } = null!;
|
||||
protected IPage Page { get; private set; } = null!;
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
Context = await PlaywrightFixture.Browser.NewContextAsync(new()
|
||||
{
|
||||
BaseURL = AspireFixture.GetBaseWebUri().ToString(),
|
||||
});
|
||||
Page = await Context.NewPageAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await Page.CloseAsync();
|
||||
await Context.CloseAsync();
|
||||
await Context.DisposeAsync();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public static ILocatorAssertions Expect(ILocator locator)
|
||||
{
|
||||
return Assertions.Expect(locator);
|
||||
}
|
||||
|
||||
public static IPageAssertions Expect(IPage page)
|
||||
{
|
||||
return Assertions.Expect(page);
|
||||
}
|
||||
|
||||
public static IAPIResponseAssertions Expect(IAPIResponse response)
|
||||
{
|
||||
return Assertions.Expect(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace FiscalOS.AppHost.Tests.Infra;
|
||||
|
||||
public sealed class PlaywrightFixture : IAsyncLifetime
|
||||
{
|
||||
private IPlaywright? _playwright;
|
||||
|
||||
internal IBrowser Browser { get; set; } = null!;
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
_playwright = await Playwright.CreateAsync();
|
||||
|
||||
Browser = await _playwright.Chromium.LaunchAsync(new()
|
||||
{
|
||||
Headless = false,
|
||||
});
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await Browser.CloseAsync();
|
||||
await Browser.DisposeAsync();
|
||||
|
||||
_playwright?.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user