agentleFS
Sorcha-PlatformSorcha-Platform/Sorcha/.claude/skills/playwright/SKILL.md

playwright

Skill2 starsChanged 10 months agoMITView on GitHub

Develops end-to-end UI tests with Playwright for Blazor applications. Use when: Writing E2E tests, testing Blazor WASM pages, validating UI flows, checking responsive design, detecting JavaScript errors, or testing MudBlazor components.

55 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use doc, web-perf and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • JetBrainsSkill

    doc

    Use when the task involves reading, creating, or editing `.docx` documents, especially when formatting or layout fidelity matters; prefer `python-docx` plus the bundled `scripts/render_docx.py` for visual checks.

    Also in 5 projects that use this

  • OpenAISkill

    web-perf

    Analyzes web performance using Chrome DevTools MCP. Measures Core Web Vitals (FCP, LCP, TBT, CLS, Speed Index), identifies render-blocking resources, network dependency chains, layout shifts, caching issues, and accessibility gaps. Use when asked to audit, profile, debug, or optimize page load performance, Lighthouse scores, or site speed. Biases towards retrieval from current documentation over pre-trained knowledge.

    Also in 4 projects that use this

  • CloudflareSkill

    turnstile-spin

    Set up, repair, or migrate to Cloudflare Turnstile bot verification in an existing frontend and backend, including server-side Siteverify.

    Also in 3 projects that use this

  • CloudflareSkill

    cloudflare-one

    Design, configure, troubleshoot, or review Cloudflare One Zero Trust and SASE deployments. Use cloudflare-one-migrations for migration planning from other vendors.

    Also in 3 projects that use this

  • kayamanSkill

    edit-article

    Edit and improve articles by restructuring sections, improving clarity, and tightening prose. Use when user wants to edit, revise, or improve an article draft.

    Also in 4 projects that use this

  • OpenAISkill

    durable-objects

    Create and review Cloudflare Durable Objects. Use when building stateful coordination (chat rooms, multiplayer games, booking systems), implementing RPC methods, SQLite storage, alarms, WebSockets, or reviewing DO code for best practices. Covers Workers integration, wrangler config, and testing with Vitest. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

    Also in 3 projects that use this

  • +2 more from openai

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 50 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every nav-triggering locator gets a corresponding Click_RoutesTo<Page> test that asserts the URL after the click.

    line 118
  2. Distinctive:

    Every state-mutating button gets a click + assert-on-resulting-state test.

    line 119
  3. Very specific:

    If a locator is for an assertion target only (e.g.

    line 120
  4. Very specific:

    Use mcp__context7__resolve-library-id to search for "playwright"

    line 176

“Common” is measured: kept by at least 6 in 10 of the 50 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Playwright Skill

E2E testing for Blazor WebAssembly using Playwright .NET with NUnit and .NET Aspire integration. Tests run against the full Aspire application stack with all services.

Quick Start

Basic Page Test

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class BlazorUITests : PageTest
{
    private DistributedApplication? _app;
    private string? _blazorUrl;

    [OneTimeSetUp]
    public async Task OneTimeSetUp()
    {
        var appHost = await DistributedApplicationTestingBuilder
            .CreateAsync<Projects.Sorcha_AppHost>();
        _app = await appHost.BuildAsync();
        await _app.StartAsync();
        _blazorUrl = _app.GetEndpoint("blazor-client").ToString();
    }

    [Test]
    public async Task HomePage_LoadsSuccessfully()
    {
        await Page.GotoAsync(_blazorUrl!);
        await Page.WaitForLoadStateAsync();
        await Expect(Page).ToHaveTitleAsync(new Regex("Sorcha|Blueprint"));
    }
}

Locator Patterns

// Role-based (preferred)
await Page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();

// Text-based
Page.Locator("a:has-text('Designer')")

// MudBlazor components
Page.Locator(".mud-button")
Page.Locator(".mud-table")

// Test IDs (most stable)
Page.Locator("[data-testid='my-element']")

Key Concepts

ConceptUsageExample
PageTestBase class providing Page objectclass MyTests : PageTest
LocatorLazy element referencePage.Locator("button")
ExpectAssertion APIawait Expect(Page).ToHaveURLAsync(...)
Aspire TestingFull stack integrationDistributedApplicationTestingBuilder
Auto-waitBuilt-in waitingActions wait for actionability

Common Patterns

JavaScript Error Detection

[Test]
public async Task NoJavaScriptErrors()
{
    var errors = new List<string>();
    Page.Console += (_, msg) =>
    {
        if (msg.Type == "error") errors.Add(msg.Text);
    };

    await Page.GotoAsync(_blazorUrl!);
    await Page.WaitForLoadStateAsync();
    
    var criticalErrors = errors.Where(e =>
        !e.Contains("WASM") && !e.Contains("Blazor")).ToList();
    Assert.That(criticalErrors, Is.Empty);
}

Responsive Design Testing

[Test]
public async Task ResponsiveDesign_Works()
{
    await Page.SetViewportSizeAsync(375, 667); // Mobile
    await Page.GotoAsync(_blazorUrl!);
    Assert.That(await Page.TextContentAsync("body"), Is.Not.Empty);

    await Page.SetViewportSizeAsync(1920, 1080); // Desktop
    await Page.ReloadAsync();
    Assert.That(await Page.TextContentAsync("body"), Is.Not.Empty);
}

Anti-pattern: locators declared but never clicked

When a page object declares a locator (EnrolDeviceButton, FooterNavSettings) but no test in the suite ever calls .ClickAsync() on it, you are paying the cost of maintaining the locator without getting any coverage from it. The smell is easy to miss in review: the locator exists, the test compiles, CI is green — but the underlying user gesture has never been exercised end-to-end.

This is exactly how the Citizen Wallet PWA shipped twelve broken navigation buttons (PR #698) past every CI gate. CitizenWalletPage declared EnrolDeviceButton + PresentButton, the test fixture imported them, but no test clicked them. The first time a real human clicked Enrol was on production — every nav button 404'd.

Discipline for new page objects:

  1. Every nav-triggering locator gets a corresponding Click_RoutesTo<Page> test that asserts the URL after the click.
  2. Every state-mutating button gets a click + assert-on-resulting-state test.
  3. If a locator is for an assertion target only (e.g. EmptyState), document that — name it *Indicator / *Banner so future contributors don't expect it to be clicked.

Stable selector convention — use data-testid attributes on every nav element rather than CSS path or text content. Pattern: kebab-case, scope-prefixed (footer-nav-settings, home-present-button, credential-detail-back-button). Survives MudBlazor markup churn; survives localisation.

Example test for a nav-button sweep — one TestCaseSource covering N buttons:

private static IEnumerable<TestCaseData> NavCases
{
    get
    {
        yield return new TestCaseData("footer-nav-devices", "devices").SetName("Footer Devices → /wallet/devices");
        yield return new TestCaseData("footer-nav-settings", "settings").SetName("Footer Settings → /wallet/settings");
        // ... one row per nav element
    }
}

[Test, TestCaseSource(nameof(NavCases))]
public async Task FooterNav_ClickRoutesToExpectedPage(string testId, string expectedSuffix)
{
    await NavigateToWalletAndWaitForBlazorAsync();
    await Page.Locator($"[data-testid='{testId}']").ClickAsync();
    await Page.WaitForURLAsync($"**/wallet/{expectedSuffix}*", new() { Timeout = 5000 });
    Assert.That(new Uri(Page.Url).AbsolutePath,
        Does.StartWith($"/wallet/{expectedSuffix}"));
}

Post-redeploy cache testing for PWAs

A PWA with year-cached entry-point JS (dotnet.js, blazor.webassembly.js — see the blazor skill on this) only breaks on return visits after a redeploy. CI's normal "fresh browser context, fresh container" Playwright runs miss it entirely.

Two cheap regression guards:

  1. HTTP cache-header probes — straight HttpClient against the live PWA, assert dotnet.js and blazor.webassembly.js carry no-cache/must-revalidate and not immutable. No browser needed, sub-second runtime. See tests/Sorcha.UI.E2E.Tests/Docker/CitizenWallet/CitizenWalletNginxCacheHeadersTests.cs.
  2. Browser context reuse across redeploy — non-trivial Playwright dance: visit /wallet/, force fingerprint rotation (rebuild + recreate citizen-wallet container with a tagged content change), navigate again without clearing browser state, assert no wasm fetches 404. Phase 2 of issue #700.

See Also

  • patterns - Locator strategies and assertions
  • workflows - Test setup and CI integration

Related Skills

  • See the xunit skill for unit testing patterns
  • See the fluent-assertions skill for SignalR integration tests
  • See the blazor skill for component architecture
  • See the signalr skill for real-time notification testing
  • See the docker skill for container-based test environments

Documentation Resources

Fetch latest Playwright .NET documentation with Context7.

How to use Context7:

  1. Use mcp__context7__resolve-library-id to search for "playwright"
  2. Prefer website documentation (/websites/playwright_dev_dotnet) over source code
  3. Query with mcp__context7__query-docs using the resolved library ID

Library ID: /websites/playwright_dev_dotnet

Recommended Queries:

  • "Locators selectors best practices"
  • "NUnit test fixtures setup teardown"
  • "Wait for element network idle auto-waiting"
  • "Assertions expect API"
  • "Trace viewer debugging"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.