Skip to main content

Overview

The PasswordFieldElement class is a Playwright wrapper for the <vaadin-password-field> component. It extends TextFieldElement with password input masking.

Component Tag

<vaadin-password-field>

Extends

  • TextFieldElement

Inherited Interfaces

  • HasValidationPropertiesElement - Validation state and error messages
  • HasInputFieldElement - Value, label, helper text, and styling
  • HasPrefixElement - Prefix slot content
  • HasSuffixElement - Suffix slot content
  • HasClearButtonElement - Clear button functionality
  • HasPlaceholderElement - Placeholder text
  • HasAllowedCharPatternElement - Character input restrictions
  • HasThemeElement - Theme variants
  • FocusableElement - Focus and blur operations
  • HasAriaLabelElement - ARIA label support
  • HasEnabledElement - Enabled/disabled state
  • HasTooltipElement - Tooltip text

Constructor

locator
Locator
required
The Playwright locator for the <vaadin-password-field> element
public PasswordFieldElement(Locator locator)

Factory Methods

getByLabel

Get a password field by its accessible label. Uses ARIA role textbox.
page
Page
required
The Playwright page
label
String
required
The accessible label of the password field
public static PasswordFieldElement getByLabel(Page page, String label)

Example

PasswordFieldElement passwordField = PasswordFieldElement.getByLabel(page, "Password");
passwordField.setValue("SecureP@ssw0rd");
passwordField.assertValid();

Inherited Methods

From TextFieldElement:
  • getMinLength() - Get minimum length
  • setMinLength(int min) - Set minimum length
  • assertMinLength(Integer min) - Assert minimum length
  • getMaxLength() - Get maximum length
  • setMaxLength(int max) - Set maximum length
  • assertMaxLength(Integer max) - Assert maximum length
  • getPattern() - Get validation pattern
  • setPattern(String pattern) - Set validation pattern
  • assertPattern(String pattern) - Assert validation pattern
From HasValueElement:
  • getValue() - Get current value
  • setValue(String value) - Set field value
  • clear() - Clear the value
  • assertValue(String value) - Assert value matches
From HasValidationPropertiesElement:
  • assertValid() - Assert field is valid
  • assertInvalid() - Assert field is invalid
  • assertErrorMessage(String message) - Assert error message text
  • getErrorMessageLocator() - Get error message locator
From HasClearButtonElement:
  • clickClearButton() - Click the clear button
  • isClearButtonVisible() - Check if clear button is visible
  • assertClearButtonVisible() - Assert clear button is visible
  • assertClearButtonNotVisible() - Assert clear button is not visible
From HasPlaceholderElement:
  • getPlaceholder() - Get placeholder text
  • setPlaceholder(String placeholder) - Set placeholder text
  • assertPlaceholder(String placeholder) - Assert placeholder matches
From FocusableElement:
  • focus() - Focus the field
  • blur() - Blur the field
  • getTabIndex() - Get tab index
  • assertIsFocused() - Assert field has focus
  • assertIsNotFocused() - Assert field does not have focus
From HasLabelElement:
  • getLabel() - Get label text
  • assertLabel(String label) - Assert label text
  • getLabelLocator() - Get label locator
From HasHelperElement:
  • getHelperText() - Get helper text
  • assertHelperHasText(String text) - Assert helper text
  • getHelperLocator() - Get helper locator

Complete Example

@Test
public void testPasswordFieldValidation() {
    // Find password field by label
    PasswordFieldElement passwordField = PasswordFieldElement.getByLabel(page, "Validated PasswordField");
    passwordField.assertVisible();
    
    // Check validation constraints
    passwordField.assertMinLength(6);
    passwordField.assertMaxLength(7);
    passwordField.assertPattern("\\d{7}");
    
    // Test invalid value
    passwordField.setValue("1");
    passwordField.assertInvalid();
    passwordField.assertErrorMessage("Minimum length is 6 characters");
    
    // Test valid value
    passwordField.setValue("1238456");
    passwordField.assertValid();
    passwordField.assertValue("1238456");
}

@Test
public void testPasswordFieldInteractions() {
    PasswordFieldElement passwordField = PasswordFieldElement.getByLabel(page, "PasswordField with placeholder and clear button");
    
    // Check placeholder
    passwordField.assertPlaceholder("Enter text here");
    
    // Test clear button
    passwordField.assertClearButtonNotVisible();
    passwordField.setValue("some value");
    passwordField.assertClearButtonVisible();
    passwordField.clear();
    passwordField.assertValue("");
    
    // Test focus state
    passwordField.focus();
    passwordField.assertIsFocused();
}

Build docs developers (and LLMs) love