Class BaseBrowserlessTest

  • All Implemented Interfaces:

    
    public abstract class BaseBrowserlessTest
    
                        

    Base class for browserless tests. Provides methods to set up and clean a mocked Vaadin environment. The class allows scan classpath for routes and error views. Subclasses should typically restrict classpath scanning to a specific packages for faster bootstrap, by using ViewPackages annotation. If the annotation is not present a full classpath scan is performed For internal use only. May be renamed or removed in a future release.

    Since:

    1.0

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      <T extends Component> T navigate(Class<T> navigationTarget) Navigate to the given view class if it is registered.
      <C, T extends Component, HasUrlParameter<C>> T navigate(Class<T> navigationTarget, C parameter) Navigate to view with url parameter.
      <T extends Component> T navigate(Class<T> navigationTarget, Map<String, String> parameters) Navigate to view corresponding to the given navigation target with the specified route parameters.
      <T extends Component> T navigate(String location, Class<T> expectedTarget) Navigate to given location string.
      void fireShortcut(Key key, Array<KeyModifier> modifiers) Simulates a keyboard shortcut performed on the browser.
      HasElement getCurrentView() Get the current view instance that is shown on the ui.
      <T extends ComponentTester<Y>, Y extends Component> T test(Y component) Wrap component with ComponentTester best matching component type.
      <T extends ComponentTester<Y>, Y extends Component> T test(Class<T> tester, Y component) Wrap component in given ComponentTester.
      <T extends Component> ComponentQuery<T> find(Class<T> componentType) Gets a query object for finding a component inside the UI The query walks the server-side component tree.
      <T extends Component> ComponentQuery<T> find(Class<T> componentType, Component fromThis) Gets a query object for finding a component nested inside the given component.
      <T extends Component> ComponentQuery<T> findInView(Class<T> componentType) Gets a query object for finding a component inside the current view Searches the same server-side component tree as find, see there for what that tree does not contain.
      <T extends Component> ComponentQuery<T> $(Class<T> componentType) Gets a query object for finding a component inside the UI.
      <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis) Gets a query object for finding a component nested inside the given component.
      <T extends Component> ComponentQuery<T> $view(Class<T> componentType) Gets a query object for finding a component inside the current view.
      • Methods inherited from class java.lang.Object

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

      • BaseBrowserlessTest

        BaseBrowserlessTest()
    • Method Detail

      • navigate

         <T extends Component> T navigate(Class<T> navigationTarget)

        Navigate to the given view class if it is registered.

        Parameters:
        navigationTarget - view class to navigate to
        Returns:

        instantiated view

      • navigate

         <C, T extends Component, HasUrlParameter<C>> T navigate(Class<T> navigationTarget, C parameter)

        Navigate to view with url parameter.

        Parameters:
        navigationTarget - view class to navigate to
        parameter - parameter to send to view
        Returns:

        instantiated view

      • navigate

         <T extends Component> T navigate(Class<T> navigationTarget, Map<String, String> parameters)

        Navigate to view corresponding to the given navigation target with the specified route parameters.

        These are the parameters of the route template, such as orderId of @Route("order/:orderId") — not query parameters. To navigate with a query string, write it into the location given to navigate.

        Parameters:
        navigationTarget - view class to navigate to
        parameters - route parameters of the target's route template, keyed by parameter name
        Returns:

        instantiated view

      • navigate

         <T extends Component> T navigate(String location, Class<T> expectedTarget)

        Navigate to given location string. Check that location navigated to is the expected view or throw exception.

        The location is written the way it appears in the browser's address bar, so it may carry a query string and a fragment — for example "order/ORD-1?tab=history", whose query parameters the view reads from the navigation event.

        Parameters:
        location - location string for navigating, optionally with a query string and a fragment
        expectedTarget - class that is expected for navigation
        Returns:

        instantiated view

      • fireShortcut

         void fireShortcut(Key key, Array<KeyModifier> modifiers)

        Simulates a keyboard shortcut performed on the browser.

        Parameters:
        key - Primary key of the shortcut.
        modifiers - Key modifiers.
      • getCurrentView

         HasElement getCurrentView()

        Get the current view instance that is shown on the ui.

        Returns:

        current view

      • test

         <T extends ComponentTester<Y>, Y extends Component> T test(Y component)

        Wrap component with ComponentTester best matching component type.

        Parameters:
        component - component to get test wrapper for
        Returns:

        component in wrapper with test helpers

      • test

         <T extends ComponentTester<Y>, Y extends Component> T test(Class<T> tester, Y component)

        Wrap component in given ComponentTester.

        Parameters:
        tester - test wrapper to use
        component - component to wrap
        Returns:

        initialized test wrapper for component

      • find

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

        Gets a query object for finding a component inside the UI

        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 - the type of the component(s) to search for
        Returns:

        a query object for finding components

        Since:

        1.1

      • find

         <T extends Component> ComponentQuery<T> find(Class<T> componentType, Component fromThis)

        Gets a query object for finding a component nested inside the given component.

        Searches the same server-side component tree as find, see there for what that tree does not contain.

        Parameters:
        componentType - the type of the component(s) to search for
        fromThis - component used as starting element for search.
        Returns:

        a query object for finding components

        Since:

        1.1

      • findInView

         <T extends Component> ComponentQuery<T> findInView(Class<T> componentType)

        Gets a query object for finding a component inside the current view

        Searches the same server-side component tree as find, see there for what that tree does not contain.

        Parameters:
        componentType - the type of the component(s) to search for
        Returns:

        a query object for finding components

        Since:

        1.1

      • $

        @Deprecated(since = "1.1", forRemoval = true) <T extends Component> ComponentQuery<T> $(Class<T> componentType)

        Gets a query object for finding a component inside the UI.

        Parameters:
        componentType - the type of the component(s) to search for
        Returns:

        a query object for finding components

      • $

        @Deprecated(since = "1.1", forRemoval = true) <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis)

        Gets a query object for finding a component nested inside the given component.

        Parameters:
        componentType - the type of the component(s) to search for
        fromThis - component used as starting element for search.
        Returns:

        a query object for finding components

      • $view

        @Deprecated(since = "1.1", forRemoval = true) <T extends Component> ComponentQuery<T> $view(Class<T> componentType)

        Gets a query object for finding a component inside the current view.

        Parameters:
        componentType - the type of the component(s) to search for
        Returns:

        a query object for finding components