Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

For a C# test project, install the matching Microsoft.Playwright.* NuGet package, build the project, then run the generated playwright.ps1 install script from the build output. Use the plain Microsoft.Playwright package for a console application or custom test harness. Browser binaries are a separate, version-matched install.

Choose the Playwright package that matches your project

The package determines whether Playwright supplies base classes and fixtures for a test runner or only the automation library. Pick the project template and package together.

Project or test runner NuGet package Typical command
NUnit end-to-end tests Microsoft.Playwright.NUnit dotnet new nunit -n PlaywrightTests
MSTest end-to-end tests Microsoft.Playwright.MSTest dotnet new mstest -n PlaywrightTests
xUnit end-to-end tests Microsoft.Playwright.Xunit dotnet new xunit -n PlaywrightTests
xUnit v3 end-to-end tests Microsoft.Playwright.Xunit.v3 dotnet new xunit3 -n PlaywrightTests
Console app, library, or custom test infrastructure Microsoft.Playwright dotnet new console -n BrowserAutomation

Use the framework package only when you want Playwright’s integration classes for that runner. A custom harness should reference the base library and manage its own fixtures, assertions, and test lifecycle.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prerequisites and a clean starting point

  • Install a supported .NET SDK and verify it with dotnet --info. The examples use .NET 8, but the target framework folder must match the SDK and project file you actually use.
  • Install PowerShell 7 so the generated script can run as pwsh. On systems where the command is missing or produces the documented TypeNotFound error, update it with dotnet tool update --global PowerShell or use the current PowerShell installation method for your operating system.
  • Use a terminal in the directory where you want the solution or project created.
  • Allow the machine to download NuGet packages and browser archives. Corporate proxies, TLS interception, and restricted CI runners may require additional configuration.

Install Playwright for NUnit, MSTest, xUnit, or xUnit v3

The sequence is the same for each supported runner: create a template, add its matching package, build once, and install browsers from the script emitted by that build.

1. Create the test project

Choose one template:

dotnet new nunit -n PlaywrightTests
cd PlaywrightTests

For the other runners, use the corresponding commands instead:

dotnet new mstest -n PlaywrightTests
dotnet new xunit -n PlaywrightTests
dotnet new xunit3 -n PlaywrightTests

If you created a project elsewhere, change into that project directory before running the remaining commands.

2. Add the matching NuGet package

dotnet add package Microsoft.Playwright.NUnit

Replace the package for another runner:

dotnet add package Microsoft.Playwright.MSTest
dotnet add package Microsoft.Playwright.Xunit
dotnet add package Microsoft.Playwright.Xunit.v3

Do not mix a runner package and a different runner’s base classes. Keep the Playwright package version consistent across projects in the same solution.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Build before looking for the installer

dotnet build

The build generates playwright.ps1 under bin/Debug/<target-framework>/. The framework directory is not always net8.0; inspect the actual build output if you target another framework, configuration, or runtime.

4. Download the browser binaries

pwsh bin/Debug/net8.0/playwright.ps1 install

Replace net8.0 with the directory produced by your build. This command installs the browser revisions expected by the Playwright package. Run it again after updating the package because a newer package can require different browser executables.

5. Add a first NUnit test

With Microsoft.Playwright.NUnit, inherit from Playwright’s PageTest base class. The fixture creates and disposes the browser context for you.

using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests;

public class HomePageTests : PageTest
{
    [Test]
    public async Task Home_page_has_a_title()
    {
        await Page.GotoAsync("https://example.com");
        var title = await Page.TitleAsync();
        Assert.That(title, Does.Contain("Example Domain"));
    }
}

Run the test with:

dotnet test

The same browser installation is used by MSTest, xUnit, and xUnit v3 projects; only the test base classes and attributes differ.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Playwright as a C# library

Use the plain package when you are writing a console program, a service, or a custom test framework rather than using Playwright’s runner integration.

1. Create the console project and add the package

dotnet new console -n BrowserAutomation
cd BrowserAutomation
dotnet add package Microsoft.Playwright

2. Build, then install browsers from the generated script

dotnet build
pwsh bin/Debug/net8.0/playwright.ps1 install

Again, substitute the target-framework directory emitted by your build.

3. Run a complete console example

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
    Headless = true
});

var page = await browser.NewPageAsync();
await page.GotoAsync("https://example.com");
Console.WriteLine(await page.TitleAsync());

Save this as Program.cs and run dotnet run. The browser launch will fail if the package was restored but its matching browser binary was not installed.

Install a specific browser or operating-system dependencies

Selecting Chromium, Firefox, or WebKit

The default install downloads the supported browser set. To install only one engine, pass its name:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pwsh bin/Debug/net8.0/playwright.ps1 install chromium
pwsh bin/Debug/net8.0/playwright.ps1 install firefox
pwsh bin/Debug/net8.0/playwright.ps1 install webkit

Install every engine when your test matrix covers Chromium, Firefox, and WebKit. Installing one engine saves disk space and download time but makes tests that select another engine fail until its binary is present.

Linux system libraries

Browser archives are not the same as Linux operating-system libraries. On Linux CI or a minimal machine, install dependencies with:

pwsh bin/Debug/net8.0/playwright.ps1 install-deps

For a combined browser and dependency setup, use:

pwsh bin/Debug/net8.0/playwright.ps1 install --with-deps chromium

Use the live Playwright .NET system-requirements guidance for the distribution and CPU architecture you deploy. Supported operating-system versions change, so do not treat an old CI image as permanently supported.

Browser download paths and cache management

Playwright stores browser binaries in an operating-system-specific cache by default. Set PLAYWRIGHT_BROWSERS_PATH when you need a shared cache, a workspace-local cache, or a path writable by a CI user. The Playwright command-line tools also provide operations for listing installed browsers, removing them, and cleaning stale revisions. Keep the cache location stable between CI jobs if you want to avoid downloading the same revision repeatedly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Network, proxy, and certificate considerations

Browser installation downloads archives independently of your application’s HTTP traffic. In a restricted network, configure the environment and Playwright download settings documented for .NET:

  • Set HTTPS_PROXY when outbound downloads must traverse a proxy.
  • Use a custom browser-download host when your organization mirrors or proxies the official archive location.
  • Provide the custom certificate-authority configuration required by TLS-intercepting proxies.
  • Run the install command under the same account and environment that will execute tests; a browser installed for one user is not necessarily visible to another.

A successful NuGet restore does not prove that browser downloads can reach their host. Test the browser-install step separately in a clean CI job.

Continuous integration: build, install, test

A reliable CI job preserves the order that works locally:

  1. Restore and build the project.
  2. Run the generated PowerShell installer from the build’s target-framework directory.
  3. On Linux, include --with-deps or run install-deps when the runner image lacks required libraries.
  4. Execute dotnet test (or your custom application’s command).
dotnet build --configuration Release
pwsh bin/Release/net8.0/playwright.ps1 install --with-deps chromium
dotnet test --configuration Release

Change Release, net8.0, and the browser selection to match your project. Cache the browser directory only when the cache key includes the Playwright package version, operating system, architecture, and browser choice. Otherwise, a stale cache can contain a revision that the current package does not understand.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Containers and official Playwright images

If you use an official Playwright Docker image, align its version with the Playwright NuGet package in your project. A version mismatch can leave the expected browser executable unavailable even though the container appears to contain Playwright. Pin both versions together rather than floating one independently, and rebuild the image when the package is upgraded.

Reliability and performance choices

Keep package and browser revisions synchronized

Playwright packages target specific browser versions. Treat a package update as a two-step change: update the NuGet reference, then run the generated installer again. Commit the package version through your normal dependency-management process so local development and CI resolve the same revision.

Reduce cold-start time without hiding failures

  • Install only the engines your test matrix uses.
  • Cache the browser directory with a versioned key.
  • Build once per job and invoke the script from that build output instead of guessing a path.
  • Use a prebuilt, version-pinned container when your organization standardizes CI environments.

Do not skip installation errors merely because a previous job populated a cache. A missing or incompatible executable should fail the job before tests begin.

Control parallelism deliberately

Test-runner workers can launch multiple browser contexts and increase CPU, memory, and network demand. Start with the runner’s default worker count, then increase it only after the CI machine can sustain the load. Browser installation itself is normally a one-time setup per image or cache key; it does not need to run once per test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting common installation failures

Symptom Likely cause Fix
playwright.ps1 cannot be found The project has not been built, or the framework folder was guessed incorrectly. Run dotnet build, inspect bin/Debug or bin/Release, and use the exact target-framework directory generated there.
pwsh is not recognized or reports TypeNotFound PowerShell 7 is missing or the installed tool is outdated. Install or update PowerShell; the documented .NET example is dotnet tool update --global PowerShell.
Browser executable is missing after a package update The NuGet package now expects a different browser revision. Run the generated script’s install command again using the newly built project output.
Linux launch fails with missing shared libraries The runner image lacks browser system dependencies. Run install-deps or install --with-deps chromium as appropriate for the image.
Browser download times out or returns a certificate/proxy error Outbound downloads are blocked or intercepted. Configure HTTPS_PROXY, the approved download host, and the required custom CA settings; then rerun installation.
Tests run in Docker but cannot locate browsers The Docker image and NuGet package versions do not match. Pin compatible versions for both and rebuild the image before running tests.
One runner’s attributes or base class are unavailable The project has the wrong Playwright integration package. Install the package whose suffix matches the template: NUnit, MSTest, Xunit, or Xunit.v3.
It works locally but not in CI The CI user has a different cache path, no proxy configuration, or no Linux dependencies. Run build and browser installation in the job, set a writable PLAYWRIGHT_BROWSERS_PATH if needed, and add the network and dependency setup explicitly.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to obtain a clean image or PDF of a URL rather than maintain a Playwright runtime, ScreenshotNeo provides a single HTTP endpoint and an MCP server for AI clients such as Claude, Cursor, and other MCP-compatible tools. It accepts consent banners like a visitor, removes more than 60 known consent platforms plus newsletter popups and chat widgets before capture, and lets you turn those cleanup steps off.

Only clean shots are billed. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the result with X-Page-Verdict and X-Billed headers. The service supports PNG, JPEG, WebP, and PDF output, with options including full-page lazy-image loading, CSS-selector element capture, device and viewport choices, dark mode, retina scale, custom CSS and JavaScript, clicks, waits, blocked resources, cookies, headers, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, bulk requests, and usage reporting.

Use the API documentation at https://screenshotneo.com/docs/ for the complete parameter list. A basic request is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same request from Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And from Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' }); const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The free plan includes 1,000 screenshots per month without a card. Paid plans start at $5 for 3,000 shots; yearly billing provides two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to get started.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

FAQ

Do I need to install browsers globally?

No. Install them through the playwright.ps1 script generated for the project so the binaries match that project’s Playwright package.

Can I use an already-installed Chrome or Edge?

The installation sequence described here uses Playwright-managed browser revisions. Using a system browser is a separate launch configuration and does not remove the need to understand package and browser compatibility.

Why does the script live under bin/Debug?

The .NET package generates the script as part of the build output. A clean checkout has no script until the project has been restored and built.

Should browser downloads run during every test invocation?

No. Install once per machine, image, or correctly keyed CI cache, then run the tests. Repeat installation only after changing the package, browser selection, or installation environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Which package should a C# console application reference?

Reference Microsoft.Playwright, not one of the runner-specific Microsoft.Playwright.NUnit, MSTest, Xunit, or Xunit.v3 packages.

What is the safest way to choose the installer path?

Build first, then copy the target-framework directory that actually appears beneath the build configuration and use that path in the generated playwright.ps1 command.

When should Linux CI use –with-deps?

Use it when the runner image may not contain the operating-system libraries required by the selected browser; it combines dependency installation with browser installation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.