Skip to content

rafalkukuczka/PlaywrightCSharpCompleteProject

Repository files navigation

Playwright Testing in C# - Complete Downloadable Project

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

Seeded login

Use this account in the MVC application:

Email: admin@company.com
Password: Password123!

Requirements

  • .NET 9 SDK
  • PowerShell for installing Playwright browsers

How to run the MVC application

From the repository root:

cd src/SampleMvcApp
dotnet restore
dotnet run

The 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"

How to install Playwright browsers

Build the test project first:

cd tests/PlaywrightCSharpTests
dotnet restore
dotnet build

Install browsers (Windows)

dotnet tool install --global Microsoft.Playwright.CLI
playwright install

Install browsers (Linux):

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

On Linux CI you may need:

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

How to run tests

Keep the MVC application running in one terminal.

In another terminal:

cd tests/PlaywrightCSharpTests
dotnet test

Run only smoke tests:

dotnet test --filter TestCategory=Smoke

Run regression tests:

dotnet test --filter TestCategory=Regression

Project structure

PlaywrightCSharpCompleteProject/
├── src/
│   └── SampleMvcApp/
│       ├── Controllers/
│       ├── Data/
│       ├── Models/
│       ├── ViewModels/
│       ├── Views/
│       └── wwwroot/
│
└── tests/
    └── PlaywrightCSharpTests/
        ├── Infrastructure/
        ├── Pages/
        ├── TestData/
        └── Tests/
            ├── Smoke/
            └── Regression/

What the tests cover

HomePageSmokeTests

Checks if the MVC home page loads and the Dashboard heading is visible.

LoginSmokeTests

Uses the seeded admin account and verifies that login redirects to the Orders page.

LoginValidationTests

Checks that invalid credentials display a validation error.

OrderRegressionTests

Logs in, creates a new order, verifies the success message, verifies the order number, saves a screenshot and records a Playwright trace.

Trace viewer

After running the regression test, open a trace file:

pwsh bin/Debug/net9.0/playwright.ps1 show-trace artifacts/order-ORD-xxxx-trace.zip

Notes

This 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.

Suggested article section

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/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors