| name | playwright-dotnet-refactor |
| description | Refactor generated Playwright .NET test drafts into readable xUnit tests with role-based locators, intent-based assertions, and minimal helper extraction. Use when a generated Playwright test is noisy, brittle, or hard to maintain and needs cleanup without changing user intent. |
| metadata | {"author":"nimblepros","version":"1.0","spec":"agentskills.io"} |
Playwright .NET Refactor Skill
Purpose
Turn generated Playwright .NET test code into maintainable xUnit tests while preserving the original user journey and intent.
Use This Skill When
- You have generated Playwright C# code from codegen and want production-quality tests.
- Selectors are brittle (CSS-heavy, position-dependent, implementation-coupled).
- Assertions are missing, weak, or coupled to internals instead of user-visible outcomes.
- Test flow is hard to read and would benefit from light structure.
Inputs To Gather Before Refactor
- Raw generated Playwright C# test draft.
- Intended user scenario in one sentence.
- Target location for test (file/class name).
- Existing fixture and conventions in the repo (for this repo, prefer xUnit and BrowserFixture patterns).
- Any known app constraints (auth state, seed data, environment, flaky selectors).
Refactor Rules
- Preserve user intent.
- Keep the same user-visible workflow and expected behavior.
- Do not silently add or remove meaningful scenario steps.
- Prefer role-based locators.
- Prioritize GetByRole, then GetByLabel/GetByPlaceholder, then GetByText, then GetByTestId.
- Avoid brittle CSS/XPath selectors unless no better semantic locator exists.
- Produce readable xUnit tests.
- Use clear test names describing behavior and expected outcome.
- Keep Arrange/Act/Assert intent obvious through structure and naming.
- Minimize incidental complexity in the main test body.
- Extract helpers only when readability improves.
- Extract repeated or noisy interaction sequences.
- Keep helpers small and intention-revealing.
- Do not introduce abstractions that hide simple steps.
- Avoid implementation-detail assertions.
- Assert only user-observable behavior (visible text, accessible state, navigation outcome, enabled/disabled controls, etc.).
- Do not assert internal IDs, hidden DOM structure, CSS class internals, or framework-specific plumbing unless user-visible behavior depends on them.
- Keep tests deterministic.
- Prefer Playwright assertions and explicit waits tied to user-visible conditions.
- Avoid arbitrary sleeps.
Output Contract
Return:
- Refactored C# xUnit test code.
- Optional helper/page object code only if it materially improves readability.
- Short rationale list covering:
- Locator improvements made.
- Assertion improvements made.
- Helper extraction decisions.
- Any uncertainty or assumptions.
Quality Gate Checklist
- User intent preserved.
- Locators are semantic and stable.
- Assertions are user-observable.
- Test reads clearly top-to-bottom.
- No unnecessary abstraction introduced.
- No arbitrary waits or timing hacks.
Prompt Starter
Use assets/refactor-prompt-template.md as the reusable Level 2 prompt.