Class BaseBrowserlessTest
-
- All Implemented Interfaces:
public abstract class BaseBrowserlessTestBase 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
-
-
Constructor Summary
Constructors Constructor Description BaseBrowserlessTest()
-
Method Summary
Modifier and Type Method Description <T extends Component> Tnavigate(Class<T> navigationTarget)Navigate to the given view class if it is registered. <C, T extends Component, HasUrlParameter<C>> Tnavigate(Class<T> navigationTarget, C parameter)Navigate to view with url parameter. <T extends Component> Tnavigate(Class<T> navigationTarget, Map<String, String> parameters)Navigate to view corresponding to the given navigation target with the specified route parameters. <T extends Component> Tnavigate(String location, Class<T> expectedTarget)Navigate to given location string. HasElementreload()Simulates the user reloading the page (pressing F5): the current UI is detached and a fresh one is created in the same Vaadin session, then the current location is rendered again. <T extends Component> Treload(Class<T> expectedTarget)Simulates a page reload (see reload) and verifies the resulting view is of the expected type. voidfireShortcut(Key key, Array<KeyModifier> modifiers)Simulates a keyboard shortcut performed on the browser. HasElementgetCurrentView()Get the current view instance that is shown on the ui. <T extends ComponentTester<Y>, Y extends Component> Ttest(Y component)Wrap component with ComponentTester best matching component type. <T extends ComponentTester<Y>, Y extends Component> Ttest(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. -
-
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 toparameter- 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
orderIdof@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 toparameters- 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 fragmentexpectedTarget- class that is expected for navigation- Returns:
instantiated view
-
reload
HasElement reload()
Simulates the user reloading the page (pressing F5): the current UI is detached and a fresh one is created in the same Vaadin session, then the current location is rendered again. Session-scoped state (session attributes, security context) survives. Views annotated with @PreserveOnRefresh keep their component instance and state; other views are recreated.
- Returns:
the view shown after the reload
- Since:
25.4
-
reload
<T extends Component> T reload(Class<T> expectedTarget)
Simulates a page reload (see reload) and verifies the resulting view is of the expected type.
- Parameters:
expectedTarget- the expected view class after reload- Returns:
the view shown after the reload
- Since:
25.4
-
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 usecomponent- 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
ComponentRenderercolumn 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 thenclickItem(...)for a context menu, andGridTester.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 forfromThis- 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 forfromThis- 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
-
-
-
-