Soenneker.Playwrights.TestHosts
4.0.241
Prefix Reserved
dotnet add package Soenneker.Playwrights.TestHosts --version 4.0.241
NuGet\Install-Package Soenneker.Playwrights.TestHosts -Version 4.0.241
<PackageReference Include="Soenneker.Playwrights.TestHosts" Version="4.0.241" />
<PackageVersion Include="Soenneker.Playwrights.TestHosts" Version="4.0.241" />
<PackageReference Include="Soenneker.Playwrights.TestHosts" />
paket add Soenneker.Playwrights.TestHosts --version 4.0.241
#r "nuget: Soenneker.Playwrights.TestHosts, 4.0.241"
#:package Soenneker.Playwrights.TestHosts@4.0.241
#addin nuget:?package=Soenneker.Playwrights.TestHosts&version=4.0.241
#tool nuget:?package=Soenneker.Playwrights.TestHosts&version=4.0.241
Soenneker.Playwrights.TestHosts
A reusable test fixture that locates an application project, starts it on an available loopback port, and provides Playwright browser sessions to the suite.
Installation
dotnet add package Soenneker.Playwrights.TestHosts
Define a host
Derive from PlaywrightHostedTestHost and identify the solution and application project. The project path must be relative to, and remain inside, the discovered solution directory.
using System.IO;
using Soenneker.Playwrights.TestEnvironment.Options;
using Soenneker.Playwrights.TestHosts;
public sealed class AppPlaywrightHost : PlaywrightHostedTestHost
{
protected override PlaywrightTestHostOptions CreateOptions()
{
return new PlaywrightTestHostOptions
{
SolutionFileName = "MyApp.slnx",
ProjectRelativePath = Path.Combine("src", "MyApp", "MyApp.csproj"),
ApplicationName = "MyApp",
Restore = false,
Build = true,
BuildConfiguration = "Debug",
ReuseBrowserContextAcrossSessions = false,
ReusePageAcrossSessions = false
};
}
}
Override ConfigureServices when the test fixture needs additional dependencies:
protected override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<TestData>();
}
Use it in tests
Share the host for the test session, then create and dispose a browser session in each test:
using Microsoft.Playwright;
using Soenneker.Playwrights.Session;
[ClassDataSource<AppPlaywrightHost>(Shared = SharedType.PerTestSession)]
public sealed class HomePageTests
{
private readonly AppPlaywrightHost _host;
public HomePageTests(AppPlaywrightHost host)
{
_host = host;
}
[Test]
public async ValueTask Home_page_loads()
{
await using BrowserSession session = await _host.CreateSession();
await session.Page.GotoAsync(_host.BaseUrl);
await Assertions.Expect(session.Page.GetByRole(AriaRole.Heading))
.ToBeVisibleAsync();
}
}
BaseUrl and CreateSession are available after the shared host initializes. Disposing the host closes Playwright and terminates the application process. Shared context/page behavior can be set in CreateOptions or overridden per CreateSession call with PlaywrightSessionOptions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Console (>= 10.0.12)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Soenneker.Playwrights.TestEnvironment (>= 4.0.251)
- Soenneker.TestHosts.Unit (>= 4.0.158)
- Soenneker.Utils.Test (>= 4.0.330)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Playwrights.TestHosts:
| Package | Downloads |
|---|---|
|
Soenneker.Playwrights.Tests.Unit
A fixtured unit test for testing with Playwright |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.241 | 0 | 9/15/2026 |
| 4.0.240 | 0 | 9/15/2026 |
| 4.0.239 | 41 | 9/15/2026 |
| 4.0.238 | 44 | 9/14/2026 |
| 4.0.237 | 60 | 9/14/2026 |
| 4.0.236 | 67 | 9/13/2026 |
| 4.0.235 | 56 | 9/13/2026 |
| 4.0.234 | 47 | 9/13/2026 |
| 4.0.233 | 52 | 9/13/2026 |
| 4.0.232 | 65 | 9/13/2026 |
| 4.0.231 | 48 | 9/13/2026 |
| 4.0.230 | 52 | 9/12/2026 |
| 4.0.229 | 59 | 9/12/2026 |
| 4.0.228 | 62 | 9/12/2026 |
| 4.0.227 | 110 | 9/10/2026 |
| 4.0.226 | 87 | 9/10/2026 |
| 4.0.225 | 105 | 9/9/2026 |
| 4.0.224 | 93 | 9/9/2026 |
| 4.0.223 | 102 | 9/9/2026 |
| 4.0.222 | 97 | 9/8/2026 |