Playwright janitor violations reduced by 43
Test infrastructure cleanup resolves 43 violations in Playwright locator patterns, improving test reliability by scoping elements to containers instead of the full page.
The test suite's Playwright janitor was flagging 408 violations — loose locator patterns that could lead to flaky or incorrect element selection. A targeted cleanup effort has resolved 43 of those violations, bringing the count down to 365.
The core problem was twofold: some page objects lacked proper navigation methods (the janitor's scope-lockdown rule), while others chained selectors directly off this.page instead of scoping to container elements (the selector-purity rule). When locators search the entire page, they risk grabbing elements from modals, sidebars, or other components that happen to match first.
The fix introduces container getters across multiple page objects. Instead of this.page.getByTestId('ask-assistant-chat'), methods now return this.container.getByTestId('ask-assistant-chat'). This pins locators to their correct scope — the chat sidebar, the node details view, the settings modal.
Seven new convenience methods were added to NodeDetailsViewPage for common interactions: retrieving parameter textboxes, toggling assignment expressions, accessing resource locators. A getContainer() method was converted to a container getter, and goto() navigation was added where missing.
In the @n8n/playwright package, locator patterns are now more resilient. Tests targeting specific UI regions won't accidentally interact with similarly-named elements elsewhere on the page.
View Original GitHub DescriptionFact Check
Summary
- Resolve 43 Playwright janitor violations (408 → 365), targeting scope-lockdown and selector-purity rules
- Add
goto()methods to 8 ambiguous page objects so the janitor skips them (scope-lockdown) - Refactor
NodeDetailsViewPage.getContainer()→get container()getter - Replace chained locator calls in 14 test files with existing/new page object methods (selector-purity)
- Add 7 new convenience methods to
NodeDetailsViewPage:getParameterTextboxByLabel,getParameterTextarea,getAssignmentExpressionToggle,getAssignmentNameTextbox,getAssignments,getResourceLocatorInputField,getResourceLocatorLink - Update
.janitor-baseline.jsonto reflect new 365 violation count
Test plan
- Typecheck passes (
pnpm --filter=n8n-playwright typecheck) - Janitor reports 0 new violations (
pnpm --filter=n8n-playwright janitor) - E2E tests pass in CI (no functional changes, only locator routing)
🤖 Generated with Claude Code