Skip to main content

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()

Returns a locator for the tooltip content element, which has the ARIA role of 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()

Retrieves the text content of the tooltip. Returns: String - The tooltip text content

assertTooltipHasText()

Asserts that the tooltip has the expected text. When null is provided, asserts that the tooltip is not visible.
String
The expected tooltip text, or null to assert the tooltip is not visible
Throws: AssertionError if the tooltip text does not match or visibility does not match expectation

Implementing Classes

The following element classes implement HasTooltipElement:
  • AvatarElement
  • ListBoxElement
  • TextFieldElement (and all subclasses)
  • Any component that uses Vaadin’s HasTooltip mixin

Usage Example

Implementation Details

ARIA Role Tooltip

The implementation uses ARIA role-based selection to find tooltips:
The 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
Tooltips automatically hide when:
  • The mouse moves away
  • Focus moves to another element
  • The user presses Escape

Inner Text Option

The assertion uses setUseInnerText(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 ARIA tooltip role helps with this:

Common Use Cases

Icon Button Descriptions

Disabled Element Explanations

Abbreviation Expansions

Keyboard Shortcut Hints