Skip to main content

Overview

ContextMenuElement is a Playwright wrapper for context menu overlays <vaadin-context-menu-overlay>. It provides helpers to open a menu via a context-click on the target, inspect the overlay list box, and pick menu items by their accessible label. Component tag: vaadin-context-menu Implements:
  • HasStyleElement

Constructors

ContextMenuElement(Page page)

Create a ContextMenuElement from the page overlay by locating the first opened context menu.
page
Page
required
The Playwright page instance

ContextMenuElement(Locator locator)

Create a ContextMenuElement from an existing locator.
locator
Locator
required
The Playwright locator for the context menu element

Static Methods

openOn(Locator target)

Open the context menu by invoking a context-click (right-click) on the provided target element.
target
Locator
required
The element that triggers the context menu

Instance Methods

assertOpen()

Assert that the context menu overlay is open. Verifies: The element has the opened attribute.

assertClosed()

Assert that the context menu overlay is closed or hidden. Verifies: The element is hidden in the DOM.

openSubMenu(String itemLabel)

Open a submenu and return its overlay.
itemLabel
String
required
The visible label of the parent menu item
Returns: ContextMenuElement - The submenu overlay element

selectItem(String itemLabel)

Select a menu item by its accessible name.
itemLabel
String
required
The visible label of the menu item to select

assertItemDisabled(String itemLabel)

Assert that a menu item is disabled.
itemLabel
String
required
The visible label of the menu item

assertItemEnabled(String itemLabel)

Assert that a menu item is enabled.
itemLabel
String
required
The visible label of the menu item

assertItemChecked(String itemLabel)

Assert that a checkable menu item is checked.
itemLabel
String
required
The visible label of the menu item
Verifies: The item has the menu-item-checked attribute.

assertItemNotChecked(String itemLabel)

Assert that a checkable menu item is not checked.
itemLabel
String
required
The visible label of the menu item

getListBoxLocator()

Get the locator for the context menu list box. Returns: Locator - Locator for <vaadin-context-menu-list-box>

Usage Example

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

// Open context menu on a target element
ContextMenuElement contextMenu = new ContextMenuElement(page);
ContextMenuElement.openOn(page.locator("#file-target"));
contextMenu.assertOpen();

// Select a menu item
contextMenu.selectItem("Rename");
contextMenu.assertClosed();

// Check item states
ContextMenuElement.openOn(page.locator("#status-target"));
contextMenu.assertItemDisabled("Disabled action");
contextMenu.assertItemEnabled("Refresh");

// Work with checkable items
ContextMenuElement.openOn(page.locator("#checkable-target"));
contextMenu.assertItemChecked("Project news");
contextMenu.assertItemNotChecked("Security alerts");
contextMenu.selectItem("Security alerts");

// Open and select from submenu
ContextMenuElement.openOn(page.locator("#file-target"));
ContextMenuElement shareMenu = contextMenu.openSubMenu("Share");
shareMenu.selectItem("Copy link");

// Verify CSS class
contextMenu.assertCssClass("file-context-menu");

Notes

  • The context menu uses ARIA role menuitem for item lookups
  • Checkable items use the menu-item-checked attribute to indicate state
  • Submenus are nested <vaadin-context-menu> elements with slot="submenu"

Build docs developers (and LLMs) love