Playwright Blazor Testing
Write UI tests for Blazor applications (Server or WebAssembly) using Playwright.
Install
npx skills add Aaronontheweb/dotnet-skills --skill playwright-blazor-testing -g -a claude-code -y- Repository
- Aaronontheweb/dotnet-skills1.2k
- Category
- Design
- Updated
- 7d ago
- License
- MIT
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Write UI tests for Blazor applications (Server or WebAssembly) using Playwright. Covers navigation, interaction, authentication, selectors, and common Blazor-specific patterns.
Testing Blazor Applications with Playwright
When to Use This Skill
Use this skill when:
- Writing end-to-end UI tests for Blazor Server or WebAssembly applications
- Testing interactive components, forms, and user workflows
- Verifying authentication and authorization flows
- Testing SignalR-based real-time updates in Blazor Server
- Capturing screenshots for visual regression testing
- Testing responsive designs and mobile emulation
- Debugging UI issues with browser developer tools
Core Principles
- Wait for Rendering - Blazor renders asynchronously; use proper wait strategies
- Test Attributes - Use
data-testordata-testidattributes for stable selectors - Headless by Default - Run tests headless in CI, headed for local debugging
- Handle Error UI - Always check for
#blazor-error-uito catch unhandled exceptions - Avoid Network Wait States - Blazor navigation doesn't trigger network loads; wait for DOM changes
- Pin Browser Channels - Use specific browser channels (msedge, chrome) for reproducibility
Required NuGet Packages
<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="*" />
<PackageReference Include="Microsoft.Playwright.MSTest" Version="*" />
<!-- OR for xUnit -->
<PackageReference Include="xunit" Version="*" />
<PackageReference Include="xunit.runner.visualstudio" Version="*" />
</ItemGroup>
Installation
Before running tests, install Playwright browsers:
pwsh -Command "playwright install --with-deps"
Pattern 1: Basic Playwright Setup
using Microsoft.Playwright;
public class PlaywrightFixture : IAsyncLifetime
{
private IPlaywright? _playwright;
private IBrowser? _browser;
public IBrowser Browser => _browser
?? throw new InvalidOperationException("Browser not initialized");
public async Task InitializeAsync()
{
_playwright = await Playwright.CreateAsync();


