Skip to main content

Overview

VaadinElement is the abstract base class for all Vaadin component wrappers in Drama Finder. It exposes common helpers for clicking, visibility assertions, text retrieval, and generic DOM property access. Concrete component classes extend this base and add component-specific APIs.

Constructor

VaadinElement(Locator locator)

Creates a new VaadinElement wrapper.
locator
Locator
required
The Playwright locator pointing to the component root element

Methods

click()

Clicks the component root element.
ButtonElement button = ButtonElement.getByText(page, "Click me");
button.click();
return
void
This method does not return a value

getText()

Gets the textual content of the component root element.
ButtonElement button = ButtonElement.getByText(page, "Submit");
String text = button.getText();
assertEquals("Submit", text);
return
String
The text content, or null if none

getLocator()

Gets the underlying Playwright locator for the component.
TextFieldElement textField = TextFieldElement.getByLabel(page, "Username");
Locator locator = textField.getLocator();
assertThat(locator).hasAttribute("label", "Username");
return
Locator
The Playwright locator for this element

setProperty(String name, Object value)

Sets a DOM property on the underlying element (e.g., value, disabled).
name
String
required
The property name to set
value
Object
required
The property value to assign
TextFieldElement textField = TextFieldElement.getByLabel(page, "Email");
textField.setProperty("value", "[email protected]");
textField.setProperty("disabled", true);
return
void
This method does not return a value

getProperty(String name)

Gets a DOM property from the underlying element.
name
String
required
The property name to retrieve
TextFieldElement textField = TextFieldElement.getByLabel(page, "Email");
Object value = textField.getProperty("value");
assertEquals("[email protected]", value);
return
Object
The property value, or null if the property is absent

isVisible()

Checks whether the component is visible.
ButtonElement button = ButtonElement.getByText(page, "Submit");
if (button.isVisible()) {
    button.click();
}
return
boolean
true when the element is visible, false otherwise

assertVisible()

Asserts that the component is visible. This assertion auto-retries until the timeout is reached.
TextFieldElement textField = TextFieldElement.getByLabel(page, "Username");
textField.assertVisible();
return
void
Throws an assertion error if the element is not visible

isHidden()

Checks whether the component is hidden.
ButtonElement button = ButtonElement.getByText(page, "Hidden Button");
assertTrue(button.isHidden());
return
boolean
true when the element is hidden, false otherwise

assertHidden()

Asserts that the component is hidden. This assertion auto-retries until the timeout is reached.
ButtonElement button = ButtonElement.getByText(page, "Hidden Button");
button.assertHidden();
return
void
Throws an assertion error if the element is visible

Usage Examples

Basic Interaction

@Test
public void testButtonClick() {
    ButtonElement button = ButtonElement.getByText(page, "Click me");
    button.assertVisible();
    button.click();
    assertThat(page.getByText("Button clicked!")).isVisible();
}

Property Manipulation

@Test
public void testPropertyAccess() {
    TextFieldElement textField = TextFieldElement.getByLabel(page, "Email");
    
    // Set property
    textField.setProperty("value", "[email protected]");
    
    // Get property
    Object value = textField.getProperty("value");
    assertEquals("[email protected]", value);
}

Visibility Checks

@Test
public void testVisibility() {
    ButtonElement visibleButton = ButtonElement.getByText(page, "Visible");
    ButtonElement hiddenButton = ButtonElement.getByText(page, "Hidden");
    
    visibleButton.assertVisible();
    assertTrue(visibleButton.isVisible());
    
    hiddenButton.assertHidden();
    assertTrue(hiddenButton.isHidden());
}

Text Content Retrieval

@Test
public void testTextContent() {
    ButtonElement button = ButtonElement.getByText(page, "Submit Form");
    String text = button.getText();
    assertEquals("Submit Form", text);
}

Notes

  • All assertion methods use Playwright’s auto-retry mechanism and will wait until the condition is met or the timeout is reached.
  • The getProperty() and setProperty() methods operate on DOM properties, not HTML attributes. Use getLocator().getAttribute() for HTML attributes.
  • Concrete component classes like ButtonElement, TextFieldElement, etc., extend this base class and inherit all these methods.
  • The isVisible() and isHidden() methods are inverses of each other: isHidden() returns !isVisible().

Build docs developers (and LLMs) love