Skip to main content

Overview

HasValidationPropertiesElement provides methods for interacting with Vaadin components that support validation states and error messages. It allows you to check whether a component is valid or invalid, and to assert the presence and content of error messages. Interface Location: org.vaadin.addons.dramafinder.element.shared.HasValidationPropertiesElement

Methods

getErrorMessageLocator()

Returns a locator for the error message slot element. Returns: Locator - Locator for the element with slot="error-message"

assertValid()

Asserts that the component is valid (does not have the invalid attribute). Throws: AssertionError if the component has the invalid attribute

assertInvalid()

Asserts that the component is invalid (has the invalid attribute). Throws: AssertionError if the component does not have the invalid attribute

assertErrorMessage()

Asserts that the error message equals the expected text.
String
required
The expected error message text
Throws: AssertionError if the error message does not match

Implementing Classes

The following element classes implement HasValidationPropertiesElement:
  • TextFieldElement (and its subclasses)
  • AbstractNumberFieldElement (and its subclasses)
  • DatePickerElement
  • DateTimePickerElement
  • TimePickerElement
  • RadioButtonGroupElement

Usage Example

Implementation Details

Error Message Slot

Vaadin components use a slot-based architecture for error messages. The getErrorMessageLocator() method targets elements with slot="error-message", which is where Vaadin renders validation error messages in the shadow DOM.

Validation Attribute

Vaadin components indicate validation state through the invalid HTML attribute. When a component fails validation, the invalid attribute is set to an empty string (invalid=""). The assertValid() and assertInvalid() methods check for the presence or absence of this attribute.

Testing Patterns

Validation After User Input

Server-Side Validation

Required Field Validation