Instruction file imported from zNatix/pr-reviewer-agent (
.github/instructions/playwright-anti-patterns.instructions.md). Copyright stays with the author.
Playwright for .NET — Anti-patterns
🚫 Anti-patterns to Flag Immediately
🔴 Critical — Block Merge
new Playwright()or manual lifecycle management ofIBrowser/IBrowserContext— use base classes.Resultor.Wait()on async Playwright methods — alwaysawaitThread.Sleep()orTask.Delay()as synchronization mechanism — use assertions with auto-wait- Hardcoded URLs in tests (use
ContextOptions().BaseURLor configuration) - Missing teardown for manually created resources (custom contexts,
RouteAsync, external servers); base class lifecycle (PageTest/ContextTest) handles standard disposal automatically
🟡 Warning
- XPath locators or CSS locators when role/text/label locators are available
Page.WaitForSelectorAsync()beforeClickAsync()— redundant- Tests that depend on execution order (not isolated)
- Multiple
Page.GotoAsync()in the same test to different domains (use separate tests) - Tests without assertions (navigation-only)
Page.ScreenshotAsync()calls withouttry-catch(can hide assertion failures)- Not using
BrowserNewContextOptionsto set consistent viewport/timezone/locale
🔵 Suggestion
- Missing
data-testidattributes when CSS selectors are used repeatedly - Tests longer than 30 lines without helper methods
- Duplicate locator chains across tests (extract to Page Object or helper)
- Using
.Nth()whenfilter()would be clearer/stabler - Overriding
ContextOptions()without callingbase.ContextOptions()for defaults