Class ComboBoxLocator<Y>

java.lang.Object
com.vaadin.browserless.locator.Locator<ComboBox<Y>,ComboBoxLocator<Y>>
com.vaadin.flow.component.combobox.ComboBoxLocator<Y>
Type Parameters:
Y - the ComboBox's Y type parameter
All Implemented Interfaces:
Clickable<ComboBox<Y>>, HasAriaLabelFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasLabelFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasPlaceholderFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasThemeFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasValueFilter<ComboBox<Y>,Y,ComboBoxLocator<Y>>

@Generated("com.vaadin.browserless.locator.processor.LocatorProcessor") public class ComboBoxLocator<Y> extends Locator<ComboBox<Y>,ComboBoxLocator<Y>> implements Clickable<ComboBox<Y>>, HasLabelFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasAriaLabelFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasPlaceholderFilter<ComboBox<Y>,ComboBoxLocator<Y>>, HasValueFilter<ComboBox<Y>,Y,ComboBoxLocator<Y>>, HasThemeFilter<ComboBox<Y>,ComboBoxLocator<Y>>
Generated locator for ComboBox, derived from ComboBoxTester. 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

    • ComboBoxLocator

      public ComboBoxLocator(Class<Y> yType)
      Creates a locator that searches for a ComboBox.
      Parameters:
      yType - class witness pinning the Y type parameter; the value is unused
    • ComboBoxLocator

      public ComboBoxLocator(ComboBox<Y> component)
      Creates a locator already bound to the given component, so that the action methods run against it instead of against a lookup.
      Parameters:
      component - the component the locator resolves to
  • Method Details

    • getComponent

      public ComboBox<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>
    • setFilter

      public void setFilter(String filter)
      Simulate writing a filter to the combobox. As typing does in the browser, the filter is applied to the data provider and to the component's filter property.

      Use ComboBoxTester.getSuggestions() to get the string values show in the dropdown or ComboBoxTester.getSuggestionItems() to get the actual items in the suggestion. Javadoc copied from ComboBoxTester.setFilter(java.lang.String).

      Parameters:
      filter - string to use for filtering
    • selectItem

      public void selectItem(String selection)
      Selects an item by its string representation (label).

      This method searches for the item among the current suggestions, which are affected by any filter set via ComboBoxTester.setFilter(java.lang.String). If no filter is set, all items are available for selection. If a filter is set, only the filtered items can be selected.

      To select an item when the ComboBox uses custom filtering logic (e.g., set via setItems(ItemFilter, Collection)), first call ComboBoxTester.setFilter(java.lang.String) to apply the filter, then call this method to select from the filtered results.

      Example usage with filtering:

       // Apply filter first
       comboBoxTester.setFilter("search text");
       // Then select from filtered items
       comboBoxTester.selectItem("Matching Item Label");
       
      Javadoc copied from ComboBoxTester.selectItem(java.lang.String).
      Parameters:
      selection - the item's string representation (label) to select, or null to clear the selection
      Throws:
      IllegalArgumentException - if no item with the given label is found among current suggestions
      IllegalStateException - if the component is not usable
      See Also:
    • selectItemContaining

      public void selectItemContaining(String text)
      Selects the item matching a partial text, as if the user typed the text into the combobox and picked the only remaining suggestion.

      The text is applied as a filter, so matching follows the component's own filtering: by default a case-insensitive "label contains" match, or the ItemFilter / data provider filter the application configured. Exactly one item has to match, so a test fails rather than picking an item it did not clearly name. This also applies when the text equals the full label of one of the matching items; use selectItem to pick an item by its exact label. This rule does not depend on the component's PartialMatchMode. The filter is cleared afterwards, as the browser does once a value is committed. If a value change listener disables, hides or detaches the component, or makes it inert, the filter stays at the text, as the server then ignores the browser's update. If matching fails, the selection is left unchanged and the filter set before the call is restored.

       // items "Berlin", "Bern", "Bernau", "Helsinki"
       comboBoxTester.selectItemContaining("hel"); // selects "Helsinki"
       comboBoxTester.selectItemContaining("bernau"); // selects "Bernau"
       comboBoxTester.selectItemContaining("bern"); // throws, "Bern" and
                                                    // "Bernau" match
       
      Javadoc copied from ComboBoxTester.selectItemContaining(java.lang.String).
      Parameters:
      text - the text the user types to find the item, not null
      Throws:
      IllegalArgumentException - if the text is null, matches no item, or matches more than one item
      IllegalStateException - if the component is not usable
      See Also:
    • clickClearButton

      public void clickClearButton()
      Clears the selection by clicking the clear button, as the user would.

      Requires the clear button to be visible — a hidden clear button is not something the user can click. ComboBoxTester.selectItem(java.lang.String) with null clears the selection without that requirement. Javadoc copied from ComboBoxTester.clickClearButton().

      Throws:
      IllegalStateException - if the component is not usable, or its clear button is not visible
      Since:
      25.3
    • getSelected

      public Y getSelected()
      Get the currently selected item. Javadoc copied from ComboBoxTester.getSelected().
      Returns:
      current selection
    • getSuggestions

      public List<String> getSuggestions()
      Get dropdown suggestions as String representations sent to the client. Any filter that is set is taken into account. Javadoc copied from ComboBoxTester.getSuggestions().
      Returns:
      List of item representation strings
    • getSuggestionItems

      public List<Y> getSuggestionItems()
      Get the actual items for the dropdown as a List. Any filter that is set is taken into account. Javadoc copied from ComboBoxTester.getSuggestionItems().
      Returns:
      List of items