This repository contains a complete example for the article Playwright Testing in C#: Step-by-Step Guide for Reliable Web Applications.
It includes:
src/SampleMvcApp- ASP.NET Core MVC application with login- SQLite database created automatically on startup
- seeded admin user
- seeded orders
tests/PlaywrightCSharpTests- Playwright tests in C# using NUnit- Page Object Model examples
- smoke tests
- regression tests
- screenshots and trace recording
Use this account in the MVC application:
Email: admin@company.com
Password: Password123!
- .NET 9 SDK
- PowerShell for installing Playwright browsers
From the repository root:
cd src/SampleMvcApp
dotnet restore
dotnet runThe app will create a local SQLite database file automatically:
samplemvc.db
The application should run on a local HTTPS address such as:
https://localhost:5001
If the port is different, set the test base URL before running tests.
Windows PowerShell:
$env:APP_BASE_URL="https://localhost:5001"Linux/macOS:
export APP_BASE_URL="https://localhost:5001"Build the test project first:
cd tests/PlaywrightCSharpTests
dotnet restore
dotnet buildInstall browsers (Windows)
dotnet tool install --global Microsoft.Playwright.CLI
playwright installInstall browsers (Linux):
pwsh bin/Debug/net9.0/playwright.ps1 installOn Linux CI you may need:
pwsh bin/Debug/net9.0/playwright.ps1 install --with-depsKeep the MVC application running in one terminal.
In another terminal:
cd tests/PlaywrightCSharpTests
dotnet testRun only smoke tests:
dotnet test --filter TestCategory=SmokeRun regression tests:
dotnet test --filter TestCategory=RegressionPlaywrightCSharpCompleteProject/
├── src/
│ └── SampleMvcApp/
│ ├── Controllers/
│ ├── Data/
│ ├── Models/
│ ├── ViewModels/
│ ├── Views/
│ └── wwwroot/
│
└── tests/
└── PlaywrightCSharpTests/
├── Infrastructure/
├── Pages/
├── TestData/
└── Tests/
├── Smoke/
└── Regression/
Checks if the MVC home page loads and the Dashboard heading is visible.
Uses the seeded admin account and verifies that login redirects to the Orders page.
Checks that invalid credentials display a validation error.
Logs in, creates a new order, verifies the success message, verifies the order number, saves a screenshot and records a Playwright trace.
After running the regression test, open a trace file:
pwsh bin/Debug/net9.0/playwright.ps1 show-trace artifacts/order-ORD-xxxx-trace.zipThis project uses Database.EnsureCreatedAsync() for simplicity. In production projects, use EF Core migrations instead.
The goal of this repository is to demonstrate practical Playwright testing in C# with a working MVC application and repeatable seed data.
You can use this project as a downloadable companion for an article titled:
Playwright Testing in c#: https://pkey.info/knowledge-base/playwright-testing-in-c-step-by-step-guide/