Playwright Integration
End-to-end browser testing with Playwright for .NET.
Overview
C# Dev Tools supports Playwright test projects for browser automation testing.
Test Discovery
Playwright tests are discovered automatically:
- Test Explorer recognizes Playwright test projects
- Tests appear alongside unit tests
- Organized by test class and method
Running Playwright Tests
Run browser tests like any other test:
- Click "Run Test" in Test Explorer
- Or right-click test project: "Run Tests"
- Browser launches and executes tests
- Results appear in Test Explorer
Debugging Playwright Tests
Debug browser interactions:
- Set breakpoints in test code
- Click "Debug Test" in Test Explorer
- Debugger stops at breakpoints
- Inspect browser state and variables
Creating Playwright Tests
Create test files with templates:
- Use Quick Add:
MyPlaywrightTest.cs
- Or right-click: Add > New File
- Template includes Playwright setup
Common Scenarios
Page Navigation
await page.GotoAsync("https://example.com");
Element Interaction
await page.ClickAsync("#submit-button");
await page.FillAsync("#username", "testuser");
Assertions
await Expect(page.Locator("h1")).ToHaveTextAsync("Welcome");
Best Practices
- Use Page Object Model pattern
- Keep tests independent
- Use proper wait strategies
- Clean up browser state between tests
- Configure timeouts appropriately
Configuration
Configure Playwright in test project:
- Browser types (Chromium, Firefox, WebKit)
- Headless vs headed mode
- Screenshots on failure
- Video recording
- Timeout settings
Integration Benefits
- Unified test management
- Combined unit and E2E test results
- Consistent debugging experience
- Single test runner for all tests