Class ContextMenuLocator
java.lang.Object
com.vaadin.browserless.locator.Locator<ContextMenu,ContextMenuLocator>
com.vaadin.flow.component.contextmenu.ContextMenuLocator
- All Implemented Interfaces:
Clickable<ContextMenu>
@Generated("com.vaadin.browserless.locator.processor.LocatorProcessor")
public class ContextMenuLocator
extends Locator<ContextMenu,ContextMenuLocator>
implements Clickable<ContextMenu>
Generated locator for
ContextMenu, derived from
ContextMenuTester. Filter steps are inherited from
Locator; action methods delegate to a fresh tester
around the resolved component, so behavioral changes belong on the
tester, not here.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclickItem(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu.voidSimulates a click on the item that matches the given text.voidclose()Closes the context menu.voidEnsures the component is in a usable state before interaction.Gets the component being tested.booleanisItemChecked(int topLevelPosition, int... nestedItemsPositions) Checks if the checkable menu item at given position is checked.booleanisItemChecked(String topLevelText, String... nestedItemsText) Checks if the checkable menu item matching given text is checked.voidopen()Opens the context menu, as if the action is done in the browser.Methods inherited from class com.vaadin.browserless.locator.Locator
atIndex, component, components, exists, inside, inside, invalidate, self, with, withAriaLabel, withAriaLabelContaining, withAttribute, withAttribute, withCaption, withCaptionContaining, withClassName, withCondition, withId, withLabel, withLabelContaining, withoutAttribute, withoutAttribute, withoutClassName, withoutTheme, withText, withTextContaining, withTheme, withValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.browserless.Clickable
click, click, click, middleClick, middleClick, rightClick, rightClick
-
Constructor Details
-
ContextMenuLocator
public ContextMenuLocator()
-
-
Method Details
-
getComponent
Description copied from interface:ClickableGets the component being tested.- Specified by:
getComponentin interfaceClickable<ContextMenu>- Returns:
- the component under test
-
ensureComponentIsUsable
public void ensureComponentIsUsable()Description copied from interface:ClickableEnsures the component is in a usable state before interaction.- Specified by:
ensureComponentIsUsablein interfaceClickable<ContextMenu>
-
open
public void open()Opens the context menu, as if the action is done in the browser.It simulates, for example, a right click on a UI component with an assigned
ContextMenu.It does not render any client-side overlay. In other words, it only simulates the server-side state changes that would occur when a user opens the menu in the browser.
Calling
open()is not required before usingclickItem(...)orfind(Class)methods. Those methods operate on the server component state and can be used regardless of the menuopenedstate. Useopen()only if you want to explicitly simulate the act of opening. Javadoc copied fromContextMenuTester.open().- Throws:
IllegalStateException- if the menu is already opened.
-
close
public void close()Closes the context menu. Javadoc copied fromContextMenuTester.close(). -
clickItem
Simulates a click on the item that matches the given text. For a nested menu item, provide the text of each menu item in the hierarchy. The path to the menu item must reflect what is seen in the browser, meaning that hidden items are ignored. If there are multiple visible items at the same level with the same text, anIllegalStateExceptionis thrown because the target is ambiguous. Disabled or invisible items cannot be clicked and will also cause anIllegalStateException.
Note: Opening the menu viamenu.addItem("Preview", event -> { }); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> { }); subMenu.addItem("Email", event -> { }); // clicks top level menu item with text Preview tester.clickItem("Preview"); // clicks nested menu item with text Email tester.clickItem("Share", "Email");open()is not required before invoking this method; the lookup operates on server-side state. Javadoc copied fromContextMenuTester.clickItem(java.lang.String,java.lang.String[]).- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Throws:
IllegalArgumentException- if the provided text does not identify a menu item.IllegalStateException- if there are multiple matching items at any level, or if the item at the given path is disabled or not visible.
-
clickItem
public void clickItem(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu. For a nested menu item, provide the position of each sub menu that should be navigated to reach the requested item. Positions are zero-based and refer only to items that are visible at each menu level, i.e. hidden items are ignored (the same way as in the browser). Disabled or invisible items cannot be clicked and will cause anIllegalStateException.
Note: Opening the menu viamenu.addItem("Preview", event -> { }); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> { }); subMenu.addItem("Email", event -> { }); // clicks top level "Preview" menu item at position 0 tester.clickItem(0); // clicks then nested menu item at position 1 "Email" through the // item "Share" at position 1 tester.clickItem(1, 1);open()is not required before invoking this method; the lookup operates on server-side state. Javadoc copied fromContextMenuTester.clickItem(int,int[]).- Parameters:
topLevelPosition- the zero-based position of the item in the menu, as it will be seen in the browser.nestedItemsPositions- the zero-based position of the nested items, relative to the parent menu- Throws:
IllegalArgumentException- if the provided position does not identify a menu item.IllegalStateException- if the item at the given position is disabled or not visible.
-
isItemChecked
Checks if the checkable menu item matching given text is checked. For nested menu item provide the text of each menu item in the hierarchy. The path to the menu item must reflect what is seen in the browser, meaning that hidden items are ignored.
Javadoc copied frommenu.addItem("Preview", event -> { }).setCheckable(true); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> { }).setCheckable(true); subMenu.addItem("Email", event -> { }).setCheckable(true); tester.isItemChecked("Preview"); tester.isItemChecked("Share", "Email");ContextMenuTester.isItemChecked(java.lang.String,java.lang.String[]).- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Returns:
- true if the item at given path is checked, otherwise false.
- Throws:
IllegalArgumentException- if the provided text does not identify a menu item or if the menu item is not checkable.IllegalStateException- if the item at given path is not usable.
-
isItemChecked
public boolean isItemChecked(int topLevelPosition, int... nestedItemsPositions) Checks if the checkable menu item at given position is checked. For nested menu item provide the position of each sub menu that should be navigated to reach the requested item. The position reflects what is seen in the browser, so hidden items are ignored.
Javadoc copied frommenu.addItem("Preview", event -> { }).setCheckable(true); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> { }).setCheckable(true); subMenu.addItem("Email", event -> { }).setCheckable(true); // checks top level "Preview" menu item at position 0 tester.isItemChecked(0); // checks nested menu item at position 1 "Email" through the // item "Share" at position 1 tester.isItemChecked(1, 1);ContextMenuTester.isItemChecked(int,int[]).- Parameters:
topLevelPosition- the zero-based position of the item in the menu, as it will be seen in the browser.nestedItemsPositions- the zero-based position of the nested items, relative to the parent menu- Throws:
IllegalArgumentException- if the provided position does not identify a menu item or if the menu item is not checkable.IllegalStateException- if the item at given position is not usable.
-