This repository contains Playwright C# demo code used in conference talks to showcase end-to-end testing patterns with local and cloud browser execution.
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
.zipartifacts - Network mocking and request interception with
page.RouteAsync - Cloud browser execution via Azure Playwright Testing Service
- .NET 10.0 (target framework)
- Microsoft Playwright for .NET
- MSTest 4.x
- NUnit + NUnit3TestAdapter
- Azure Playwright Testing Service
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
- .NET 10.0 SDK
- PowerShell (
pwsh) for Playwright browser 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 installRun all tests:
dotnet test ./PlaywrightDemos/PlayDemo.csproj --no-buildRun 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 | 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 |
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.
The AzurePlaywrightTests_BastaSpring2026*.cs files demonstrate how to run Playwright tests against remote cloud browsers managed by Azure.
PlawrightServiceSetup.csregisters the NUnitSetUpFixturethat initialises the service connection.CloudBrowserPageTest.csoverridesConnectOptionsAsync()on the NUnitPageTestbase class to redirect browser connections to the Azure endpoint.- Individual test classes extend
CloudBrowserPageTestβ no other changes to the test code are required.
- An active Azure Playwright Testing workspace.
- The
PLAYWRIGHT_SERVICE_URLenvironment 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"| 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 |
The GitHub Actions workflow (.github/workflows/dotnet.yml) runs on every push and pull request to main:
- Setup β restores and builds the project using .NET 10.
- Browser install β installs Playwright browsers and WebKit system dependencies.
- Test β runs only
TestCategory=CICDtests; produces TRX, NUnit XML, and HTML reports. - Test Reporter β publishes results inline in the pull request via
dorny/test-reporter. - 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.
| 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 |
The repository also includes a Copilot prompt:
MIT License β see LICENSE.
Nico Orschel