Soenneker.Playwrights.TestHosts
11.0.352
Prefix Reserved
dotnet add package Soenneker.Playwrights.TestHosts --version 11.0.352
NuGet\Install-Package Soenneker.Playwrights.TestHosts -Version 11.0.352
<PackageReference Include="Soenneker.Playwrights.TestHosts" Version="11.0.352" />
<PackageVersion Include="Soenneker.Playwrights.TestHosts" Version="11.0.352" />
<PackageReference Include="Soenneker.Playwrights.TestHosts" />
paket add Soenneker.Playwrights.TestHosts --version 11.0.352
#r "nuget: Soenneker.Playwrights.TestHosts, 11.0.352"
#:package Soenneker.Playwrights.TestHosts@11.0.352
#addin nuget:?package=Soenneker.Playwrights.TestHosts&version=11.0.352
#tool nuget:?package=Soenneker.Playwrights.TestHosts&version=11.0.352
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 | net11.0 is compatible. |
-
net11.0
- Microsoft.Extensions.Logging.Console (>= 11.0.0)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Soenneker.Playwrights.TestEnvironment (>= 11.0.350)
- Soenneker.TestHosts.Unit (>= 11.0.232)
- Soenneker.Utils.Test (>= 11.0.347)
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 |
|---|---|---|
| 11.0.352 | 56 | 11/13/2026 |
| 11.0.351 | 98 | 11/12/2026 |
| 11.0.350 | 91 | 11/12/2026 |
| 11.0.349 | 93 | 11/11/2026 |
| 11.0.347 | 95 | 11/11/2026 |
| 11.0.345 | 89 | 11/11/2026 |
| 11.0.344 | 91 | 11/11/2026 |
| 11.0.343 | 85 | 11/11/2026 |
| 11.0.342 | 83 | 11/11/2026 |
| 11.0.340 | 105 | 11/10/2026 |
| 11.0.339 | 124 | 11/7/2026 |
| 11.0.338 | 98 | 11/4/2026 |
| 11.0.337 | 87 | 11/4/2026 |
| 11.0.336 | 81 | 11/3/2026 |
| 11.0.335 | 79 | 11/3/2026 |
| 11.0.334 | 75 | 11/3/2026 |
| 11.0.333 | 73 | 11/3/2026 |
| 11.0.330 | 75 | 11/3/2026 |
| 11.0.329 | 69 | 11/3/2026 |
| 11.0.327 | 79 | 11/3/2026 |
Updated Soenneker.TestHosts.Unit to 11.0.232