Playwright-Dotnet
Playwright-Dotnet是一款code方向的AI技能,核心价值是Playwright ,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Playwright .NET test generation instructions
mkdir -p ./skills/playwright-dotnet && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/playwright-dotnet/SKILL.md -o ./skills/playwright-dotnet/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# Playwright .NET Test Generation Instructions
Test Writing Guidelines
Code Quality Standards
- **Locators**: Prioritize user-facing, role-based locators (`GetByRole`, `GetByLabel`, `GetByText`, etc.) for resilience and accessibility. Use `await Test.StepAsync()` to group interactions and improve test readability and reporting.
- **Assertions**: Use auto-retrying web-first assertions. These assertions use `Expect()` from Playwright assertions (e.g., `await Expect(locator).ToHaveTextAsync()`). Avoid checking visibility unless specifically testing for visibility changes.
- **Timeouts**: Rely on Playwright's built-in auto-waiting mechanisms. Avoid hard-coded waits or increased default timeouts.
- **Clarity**: Use descriptive test and step titles that clearly state the intent. Add comments only to explain complex logic or non-obvious interactions.
Test Structure
- **Usings**: Start with `using Microsoft.Playwright;` and either `using Microsoft.Playwright.Xunit;` or `using Microsoft.Playwright.NUnit;` or `using Microsoft.Playwright.MSTest;` for MSTest.
- **Organization**: Create test classes that inherit from `PageTest` (available in NUnit, xUnit, and MSTest packages) or use `IClassFixture<PlaywrightFixture>` for xUnit with custom fixtures. Group related tests for a feature in the same test class.
- **Setup**: Use `[SetUp]` (NUnit), `[TestInitialize]` (MSTest), or constructor initialization (xUnit) for setup actions common to all tests (e.g., navigating to a page).
- **Titles**: Use the appropriate test attribute (`[Test]` for NUnit, `[Fact]` for xUnit, `[TestMethod]` for MSTest) with descriptive method names following C# naming conventions (e.g., `SearchForMovieByTitle`).
File Organization
- **Location**: Store all test files in a `Tests/` directory or organize by feature.
- **Naming**: Use the convention `<FeatureOrPage>Tests.cs` (e.g., `LoginTests.cs`, `SearchTests.cs`).
- **Scope**: Aim for one test class per major application feature or page.
Assertion Best Practices
- **UI Structure**: Use `ToMatchAriaSnapshotAsync` to verify the accessibility tree structure of a component. This provides a comprehensive and accessible snapshot.
- **Element Counts**: Use `ToHaveCountAsync` to assert the number of elements found by a locator.
- **Text Content**: Use `ToHaveTextAsync` for exact text matches and `ToContainTextAsync` for partial matches.
- **Navigation**: Use `ToHaveURLAsync` to verify the page URL after an action.
Example Test Structure
using Microsoft.Playwright;
using Microsoft.Playwright.Xunit;
using static Microsoft.Playwright.Assertions;
namespace PlaywrightTests;
public class MovieSearchTests : PageTest
{
public override async Task InitializeAsync()
{
await base.InitializeAsync();
// Navigate to the application before each test
await Page.GotoAsync("https://debs-obrien.github.io/playwright-movies-app");
}
[Fact]
public async Task SearchForMovieByTitle()
{
await Test.StepAsync("Activate and perform search", async () =>
{
await Page.GetByRole(AriaRole.Search).ClickAsync();
var searchInput = Page.GetByRole(AriaRole.Textbox, new() { Name = "Search Input" });
await searchInput.FillAsync("Garfield");
await searchInput.PressAsync("Enter");
});
await Test.StepAsync("Verify search results", async () =>
{
// Verify the accessibility tree of the search results
await Expect(Page.GetByRole(AriaRole.Main)).ToMatchAriaSnapshotAsync(@"
- main:
- heading ""Garfield"" [level=1]
- heading ""search results"" [level=2]
- list ""movies"":
- listitem ""movie"":
- link ""poster of The Garfield Movie The Garfield Movie rating"":
- /url: /playwright-movies-app/movie?id=tt5779228&page=1
- i🎯 Best For
- QA engineers
- Developers writing unit tests
- Claude users
- GitHub Copilot users
- Software engineers
💡 Use Cases
- Generating test cases for edge conditions
- Writing integration test suites
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Playwright-Dotnet to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Does this generate test mocks?
Many testing skills include mock generation. Check the install command and skill content for details.
Is Playwright-Dotnet compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Playwright-Dotnet?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Playwright-Dotnet?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/playwright-dotnet/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Not testing edge cases
AI tends to generate happy-path tests. Manually review for boundary conditions.
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.