Skip to content

Latest commit

Β 

History

169 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PlaywrightDemos

This repository contains Playwright C# demo code used in conference talks to showcase end-to-end testing patterns with local and cloud browser execution.

Overview

The project combines MSTest- and NUnit-based examples, organized by conference and scenario. Demonstrated techniques include:

  • UI smoke tests with locator strategies (roles, CSS selectors, text, test IDs)
  • Data-driven tests across multiple browsers (Chromium, Firefox, WebKit, Edge, Chrome)
  • File download testing
  • Device emulation (e.g. iPhone 13 landscape)
  • Video recording during test execution
  • Playwright Tracing (screenshots, snapshots, source links) saved as .zip artifacts
  • Network mocking and request interception with page.RouteAsync
  • Cloud browser execution via Azure Playwright Testing Service

Technologies

  • .NET 10.0 (target framework)
  • Microsoft Playwright for .NET
  • MSTest 4.x
  • NUnit + NUnit3TestAdapter
  • Azure Playwright Testing Service

Project Structure

PlaywrightDemos/
β”œβ”€β”€ PlaywrightDemos/
β”‚   β”œβ”€β”€ PlayDemo.csproj                         # Project file; single test project for MSTest and NUnit
β”‚   β”‚
β”‚   β”‚   # Local MSTest-based conference demos
β”‚   β”œβ”€β”€ PlaywrightE2ETests_Basta2023.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_Basta2024.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_BastaSpring2026.cs   # Smoke, video, download, data-driven, device, route demos
β”‚   β”œβ”€β”€ PlaywrightE2ETests_DDC2023.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_DDC2024.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_IT_Tage_2025.cs      # Smoke, data-driven, download, device demos
β”‚   β”œβ”€β”€ PlaywrightE2ETests_KET2023.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_MDD2024.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_MDD2025.cs
β”‚   β”œβ”€β”€ PlaywrightE2ETests_MDD2026.cs           # Smoke, data-driven, download, device, video, route demos
β”‚   β”œβ”€β”€ PlaywrightE2ETests_WDC2023.cs
β”‚   β”‚
β”‚   β”‚   # NUnit-based Azure Playwright Testing Service demos
β”‚   β”œβ”€β”€ AzurePlaywrightTests_BastaSpring2026.cs   # Step-by-step: basic connection
β”‚   β”œβ”€β”€ AzurePlaywrightTests_BastaSpring2026_1.cs # + maximized window args
β”‚   β”œβ”€β”€ AzurePlaywrightTests_BastaSpring2026_2.cs # + cookie-banner handling
β”‚   β”œβ”€β”€ AzurePlaywrightTests_BastaSpring2026_3.cs # + final polished version
β”‚   β”‚
β”‚   β”‚   # Infrastructure
β”‚   β”œβ”€β”€ CloudBrowserPageTest.cs    # Base class: connects PageTest to Azure Playwright Service
β”‚   β”œβ”€β”€ PlawrightServiceSetup.cs   # NUnit SetUpFixture for Azure Playwright Service
β”‚   β”œβ”€β”€ LocalServer.cs             # Helper to start/stop a local npm dev server
β”‚   β”œβ”€β”€ TestAssemblyInfos.cs       # MSTest assembly-level configuration
β”‚   β”œβ”€β”€ Usings.cs                  # Global using directives
β”‚   β”‚
β”‚   └── testdaten/                 # Test data files (images used by network-mocking tests)
β”‚
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ dotnet.yml   # CI pipeline: build, test (CICD tag only), upload artifacts
β”‚   └── docker.yml   # Docker-based workflow
└── README.md

Getting Started

Prerequisites

  • .NET 10.0 SDK
  • PowerShell (pwsh) for Playwright browser installation

Installation

git clone https://github.com/norschel/PlaywrightDemos.git
cd PlaywrightDemos
dotnet restore ./PlaywrightDemos/PlayDemo.csproj
dotnet build ./PlaywrightDemos/PlayDemo.csproj --no-restore
pwsh ./PlaywrightDemos/bin/Debug/net10.0/playwright.ps1 install

Running Tests

Run all tests:

dotnet test ./PlaywrightDemos/PlayDemo.csproj --no-build

Run only CI-tagged tests (the subset executed in the CI pipeline):

dotnet test ./PlaywrightDemos/PlayDemo.csproj --no-build --filter "TestCategory=CICD"

Run a specific test class:

dotnet test ./PlaywrightDemos/PlayDemo.csproj --filter "FullyQualifiedName~PlaywrightE2ETests_IT_Tage_2025"

Run with verbose output and all log formats:

dotnet test ./PlaywrightDemos/PlayDemo.csproj --no-build --verbosity normal \
  --logger "trx;LogFileName=test-results.trx" \
  --logger "nunit;LogFileName=test-results.xml" \
  --logger "html;logfilename=test-results.html"

Conference Demos Included

Conference File(s) Highlighted Scenarios
BASTA! 2023 PlaywrightE2ETests_Basta2023.cs Smoke test
BASTA! 2024 PlaywrightE2ETests_Basta2024.cs Smoke test
BASTA! Spring 2026 PlaywrightE2ETests_BastaSpring2026.cs Smoke, video recording, file download, data-driven (3 browsers), device emulation, network route blocking
BASTA! Spring 2026 (Azure) AzurePlaywrightTests_BastaSpring2026*.cs Cloud browser execution via Azure Playwright Testing Service (4 variants showing progressive refinement)
DDC 2023 PlaywrightE2ETests_DDC2023.cs Smoke test
DDC 2024 PlaywrightE2ETests_DDC2024.cs Smoke test
IT-Tage 2025 PlaywrightE2ETests_IT_Tage_2025.cs Smoke, data-driven (5 browsers), file download, device emulation, tracing
KET 2023 PlaywrightE2ETests_KET2023.cs Smoke test
MDD 2024 PlaywrightE2ETests_MDD2024.cs Smoke, data-driven (5 browsers), file download, device emulation, video recording
MDD 2025 PlaywrightE2ETests_MDD2025.cs Smoke, data-driven (5 browsers), file download, device emulation, video recording
MDD 2026 PlaywrightE2ETests_MDD2026.cs Smoke, data-driven (5 browsers), file download, device emulation, video recording, advanced network request interception
WDC 2023 PlaywrightE2ETests_WDC2023.cs Smoke test

Test Categories

Tests are annotated with [TestCategory] attributes to allow selective execution:

Category Description
CICD Tests safe to run in CI (headless, no manual interaction). Only these run in the GitHub Actions pipeline.
MSTest Tests using the MSTest framework.
NUnit Tests using the NUnit framework (Azure Playwright Testing Service demos).

Most PlaywrightE2ETests_* classes are disabled ([TestClass] commented out) to avoid running all demos simultaneously. Enable individual classes as needed.

Azure Playwright Testing Service

The AzurePlaywrightTests_BastaSpring2026*.cs files demonstrate how to run Playwright tests against remote cloud browsers managed by Azure.

How It Works

  1. PlawrightServiceSetup.cs registers the NUnit SetUpFixture that initialises the service connection.
  2. CloudBrowserPageTest.cs overrides ConnectOptionsAsync() on the NUnit PageTest base class to redirect browser connections to the Azure endpoint.
  3. Individual test classes extend CloudBrowserPageTest β€” no other changes to the test code are required.

Prerequisites for Azure Tests

  • An active Azure Playwright Testing workspace.
  • The PLAYWRIGHT_SERVICE_URL environment variable set to your workspace endpoint.
  • Azure credentials available (the code uses DefaultAzureCredential, which supports Managed Identity, environment variables, Azure CLI, and more).
export PLAYWRIGHT_SERVICE_URL="wss://<your-workspace>.api.playwright.microsoft.com/accounts/<account-id>/browsers"
dotnet test ./PlaywrightDemos/PlayDemo.csproj --filter "TestCategory=NUnit"

Key Test Patterns

Pattern API Used Example File
Simple smoke test page.GotoAsync, page.TitleAsync, Assert All PlaywrightE2ETests_*.cs
Role-based locators page.GetByRole PlaywrightE2ETests_BastaSpring2026.cs
CSS / attribute locators page.Locator("[href*=playwright]") All
Data-driven (multi-browser) [DataRow] / [TestCase] PlaywrightE2ETests_MDD2026.cs
File download page.RunAndWaitForDownloadAsync PlaywrightE2ETests_BastaSpring2026.cs
Device emulation playwright.Devices["iPhone 13 landscape"] PlaywrightE2ETests_MDD2025.cs
Video recording BrowserNewContextOptions.RecordVideoDir PlaywrightE2ETests_MDD2024.cs
Tracing context.Tracing.StartAsync / StopAsync PlaywrightE2ETests_IT_Tage_2025.cs
Network blocking page.RouteAsync + route.FulfillAsync(404) PlaywrightE2ETests_BastaSpring2026.cs
Response interception route.FetchAsync + route.FulfillAsync with modified body PlaywrightE2ETests_MDD2026.cs
Cloud browser CloudBrowserPageTest + PlaywrightServiceBrowserClient AzurePlaywrightTests_BastaSpring2026.cs

CI/CD Pipeline

The GitHub Actions workflow (.github/workflows/dotnet.yml) runs on every push and pull request to main:

  1. Setup β€” restores and builds the project using .NET 10.
  2. Browser install β€” installs Playwright browsers and WebKit system dependencies.
  3. Test β€” runs only TestCategory=CICD tests; produces TRX, NUnit XML, and HTML reports.
  4. Test Reporter β€” publishes results inline in the pull request via dorny/test-reporter.
  5. Artifacts uploaded:
    • test-results β€” TRX and NUnit XML files (90-day retention).
    • playwright-diagnostics β€” all screenshots (.png/.jpg), videos (.webm), and traces (.zip) collected during the run (90-day retention).
    • ErrorArtifact β€” full workspace snapshot uploaded only on failure.

Key Dependencies

Package Version
Microsoft.Playwright.MSTest 1.58.0
Microsoft.Playwright.NUnit 1.58.0
Azure.Developer.Playwright.NUnit 1.0.0
MSTest / MSTest.TestAdapter / MSTest.TestFramework 4.1.0
NUnit3TestAdapter 6.1.0
Azure.Identity 1.18.0
NunitXml.TestLogger 8.0.0
coverlet.collector 8.0.0

AI-Assisted Automation Prompt

The repository also includes a Copilot prompt:

License

MIT License β€” see LICENSE.

Author

Nico Orschel

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages