Skip to main content

Overview

MessageListElement is a Playwright wrapper for <vaadin-message-list>. It provides helpers to access individual messages, read their content (text, user name, time) and assert message count. Messages are rendered as <vaadin-message> children in light DOM. Component tag: vaadin-message-list Implements:
  • HasStyleElement
  • HasThemeElement

Constructors

MessageListElement(Locator locator)

Create a new MessageListElement from an existing locator.
locator
Locator
required
The Playwright locator for the <vaadin-message-list> element

Message Access Methods

getMessages()

Get a locator for all <vaadin-message> children. Returns: Locator - Locator matching every message in the list

getMessage(int index)

Get a locator for a single message by index.
index
int
required
Zero-based index of the message
Returns: Locator - Locator for the message at the given index

getMessageByUserName(String userName)

Get a locator for the first message whose author name contains the given text.
userName
String
required
The user name to search for
Returns: Locator - Locator for the matching message

Content Accessor Methods

getMessageText(int index)

Get the text content of the message at the given index.
index
int
required
Zero-based index of the message
Returns: String - The message text

getMessageUserName(int index)

Get the user name of the message at the given index.
index
int
required
Zero-based index of the message
Returns: String - The user name

getMessageTime(int index)

Get the time of the message at the given index.
index
int
required
Zero-based index of the message
Returns: String - The time text

Assertion Methods

assertMessageCount(int count)

Assert that the list contains exactly the expected number of messages.
count
int
required
Expected message count

assertEmpty()

Assert that the list contains no messages.

assertMessageText(int index, String expected)

Assert that the message at the given index has the expected text.
index
int
required
Zero-based index of the message
expected
String
required
Expected message text

assertMessageUserName(int index, String expected)

Assert that the message at the given index has the expected user name.
index
int
required
Zero-based index of the message
expected
String
required
Expected user name

assertMessageTime(int index, String expected)

Assert that the message at the given index has the expected time.
index
int
required
Zero-based index of the message
expected
String
required
Expected time text

Static Factory Methods

get(Page page)

Get the first <vaadin-message-list> on the page.
page
Page
required
The Playwright page instance
Returns: MessageListElement - The first message list on the page

get(Locator locator)

Get the first <vaadin-message-list> within a locator scope.
locator
Locator
required
The scope to search within
Returns: MessageListElement - The first message list within the scope

Usage Example

import org.vaadin.addons.dramafinder.element.MessageListElement;

// Get the message list
MessageListElement list = MessageListElement.get(page);
assertThat(list.getLocator()).isVisible();

// Verify message count
list.assertMessageCount(3);

// Access and verify message content by index
list.assertMessageText(0, "Hello everyone!");
list.assertMessageUserName(0, "Alice");

list.assertMessageText(1, "Hi Alice, welcome!");
list.assertMessageUserName(1, "Bob");

list.assertMessageText(2, "Thanks Bob!");
list.assertMessageUserName(2, "Alice");

// Get message text programmatically
String firstMessage = list.getMessageText(0);
String author = list.getMessageUserName(0);
String time = list.getMessageTime(0);

// Find message by user name
Locator bobMessage = list.getMessageByUserName("Bob");
assertThat(bobMessage).isVisible();
assertThat(bobMessage.locator("[part='name']")).hasText("Bob");

// Verify empty list
Locator secondList = page.locator(MessageListElement.FIELD_TAG_NAME).nth(1);
MessageListElement emptyList = new MessageListElement(secondList);
emptyList.assertEmpty();

// Access all messages
Locator allMessages = list.getMessages();
assertThat(allMessages).hasCount(3);

Notes

  • Messages are rendered as <vaadin-message> elements in light DOM
  • Message content is accessed via shadow DOM parts: name, time, and message
  • The message text uses a special slot mechanism and requires JavaScript evaluation
  • Zero-based indexing is used for all message accessor methods

Build docs developers (and LLMs) love