ARIA Roles
Drama Finder uses ARIA (Accessible Rich Internet Applications) roles as the foundation for element lookup. This approach ensures your tests interact with components the same way assistive technologies and real users do, promoting both test reliability and application accessibility.Why ARIA Roles Matter
ARIA roles define the semantic meaning of elements for assistive technologies. By using ARIA roles in tests, you:- Test accessibility: Ensure your application is usable by screen readers and other assistive tools
- Write resilient tests: Role-based lookups are less brittle than CSS selectors or IDs
- Follow best practices: Align with Playwright’s recommended testing patterns
- Improve maintainability: Tests remain valid even when implementation details change
ARIA Role Mapping
Every Vaadin component has internal elements with specific ARIA roles. Drama Finder factory methods leverage these roles for accurate element lookup.Input Fields
Text Input (TEXTBOX)
TEXTBOX role:
TextFieldElementEmailFieldElementPasswordFieldElementTextAreaElement
Number Input (SPINBUTTON)
SPINBUTTON role:
IntegerFieldElementBigDecimalFieldElementNumberFieldElement
Date and Time Pickers (COMBOBOX)
COMBOBOX role:
DatePickerElementTimePickerElementDateTimePickerElementComboBoxElement
ComboBox and date/time pickers use the
COMBOBOX role because they allow both selection from a list and keyboard input.Interactive Controls
Buttons (BUTTON)
Checkboxes (CHECKBOX)
Radio Buttons (RADIO)
Common Pitfall: Wrong ARIA Role
Example: Date Picker Role Mismatch
Verifying ARIA Roles
To verify the correct ARIA role for an element:- Inspect the browser: Use DevTools to examine the element’s
roleattribute - Check documentation: Refer to the element class Javadoc
- Try the lookup: Factory methods use the correct role automatically
Role-Based Filtering
Factory methods combine tag names with ARIA role filtering for precise matching:- Component type accuracy: Only matches the correct Vaadin component tag
- Accessible name matching: Finds elements by their label or text
- Unique selection: Returns the first match to avoid ambiguity
Accessible Names
ARIA roles work with accessible names, which can come from:- Labels:
<label>elements oraria-labelattributes - Text content: Visible text inside buttons or links
- aria-labelledby: References to other elements
- title attributes: Fallback for icon-only elements
Testing Without Visible Labels
For components without visible labels (like icon buttons), usearia-label:
Custom Role Options
Playwright’sGetByRoleOptions provides additional filters:
Complete ARIA Role Reference
| ARIA Role | Usage | Drama Finder Components |
|---|---|---|
TEXTBOX | Single-line text input | TextFieldElement, EmailFieldElement, PasswordFieldElement |
SPINBUTTON | Numeric input with increment/decrement | IntegerFieldElement, BigDecimalFieldElement, NumberFieldElement |
COMBOBOX | Dropdown with filtering | ComboBoxElement, DatePickerElement, TimePickerElement, DateTimePickerElement |
BUTTON | Clickable button | ButtonElement |
CHECKBOX | Checkable input | CheckboxElement |
RADIO | Radio button option | RadioButtonElement |
LINK | Navigation link | Not directly wrapped |
DIALOG | Modal dialog | DialogElement (container) |
GRID | Data table | GridElement (container) |
Debugging ARIA Role Issues
Issue: Element Not Found
- Verify the label text: Check for typos or case sensitivity
- Inspect the element: Open DevTools and check the
roleattribute - Check shadow DOM: Ensure the input element is inside the component’s shadow DOM
- Verify accessible name: Check if the label is properly associated
Issue: Wrong Element Matched
- Use scoped lookup: Restrict search to a specific container
- Use more specific labels: Ensure labels are unique
- Add
.first(): Factory methods already use it, but check custom locators
Best Practices
Always verify accessible names
Always verify accessible names
Before writing tests, ensure your components have accessible names:
Use factory methods for role-based lookup
Use factory methods for role-based lookup
Let factory methods handle the correct ARIA role mapping:
Test with screen readers
Test with screen readers
Periodically test your application with a screen reader to verify that:
- All interactive elements have accessible names
- ARIA roles are correctly applied
- Navigation and interaction work as expected
Related Concepts
- Element Lookup - Factory methods using ARIA roles
- Assertions - Testing element state and behavior
- Locator Patterns - Advanced locator techniques