Skip to main content

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
If your test can’t find an element by its ARIA role, it’s a signal that your application may have accessibility issues that need fixing.

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)

Components using TEXTBOX role:
  • TextFieldElement
  • EmailFieldElement
  • PasswordFieldElement
  • TextAreaElement

Number Input (SPINBUTTON)

Components using SPINBUTTON role:
  • IntegerFieldElement
  • BigDecimalFieldElement
  • NumberFieldElement

Date and Time Pickers (COMBOBOX)

Components using COMBOBOX role:
  • DatePickerElement
  • TimePickerElement
  • DateTimePickerElement
  • ComboBoxElement
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

Using the wrong ARIA role in getByRole() lookups will cause your tests to fail.

Example: Date Picker Role Mismatch

Verifying ARIA Roles

To verify the correct ARIA role for an element:
  1. Inspect the browser: Use DevTools to examine the element’s role attribute
  2. Check documentation: Refer to the element class Javadoc
  3. 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:
This multi-step approach ensures:
  1. Component type accuracy: Only matches the correct Vaadin component tag
  2. Accessible name matching: Finds elements by their label or text
  3. Unique selection: Returns the first match to avoid ambiguity

Accessible Names

ARIA roles work with accessible names, which can come from:
  • Labels: <label> elements or aria-label attributes
  • Text content: Visible text inside buttons or links
  • aria-labelledby: References to other elements
  • title attributes: Fallback for icon-only elements
If a factory method can’t find your element, verify that it has an accessible name (label, text content, or aria-label).

Testing Without Visible Labels

For components without visible labels (like icon buttons), use aria-label:

Custom Role Options

Playwright’s GetByRoleOptions provides additional filters:

Complete ARIA Role Reference

Debugging ARIA Role Issues

Issue: Element Not Found

Debugging steps:
  1. Verify the label text: Check for typos or case sensitivity
  2. Inspect the element: Open DevTools and check the role attribute
  3. Check shadow DOM: Ensure the input element is inside the component’s shadow DOM
  4. Verify accessible name: Check if the label is properly associated

Issue: Wrong Element Matched

Solutions:
  1. Use scoped lookup: Restrict search to a specific container
  2. Use more specific labels: Ensure labels are unique
  3. Add .first(): Factory methods already use it, but check custom locators

Best Practices

Before writing tests, ensure your components have accessible names:
Let factory methods handle the correct ARIA role mapping:
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