Class BaseBrowserlessTest
- Direct Known Subclasses:
BrowserlessTest,QuarkusBrowserlessTest,SpringBrowserlessTest
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
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Component>
ComponentQuery<T> Deprecated, for removal: This API element is subject to removal in a future version.<T extends Component>
ComponentQuery<T> Deprecated, for removal: This API element is subject to removal in a future version.since 1.1, for removal in 26.0; usefind(Class, Component)instead.<T extends Component>
ComponentQuery<T> Deprecated, for removal: This API element is subject to removal in a future version.since 1.1, for removal in 26.0; usefindInView(Class)instead.Gets the lookup services to register, combining the ones required by the framework integration, the ones provided by the deprecatedlookupServices()hook, and the ones declared by the test configuration.allLookupServices(BrowserlessConfiguration configuration) Same asallLookupServices(), but for a configuration that has already been resolved.protected voidTears down mocked Vaadin.protected com.vaadin.browserless.internal.Routesprotected static com.vaadin.browserless.internal.RoutesdiscoverRoutes(Set<String> packageNames) Discover and return Routes for mocked Vaadin core system.<T extends Component>
ComponentQuery<T> Gets a query object for finding a component inside the UI<T extends Component>
ComponentQuery<T> 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 viewvoidfireShortcut(Key key, KeyModifier... modifiers) Simulates a keyboard shortcut performed on the browser.Gets the services implementations required by the framework integration to initialize the VaadinLookup, for example the Spring or Quarkus lookup initializers.Get the current view instance that is shown on the ui.protected voidprotected voidCreate mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc.protected static <T extends ComponentTester<Y>,Y extends Component>
TinternalWrap(Class<T> wrap, Y component) protected static <T extends ComponentTester<Y>,Y extends Component>
TinternalWrap(Y component) Deprecated.since 25.3, declare the services withBrowserlessTestConfig.lookupServices()or by overridingtestConfiguration()instead.<T extends Component>
TNavigate to the given view class if it is registered.<C,T extends Component & HasUrlParameter<C>>
TNavigate to view with url parameter.<T extends Component>
TNavigate to view corresponding to the given navigation target with the specified route parameters.<T extends Component>
TNavigate to given location string.protected static voidSimulates a server round-trip, flushing pending component changes.protected final booleanProcesses all pending Signals tasks with a default max wait time of 100 milliseconds.protected final booleanrunPendingSignalsTasks(long maxWaitTime, TimeUnit unit) Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive.protected voidScan testers and populate testers map with them.<T extends ComponentTester<Y>,Y extends Component>
TWrap component in given ComponentTester.<T extends ComponentTester<Y>,Y extends Component>
Ttest(Y component) Wrap component with ComponentTester best matching component type.protected BrowserlessConfigurationGets the custom Vaadin configuration, such as application properties and feature flags, to apply to the mock Vaadin environment.protected abstract StringGets the name of the Test Engine that is able to run the base class implementation.
-
Constructor Details
-
BaseBrowserlessTest
public BaseBrowserlessTest()
-
-
Method Details
-
discoverRoutes
protected com.vaadin.browserless.internal.Routes discoverRoutes() -
discoverRoutes
Discover and return Routes for mocked Vaadin core system.- Returns:
- Routes
- See Also:
-
initVaadinEnvironment
protected void initVaadinEnvironment()Create mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc. for testing and find testers for the components. -
allLookupServices
Gets the lookup services to register, combining the ones required by the framework integration, the ones provided by the deprecatedlookupServices()hook, and the ones declared by the test configuration. For internal use only.- Returns:
- the set of services implementation classes, never null.
-
allLookupServices
Same asallLookupServices(), but for a configuration that has already been resolved.testConfiguration()is an overridable hook, so an override rebuilding the configuration on every call would otherwise do the work twice, and a non deterministic one could register services that do not belong to the configuration actually applied to the environment. Resolve the configuration once and pass it to both this method andMockVaadin.setup(). For internal use only.- Parameters:
configuration- the configuration to read the lookup services from, not null- Returns:
- the set of services implementation classes, never null.
-
initSignalsSupport
protected void initSignalsSupport() -
scanTesters
protected void scanTesters()Scan testers and populate testers map with them. The test method can find appropriate test based on testers map.- See Also:
-
scanPackages
-
cleanVaadinEnvironment
protected void cleanVaadinEnvironment()Tears down mocked Vaadin. -
lookupServices
Deprecated.since 25.3, declare the services withBrowserlessTestConfig.lookupServices()or by overridingtestConfiguration()instead. Overrides of this method are still honored.Gets the services implementations to be used to initialized VaadinLookup. Default implementation returns an empty Set. Override this method to provide custom Vaadin services, such asInstantiatorFactory,ResourceProvider, etc. Since 25.3 the services required by the Spring and Quarkus integrations are contributed byframeworkLookupServices()instead, and are always registered. An override of this method therefore adds to them and can no longer replace one of them, for example to swap the SpringSpringSecurityRequestCustomizer; overrideframeworkLookupServices()in a framework specific base class for that.- Returns:
- set of services implementation classes, never null.
-
frameworkLookupServices
Gets the services implementations required by the framework integration to initialize the VaadinLookup, for example the Spring or Quarkus lookup initializers. These services are always registered, regardless of the test configuration, so that a test customizingtestConfiguration()cannot accidentally break the framework integration. Meant to be overridden by framework specific base classes only; tests should declare their own services withBrowserlessTestConfig.lookupServices().- Returns:
- set of services implementation classes, never null.
- Since:
- 25.3
-
testConfiguration
Gets the custom Vaadin configuration, such as application properties and feature flags, to apply to the mock Vaadin environment. Default implementation returns the configuration declared by theBrowserlessTestConfigannotations present on the test class and on the current test method, if any. Override this method to provide the configuration programmatically, potentially on top of the declared one.@Override protected BrowserlessConfiguration testConfiguration() { return BrowserlessConfiguration.builder() .withConfiguration(super.testConfiguration()) .withFeatureFlags("myExperimentalFeature").build(); }- Returns:
- the configuration to apply, never null.
- Since:
- 25.3
- See Also:
-
fireShortcut
Simulates a keyboard shortcut performed on the browser.- Parameters:
key- Primary key of the shortcut. This must not be aKeyModifier.modifiers- Key modifiers. Can be empty.
-
getCurrentView
Get the current view instance that is shown on the ui.- Returns:
- current view
-
internalWrap
-
internalWrap
protected static <T extends ComponentTester<Y>,Y extends Component> T internalWrap(Class<T> wrap, Y component) -
test
Wrap component with ComponentTester best matching component type.- Type Parameters:
T- tester typeY- component type- Parameters:
component- component to get test wrapper for- Returns:
- component in wrapper with test helpers
-
test
Wrap component in given ComponentTester.- Type Parameters:
T- tester typeY- component type- Parameters:
tester- test wrapper to usecomponent- component to wrap- Returns:
- initialized test wrapper for component
-
find
Gets a query object for finding a component inside the UIThe 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.- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search for- Returns:
- a query object for finding components
- Since:
- 1.1
-
find
Gets a query object for finding a component nested inside the given component.Searches the same server-side component tree as
find(Class), see there for what that tree does not contain.- Type Parameters:
T- the type of the component(s) to search for- 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
Gets a query object for finding a component inside the current viewSearches the same server-side component tree as
find(Class), see there for what that tree does not contain.- Type Parameters:
T- the type of the component(s) to search for- 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) public <T extends Component> ComponentQuery<T> $(Class<T> componentType) Deprecated, for removal: This API element is subject to removal in a future version.since 1.1, for removal in 26.0; usefind(Class)instead.Gets a query object for finding a component inside the UI.- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search for- Returns:
- a query object for finding components
-
$
@Deprecated(since="1.1", forRemoval=true) public <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis) Deprecated, for removal: This API element is subject to removal in a future version.since 1.1, for removal in 26.0; usefind(Class, Component)instead.Gets a query object for finding a component nested inside the given component.- Type Parameters:
T- the type of the component(s) to search for- 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) public <T extends Component> ComponentQuery<T> $view(Class<T> componentType) Deprecated, for removal: This API element is subject to removal in a future version.since 1.1, for removal in 26.0; usefindInView(Class)instead.Gets a query object for finding a component inside the current view.- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search for- Returns:
- a query object for finding components
-
roundTrip
protected static void roundTrip()Simulates a server round-trip, flushing pending component changes. -
runPendingSignalsTasks
protected final boolean runPendingSignalsTasks()Processes all pending Signals tasks with a default max wait time of 100 milliseconds. This is a convenience method for tests that need to wait for asynchronous Signal effects to complete.When Signals are triggered from background threads or non-UI contexts, their effects are enqueued to simulate asynchronous processing. This method allows tests to flush and execute all such pending tasks synchronously, ensuring deterministic behavior in unit tests.
If any
VaadinSessionlock is held by the current thread, it is temporarily released during the wait to allow background threads to acquire the lock and enqueue tasks.Confirmation of a write to a shared signal (for example
SharedValueSignalorSharedListSignal) is dispatched through the same queue. The new value is visible immediately throughpeek(), but theSignalOperationreturned by the write only completes once the queued confirmation task has been run by this method. Blocking onoperation.result().get()without draining the queue first never completes, because the confirmation task can only run on the thread that calls this method:var operation = tickets.insertLast("a ticket"); runPendingSignalsTasks(); assertTrue(operation.result().join().successful());- Returns:
trueif any pending Signals tasks were processed.- See Also:
-
runPendingSignalsTasks
Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive. This method is essential for testing asynchronous Signal effects triggered from background threads or non-UI contexts.When Signals are triggered from background threads or non-UI contexts, their effects are enqueued to simulate asynchronous processing. This method allows tests to flush and execute all such pending tasks synchronously, ensuring deterministic behavior in unit tests.
The timeout applies only to waiting for the first task to arrive. Once the first task is found, all remaining tasks in the queue are processed immediately without additional waiting. If any
VaadinSessionlock is held by the current thread, it is temporarily released during the wait to allow background threads to acquire the lock and enqueue tasks.- Parameters:
maxWaitTime- the maximum time to wait for the first task to arrive in the given time unit. If <= 0, returns immediately if no tasks are available.unit- the time unit of the timeout value- Returns:
trueif any pending Signals tasks were processed.- See Also:
-
testingEngine
Gets the name of the Test Engine that is able to run the base class implementation. The Test Engine name is reported in the exception thrown when the Vaadin environment is not set up correctly.- Returns:
- name of the Test Engine.
-
find(Class)instead.