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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Playwrights.TestHosts" Version="4.0.241" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Playwrights.TestHosts" Version="4.0.241" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Playwrights.TestHosts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Playwrights.TestHosts --version 4.0.241
                    
#r "nuget: Soenneker.Playwrights.TestHosts, 4.0.241"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Playwrights.TestHosts@4.0.241
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Playwrights.TestHosts&version=4.0.241
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Playwrights.TestHosts&version=4.0.241
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed