Soenneker.Playwrights.TestEnvironment 11.0.321

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Playwrights.TestEnvironment --version 11.0.321
                    
NuGet\Install-Package Soenneker.Playwrights.TestEnvironment -Version 11.0.321
                    
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.TestEnvironment" Version="11.0.321" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Playwrights.TestEnvironment" Version="11.0.321" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Playwrights.TestEnvironment" />
                    
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.TestEnvironment --version 11.0.321
                    
#r "nuget: Soenneker.Playwrights.TestEnvironment, 11.0.321"
                    
#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.TestEnvironment@11.0.321
                    
#: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.TestEnvironment&version=11.0.321
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Playwrights.TestEnvironment&version=11.0.321
                    
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.TestEnvironment

Runs an ASP.NET Core project on an available loopback port and provides headless Playwright sessions for integration tests.

Installation

dotnet add package Soenneker.Playwrights.TestEnvironment

Registration

Register the host options and environment in the test service collection:

using Microsoft.Extensions.DependencyInjection;
using Soenneker.Playwrights.TestEnvironment.Options;
using Soenneker.Playwrights.TestEnvironment.Registrars;

services.AddSingleton(new PlaywrightTestHostOptions
{
    SolutionFileName = "MyApp.slnx",
    ProjectRelativePath = "src/MyApp/MyApp.csproj",
    ApplicationName = "MyApp",
    Restore = true,
    Build = true,
    BuildConfiguration = "Release"
});

services.AddPlaywrightTestEnvironmentAsSingleton();

Use the singleton registration for a test host shared by the suite. AddPlaywrightTestEnvironmentAsScoped() gives each scope its own mutable host runtime, while the Playwright installer and HTTP transport remain process-wide singletons.

Start the application and create a session

using Soenneker.Playwrights.TestEnvironment.Abstract;

IPlaywrightTestEnvironment environment =
    serviceProvider.GetRequiredService<IPlaywrightTestEnvironment>();

await environment.Initialize(
    @"C:\git\MyApp\src\MyApp\MyApp.csproj",
    cancellationToken);

await using var session = await environment.CreateSession(cancellationToken: cancellationToken);

await session.Page.GotoAsync("/");
await Assertions.Expect(session.Page.GetByRole(AriaRole.Heading))
                .ToBeVisibleAsync();

Initialize installs the configured Playwright browser if needed, starts Chromium, launches the project at BaseUrl, and waits until the application accepts HTTP requests. Dispose the environment to close Playwright and terminate the application process.

Session reuse

Sessions get their own context and page unless reuse is enabled:

services.AddSingleton(new PlaywrightTestHostOptions
{
    SolutionFileName = "MyApp.slnx",
    ProjectRelativePath = "src/MyApp/MyApp.csproj",
    ReuseBrowserContextAcrossSessions = true,
    ReusePageAcrossSessions = false
});

Per-session overrides take precedence over the host defaults:

await using var session = await environment.CreateSession(
    new PlaywrightSessionOptions
    {
        ReuseBrowserContextAcrossSessions = true,
        ReusePageAcrossSessions = false
    },
    cancellationToken);

Reusing a page implies reusing its context. A session does not dispose shared pages or contexts; the environment owns and releases them.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.TestEnvironment:

Package Downloads
Soenneker.Playwrights.TestHosts

A test host for automated testing with Playwright

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.328 47 10/27/2026
11.0.327 45 10/27/2026
11.0.326 43 10/27/2026
11.0.323 50 10/26/2026
11.0.322 40 10/26/2026
11.0.321 54 10/26/2026
11.0.320 51 10/26/2026
11.0.319 60 10/26/2026
11.0.318 71 10/26/2026
4.0.317 108 10/23/2026
4.0.316 66 10/23/2026
4.0.315 76 10/23/2026
4.0.314 72 10/22/2026
4.0.313 161 10/15/2026
4.0.312 115 10/15/2026
4.0.311 96 10/15/2026
4.0.309 115 10/14/2026
4.0.306 117 10/14/2026
4.0.305 123 10/14/2026
4.0.304 86 10/14/2026
Loading failed

Updated Multiple NuGet packages