Class GridContextMenuLocator<Y>

java.lang.Object
com.vaadin.browserless.locator.Locator<GridContextMenu<Y>,GridContextMenuLocator<Y>>
com.vaadin.flow.component.grid.contextmenu.GridContextMenuLocator<Y>
All Implemented Interfaces:
Clickable<GridContextMenu<Y>>

@Generated("com.vaadin.browserless.locator.processor.LocatorProcessor") public class GridContextMenuLocator<Y> extends Locator<GridContextMenu<Y>,GridContextMenuLocator<Y>> implements Clickable<GridContextMenu<Y>>
Generated locator for GridContextMenu, derived from GridContextMenuTester. 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 Details

    • GridContextMenuLocator

      public GridContextMenuLocator(Class<Y> yType)
    • GridContextMenuLocator

      public GridContextMenuLocator(GridContextMenu<Y> component)
  • Method Details

    • getComponent

      public GridContextMenu<Y> getComponent()
      Description copied from interface: Clickable
      Gets the component being tested.
      Specified by:
      getComponent in interface Clickable<Y>
      Returns:
      the component under test
    • ensureComponentIsUsable

      public void ensureComponentIsUsable()
      Description copied from interface: Clickable
      Ensures the component is in a usable state before interaction.
      Specified by:
      ensureComponentIsUsable in interface Clickable<Y>
    • open

      public void open()
      Opens the context menu on the row it currently targets, as if the user had asked for it in the browser.

      The target row is the one given to GridTester.contextMenu(int), so this method is the counterpart of that entry point. Use open(int) to open the menu on a row directly.

      It does not render any client-side overlay, it only simulates the server-side state changes that opening the menu produces: the menu is attached to the UI, so its items become findable and clickable, and a GridContextMenuOpenedEvent reporting the target row is fired. Javadoc copied from GridContextMenuTester.open().

      Throws:
      IllegalStateException - if the menu does not target a row, if it is already open, or if a dynamic content handler prevented it from opening
    • open

      public void open(int row)
      Opens the context menu on the given row, as if the user had asked for it in the browser.

      The index is 0 based and counts the rows the user sees. The row is reported by the events the menu fires, so GridContextMenuItemClickEvent.getItem() and GridContextMenuOpenedEvent.getItem() hold the item on that row. Javadoc copied from GridContextMenuTester.open(int).

      Parameters:
      row - row to open the menu on
      Throws:
      IllegalStateException - if the menu is already open, or if a dynamic content handler prevented it from opening
      IndexOutOfBoundsException - if the grid has no such row
    • open

      public void open(int row, String columnKey)
      Opens the context menu on the given row and column, as if the user had asked for it in the browser.

      The column is reported by GridContextMenuOpenedEvent.getColumnId(). Javadoc copied from GridContextMenuTester.open(int,java.lang.String).

      Parameters:
      row - row to open the menu on, 0 based
      columnKey - key of the column to open the menu on, as set with Grid.Column.setKey(String)
      Throws:
      IllegalArgumentException - if the grid has no column with the given key
      IllegalStateException - if the column is not visible, if the menu is already open, or if a dynamic content handler prevented it from opening
      IndexOutOfBoundsException - if the grid has no such row
    • close

      public void close()
      Closes the context menu. Javadoc copied from GridContextMenuTester.close().
      Throws:
      IllegalStateException - if the menu is not open
    • clickItem

      public void clickItem(String topLevelText, String... nestedItemsText)
      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, an IllegalStateException is thrown because the target is ambiguous. Disabled or invisible items cannot be clicked and will also cause an IllegalStateException.

      The menu has to be open, since its items are not part of the UI before that. Javadoc copied from GridContextMenuTester.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 the menu is not open, if there are multiple visible 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 an IllegalStateException.

      The menu has to be open, since its items are not part of the UI before that. Javadoc copied from GridContextMenuTester.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 menu is not open, or if the item at the given position is disabled or not visible.
    • isItemChecked

      public boolean isItemChecked(String topLevelText, String... nestedItemsText)
      Checks if the checkable menu item matching given text is checked.

      For a nested menu item, provide the text of each menu item in the hierarchy. Javadoc copied from GridContextMenuTester.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 menu is not open, or 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 a nested menu item, provide the position of each sub menu that should be navigated to reach the requested item. Javadoc copied from GridContextMenuTester.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
      Returns:
      true if the item at given position is checked, otherwise false.
      Throws:
      IllegalArgumentException - if the provided position does not identify a menu item or if the menu item is not checkable.
      IllegalStateException - if the menu is not open, or if the item at given position is not usable.
    • getItemTooltipText

      public String getItemTooltipText(String topLevelText, String... nestedItemsText)
      Gets the tooltip text of the menu item matching the given text.

      For a nested menu item, provide the text of each menu item in the hierarchy. Javadoc copied from GridContextMenuTester.getItemTooltipText(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:
      the tooltip text of the menu item at given path, or null if the item has no tooltip set.
      Throws:
      IllegalArgumentException - if the provided text does not identify a menu item.
      IllegalStateException - if the menu is not open, or if the item at given path is not usable.
    • getItemTooltipText

      public String getItemTooltipText(int topLevelPosition, int... nestedItemsPositions)
      Gets the tooltip text of the menu 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. Javadoc copied from GridContextMenuTester.getItemTooltipText(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
      Returns:
      the tooltip text of the menu item at given position, or null if the item has no tooltip set.
      Throws:
      IllegalArgumentException - if the provided position does not identify a menu item.
      IllegalStateException - if the menu is not open, or if the item at given position is not usable.
    • getItemTexts

      public List<String> getItemTexts()
      Gets the texts of the menu items, as the browser shows them.

      Hidden items are ignored, so the returned texts are aligned with the positions used by clickItem(int, int...). A text can also be given to clickItem(String, String...), as long as it identifies a single enabled item: a text that several visible items share is ambiguous, and a disabled item cannot be clicked.

      An item created from a component has no text of its own, and is reported as an empty string. Use

      invalid reference
      #find(Class)
      to reach such an item.

      The menu has to be open, since its items are not part of the UI before that. The items are the ones the menu offers for the row it was opened on, so a dynamic content handler has run by then.

       
      
       menu.addItem("Edit", event -> {
       });
       menu.addItem("Hidden", event -> {
       }).setVisible(false);
       menu.addItem("Share");
      
       tester.open(0);
      
       // ["Edit", "Share"]
       tester.getItemTexts();
       
       
      Javadoc copied from GridContextMenuTester.getItemTexts().
      Returns:
      the texts of the visible top level menu items, in the order they are shown in
      Throws:
      IllegalStateException - if the menu is not open, or is not visible
    • getItemTexts

      public List<String> getItemTexts(String topLevelText, String... nestedItemsText)
      Gets the texts of the items of the sub menu of the item matching the given text, as the browser shows them.

      For a nested sub menu, provide the text of each menu item in the hierarchy, the same way as in clickItem(String, String...).

      Hidden items are ignored at every level, both when following the path and in the returned texts.

      The menu has to be open, since its items are not part of the UI before that.

       
      
       var subMenu = menu.addItem("Share").getSubMenu();
       subMenu.addItem("Copy link", event -> {
       });
       subMenu.addItem("Email", event -> {
       });
      
       tester.open(0);
      
       // ["Copy link", "Email"]
       tester.getItemTexts("Share");
       
       
      Javadoc copied from GridContextMenuTester.getItemTexts(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:
      the texts of the visible items of the sub menu, in the order they are shown in
      Throws:
      IllegalArgumentException - if the provided text does not identify a menu item, or if the item at the given path has no sub menu.
      IllegalStateException - if the menu is not open or not visible, if there are multiple matching items at any level, or if the item at the given path is disabled or not visible.