Class ComponentTester

  • All Implemented Interfaces:
    com.vaadin.browserless.Clickable

    
    public class ComponentTester<T extends Component>
     implements Clickable<T>
                        

    Test wrapper for components with helpful methods for testing a component.

    More targeted methods for specific components exist in named component wrappers.

    Since:

    1.0

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final T component
    • Constructor Summary

      Constructors 
      Constructor Description
      ComponentTester(T component) Wrap given component for testing.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      T getComponent() Get the wrapped component.
      boolean isUsable() Validate that component can be interacted with and should be visible in the UI.
      void setModal(boolean modal) Set component modality.
      <R extends Component> ComponentQuery<R> find(Class<R> componentType) Gets a ComponentQuery to search for component of the given type nested inside the wrapped component.
      final void ensureComponentIsUsable() Checks that wrapped component is usable, otherwise throws an IllegalStateException with details on the current state of the component.
      void focus() Simulates the user moving keyboard focus to the wrapped component.
      boolean isFocused() Checks whether the wrapped component currently has keyboard focus in the simulated browser, including focus given with server-side focus calls.
      void blur() Simulates the wrapped component losing keyboard focus, firing a blur event as if it came from the client.
      • Methods inherited from class com.vaadin.browserless.Clickable

        click, click, click, middleClick, middleClick, rightClick, rightClick
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComponentTester

        ComponentTester(T component)

        Wrap given component for testing.

        Parameters:
        component - target component
    • Method Detail

      • getComponent

         T getComponent()

        Get the wrapped component.

        Returns:

        wrapped component

      • isUsable

         boolean isUsable()

        Validate that component can be interacted with and should be visible in the UI. Subclasses overriding this method should also override notUsableReasons to provide additional details to the potential exception thrown by ensureComponentIsUsable.

        Returns:

        true if component can be interacted with by the user

      • setModal

         void setModal(boolean modal)

        Set component modality.

        Automatically generates a client side change to propagate modality.

        Parameters:
        modal - true to make component modal, false to remove modality
      • find

         <R extends Component> ComponentQuery<R> find(Class<R> componentType)

        Gets a ComponentQuery to search for component of the given type nested inside the wrapped component.

        The query walks the server-side component tree. A component that another component renders per item, such as the component a ComponentRenderer column renders for a grid row, is rendered into the column and not into the tree, and the content of an overlay, such as a context menu, is attached only while the overlay is open. Neither is reachable this way, and the lookup returns an empty result rather than failing, so reach those components through the owning component tester instead: GridTester.getCellComponent(row, column) for grid cells, ContextMenuTester.open() and then clickItem(...) for a context menu, and GridTester.contextMenu(row).open() for a grid context menu.

        Parameters:
        componentType - type of the component to search.
        Returns:

        a ComponentQuery instance, searching for wrapped component children.

      • focus

         void focus()

        Simulates the user moving keyboard focus to the wrapped component.

        Fires a blur event on the previously focused component and a focus event on this one, as if they came from the client. Focus also moves implicitly when interacting with components through testers, so calling this is rarely needed.

        Since:

        25.4

      • isFocused

         boolean isFocused()

        Checks whether the wrapped component currently has keyboard focus in the simulated browser, including focus given with server-side focus calls.

        Returns:

        true if the component is focused

        Since:

        25.4

      • blur

         void blur()

        Simulates the wrapped component losing keyboard focus, firing a blur event as if it came from the client. Blurring a component that does not have focus is a no-op, as in a browser.

        Focus also moves implicitly when interacting with other components through testers, so calling this is only needed when nothing else is interacted with after this component.

        Since:

        25.4