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
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)
Scope containing the avatar
getByName
Get an avatar by its name attribute.
AvatarElement.getByName(Page page, String name)
AvatarElement.getByName(Locator locator, String name)
Scope containing the avatar
Avatar’s name attribute value
Property Methods
getName
Get the avatar’s name.
Returns the name, or null if not set.
setName
Set the avatar’s name.
void setName(String name)
getAbbreviation
Get the displayed abbreviation.
Returns the abbreviation, or null if not set.
setAbbreviation
Set the abbreviation.
void setAbbreviation(String abbr)
getImage
Get the image URL.
Returns the image URL, or null if not set.
setImage
Set the image URL.
void setImage(String img)
getColorIndex
Get the background color index.
Returns the color index, or null if not set.
setColorIndex
Set the background color index.
void setColorIndex(int colorIndex)
Assertion Methods
assertName
Assert the avatar’s name property value.
void assertName(String name)
assertAbbreviation
Assert the avatar’s abbreviation.
void assertAbbreviation(String abbr)
assertHasImage
Assert that the avatar has an image set.
assertHasNoImage
Assert that the avatar has no image set.
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");
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");