Locator Patterns
Drama Finder uses sophisticated locator patterns to handle Vaadin’s shadow DOM structure and component composition. Understanding these patterns helps you work with complex components and create custom element wrappers.Locator Delegation Pattern
Elements delegate to specific internal locators for different operations. This pattern ensures actions and assertions target the correct DOM element within a component’s shadow DOM.Why Delegation Matters
Vaadin components often have a wrapper element and internal input elements. Different operations need to target different parts:Focus Locator
The focus locator determines which element receives keyboard focus:Enabled Locator
The enabled locator determines where to check the disabled state:ARIA Label Locator
The ARIA label locator specifies which element has thearia-label attribute:
Complete Example
Different component aspects (focus, enablement, aria-label) may target different internal elements. Locator delegation ensures each operation uses the correct target.
Component vs Input Locator
Understanding when to use the component locator versus the input locator is crucial:Component Locator (getLocator)
Use for component-level attributes and state:Input Locator (getInputLocator)
Use for input-specific operations:Real-World Example
Shadow DOM Piercing
Playwright automatically pierces shadow DOM with CSS selectors, but XPath requires explicit handling.CSS Selectors (Auto-Pierce)
XPath (Explicit Non-Pierce)
Part Selectors
Vaadin components expose internal elements viapart attributes for styling and testing:
Common Parts
Mixin Interfaces (Composition)
Shared behavior is extracted into interfaces with default implementations:Common Mixins
FocusableElement- Focus and blur operationsHasInputFieldElement- Value, label, helper textHasValidationPropertiesElement- Validation state and messagesHasEnabledElement- Enabled/disabled stateHasClearButtonElement- Clear button interactionHasPrefixElement- Prefix slot contentHasSuffixElement- Suffix slot contentHasThemeElement- Theme variant checking
Composite Element Pattern
Complex components compose simpler elements internally:Using Composite Elements
Scoped Lookup Pattern
Factory methods support both page-level and scoped lookups:Practical Scoping
Grid Cell Access Pattern
Grid uses a specialized pattern for accessing virtualized cells:Grid Locator Delegation
Grid cells delegate to different locators:Advanced Locator Chaining
Filter Options
And/Or Combinations
Creating Custom Elements
When creating custom element wrappers, follow these patterns:1. Extend VaadinElement
2. Implement Relevant Mixins
3. Override Locator Delegation
4. Add Factory Methods
Best Practices
Use part selectors for internal elements
Use part selectors for internal elements
Prefer
part selectors over complex CSS for accessing internal component elements:Delegate to the correct locator
Delegate to the correct locator
Always use the appropriate locator for each operation:
Leverage mixin composition
Leverage mixin composition
Implement mixins to inherit common behavior instead of duplicating code:
Always use .first() for uniqueness
Always use .first() for uniqueness
Factory methods should always call
.first() to avoid ambiguous matches:Common Pitfalls
Related Concepts
- Element Lookup - Factory methods and lookup patterns
- ARIA Roles - Role-based element selection
- Assertions - Testing with the correct locators