Skip to main content

AvatarElement

Playwright element wrapper for <vaadin-avatar> providing helpers to read and modify avatar properties (name, abbreviation, image, color index).

Component Tag

vaadin-avatar

Implements

  • FocusableElement - Focus management
  • HasStyleElement - CSS class and style management
  • HasThemeElement - Theme variant support
  • HasTooltipElement - Tooltip text

Constructor

locator
Locator
required
Playwright locator for the <vaadin-avatar> element

Static Factory Methods

get

Get the first avatar on the page or within a scope.
AvatarElement.get(Page page)
AvatarElement.get(Locator locator)
page
Page
Playwright page
locator
Locator
Scope containing the avatar

getByName

Get an avatar by its name attribute.
AvatarElement.getByName(Page page, String name)
AvatarElement.getByName(Locator locator, String name)
page
Page
Playwright page
locator
Locator
Scope containing the avatar
name
String
Avatar’s name attribute value

Property Methods

getName

Get the avatar’s name.
String getName()
Returns the name, or null if not set.

setName

Set the avatar’s name.
void setName(String name)
name
String
Name to set

getAbbreviation

Get the displayed abbreviation.
String getAbbreviation()
Returns the abbreviation, or null if not set.

setAbbreviation

Set the abbreviation.
void setAbbreviation(String abbr)
abbr
String
Abbreviation to display

getImage

Get the image URL.
String getImage()
Returns the image URL, or null if not set.

setImage

Set the image URL.
void setImage(String img)
img
String
Image URL to set

getColorIndex

Get the background color index.
Integer getColorIndex()
Returns the color index, or null if not set.

setColorIndex

Set the background color index.
void setColorIndex(int colorIndex)
colorIndex
int
Color index to set

Assertion Methods

assertName

Assert the avatar’s name property value.
void assertName(String name)
name
String
Expected name

assertAbbreviation

Assert the avatar’s abbreviation.
void assertAbbreviation(String abbr)
abbr
String
Expected abbreviation

assertHasImage

Assert that the avatar has an image set.
void assertHasImage()

assertHasNoImage

Assert that the avatar has no image set.
void assertHasNoImage()

Usage Examples

Get Avatar and Check Properties

AvatarElement avatar = AvatarElement.get(page);
avatar.assertVisible();

String name = avatar.getName();
assertEquals("John Doe", name);

String abbr = avatar.getAbbreviation();
assertEquals("JD", abbr);

Find Avatar by Name

AvatarElement avatar = AvatarElement.getByName(page, "Jane Smith");
avatar.assertName("Jane Smith");
avatar.assertAbbreviation("JS");

Set Avatar Properties

AvatarElement avatar = AvatarElement.get(page);

avatar.setName("Alice Cooper");
avatar.assertName("Alice Cooper");

avatar.setAbbreviation("AC");
avatar.assertAbbreviation("AC");

avatar.setColorIndex(3);
assertEquals(3, avatar.getColorIndex());

Work with Avatar Image

AvatarElement avatar = AvatarElement.get(page);

// Check if image is set
if (avatar.getImage() != null) {
    avatar.assertHasImage();
} else {
    avatar.assertHasNoImage();
}

// Set image
avatar.setImage("https://example.com/avatar.jpg");
avatar.assertHasImage();
assertEquals("https://example.com/avatar.jpg", avatar.getImage());

Avatar with Theme

AvatarElement avatar = AvatarElement.get(page);
avatar.assertTheme("xlarge");

Avatar with Tooltip

AvatarElement avatar = AvatarElement.getByName(page, "John Doe");
avatar.assertTooltipHasText("User profile");

Focus Avatar

AvatarElement avatar = AvatarElement.get(page);
avatar.focus();
avatar.assertIsFocused();

Scoped Avatar Lookup

// Find avatar within a card
CardElement card = CardElement.getByTitle(page, "User Profile");
AvatarElement avatar = AvatarElement.get(card.getLocator());
avatar.assertName("Profile User");

Build docs developers (and LLMs) love