Overview
HasTooltipElement provides methods for interacting with tooltips on Vaadin components. Tooltips provide additional context or information when users hover over or focus on elements. This interface allows you to locate tooltip content and verify its text in tests.
Interface Location: org.vaadin.addons.dramafinder.element.shared.HasTooltipElement
Methods
getTooltipLocator()
tooltip. The locator includes hidden elements since tooltips are typically hidden until triggered.
Returns: Locator - Locator for the first tooltip element with role="tooltip"
getTooltipText()
String - The tooltip text content
assertTooltipHasText()
null is provided, asserts that the tooltip is not visible.
String
The expected tooltip text, or
null to assert the tooltip is not visibleAssertionError if the tooltip text does not match or visibility does not match expectation
Implementing Classes
The following element classes implementHasTooltipElement:
AvatarElementListBoxElementTextFieldElement(and all subclasses)- Any component that uses Vaadin’s
HasTooltipmixin
Usage Example
Implementation Details
ARIA Role Tooltip
The implementation uses ARIA role-based selection to find tooltips:setIncludeHidden(true) option is essential because tooltips are typically hidden in the DOM until triggered by user interaction.
Tooltip Visibility
Tooltips in Vaadin are shown when:- The user hovers over the element with a mouse
- The element receives keyboard focus
- The tooltip is programmatically triggered
- The mouse moves away
- Focus moves to another element
- The user presses Escape
Inner Text Option
The assertion usessetUseInnerText(true) to properly handle nested elements within the tooltip:
Testing Patterns
Test Tooltip on Hover
Test Tooltip on Focus
Test Informational Tooltips
Test Tooltip Accessibility
Test Tooltip Position
Best Practices
Wait for Tooltip Appearance
Tooltips often have a delay before appearing. Always wait briefly after hovering:Test Tooltip Dismissal
Verify tooltips hide when appropriate:Use Tooltips for Non-Critical Info
Tooltips should enhance, not replace, essential information:Test Tooltip Content Quality
Verify tooltips provide helpful information:Consider Screen Readers
Tooltips should be accessible to screen readers. The ARIAtooltip role helps with this:
Common Use Cases
Icon Button Descriptions
Disabled Element Explanations
Abbreviation Expansions
Keyboard Shortcut Hints
Related Interfaces
- HasAriaLabelElement - For accessible names on elements
- HasHelperElement - For persistent help text below fields
- FocusableElement - Tooltips often appear on focus