Class BrowserlessClassExtension
- All Implemented Interfaces:
GeneratedLocators,Locators,TesterWrappers,org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension
The Vaadin environment is initialized once before all tests in the class and
torn down after all tests. Use as a static field with
@RegisterExtension:
class MyStatefulTest {
@RegisterExtension
static BrowserlessClassExtension ext = new BrowserlessClassExtension()
.withViewPackages(MyView.class);
@BeforeAll
static void setup() {
ext.navigate(MyView.class);
}
@Test
void testA() {
/* same session */ }
@Test
void testB() {
/* same session */ }
}
For a fresh environment per test method, use BrowserlessExtension
instead.
- Since:
- 1.1
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new extension with per-class lifecycle. -
Method Summary
Modifier and TypeMethodDescriptionvoidHook for context-bound implementations to install Vaadin thread-locals before a locator is built.protected voidaddApplicationProperties(Map<String, String> properties) protected voidaddApplicationProperty(String name, String value) protected voidaddComponentTesterPackages(Class<?>... classes) protected voidaddComponentTesterPackages(String... packages) protected voidaddConfiguration(BrowserlessConfiguration configuration) protected voidaddFeatureFlag(Feature feature, boolean enabled) protected voidaddFeatureFlag(String featureId, boolean enabled) protected voidaddFeatureFlags(Feature... features) protected voidaddFeatureFlags(String... featureIds) protected voidaddServices(Class<?>... serviceClasses) protected voidaddViewPackages(Class<?>... classes) protected voidaddViewPackages(String... packages) voidafterAll(org.junit.jupiter.api.extension.ExtensionContext ctx) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext ctx) protected voidprotected void<T extends Component>
ComponentQuery<T> Gets a query object for finding components of the given type in the UI.<T extends Component>
ComponentQuery<T> Gets a query object for finding components nested inside a given component.<T extends Component>
ComponentQuery<T> findInView(Class<T> type) Gets a query object for finding components inside the current view.voidfireShortcut(Key key, KeyModifier... modifiers) Simulates a keyboard shortcut performed on the browser.Gets the current view instance shown in the UI.protected booleanTells whether this extension creates a single Vaadin environment shared by all the tests in the class, rather than one per test method.<T extends Component>
TNavigates to the given view class.<C,T extends Component & HasUrlParameter<C>>
TNavigates to the given view class with a URL parameter.<T extends Component>
TNavigates to the given view class with route parameters.<T extends Component>
TNavigates to the given location string and verifies the expected target.voidSimulates a server round-trip, flushing pending component changes.booleanProcesses all pending Signals tasks with a default max wait of 100 milliseconds.booleanrunPendingSignalsTasks(long maxWaitTime, TimeUnit unit) Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive.withApplicationProperties(Map<String, String> properties) Sets Vaadin application properties (init parameters) for the tests using this extension.withApplicationProperty(String name, String value) Sets a Vaadin application property (init parameter) for the tests using this extension.withComponentTesterPackages(Class<?>... classes) Adds the packages of the given classes to the set of packages to scan forComponentTesterimplementations.withComponentTesterPackages(String... packages) Adds extra packages to scan forComponentTesterimplementations.withConfiguration(BrowserlessConfiguration configuration) Applies the given custom Vaadin configuration to the tests using this extension.withFeatureFlag(Feature feature, boolean enabled) Enables or disables the given Vaadin feature flag for the tests using this extension.withFeatureFlag(String featureId, boolean enabled) Enables or disables the given Vaadin feature flag for the tests using this extension.withFeatureFlags(Feature... features) Enables the given Vaadin feature flags for the tests using this extension.withFeatureFlags(String... featureIds) Enables the given Vaadin feature flags for the tests using this extension.withServices(Class<?>... serviceClasses) Adds VaadinLookupservice implementation classes.withViewPackages(Class<?>... classes) Adds packages to scan for@Route-annotated views, derived from the given classes' packages.withViewPackages(String... packages) Adds packages to scan for@Route-annotated views.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.browserless.locator.GeneratedLocators
findAccordion, findAnchor, findAvatarGroup, findBigDecimalField, findBreadcrumbs, findButton, findCard, findCheckbox, findCheckboxGroup, findComboBox, findConfirmDialog, findContextMenu, findDatePicker, findDateTimePicker, findDecimalRangeSlider, findDecimalSlider, findDescriptionList, findDetails, findDialog, findDiv, findEmailField, findEmphasis, findGrid, findGridContextMenu, findH1, findH2, findH3, findH4, findH5, findH6, findHr, findImage, findInput, findIntegerField, findIntegerRangeSlider, findIntegerSlider, findListBox, findListItem, findLoginForm, findLoginOverlay, findMarkdown, findMasterDetailLayout, findMenuBar, findMessageInput, findMessageList, findMultiSelectComboBox, findMultiSelectListBox, findNativeButton, findNativeDetails, findNativeLabel, findNotification, findNumberField, findOrderedList, findParagraph, findPasswordField, findPopover, findPre, findRadioButton, findRadioButtonGroup, findRangeInput, findRouterLink, findSelect, findSideNav, findSpan, findSplitLayout, findSwitch, findTabs, findTabSheet, findText, findTextArea, findTextField, findTimePicker, findTreeGrid, findUnorderedList, findUpload, findVirtualList, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, use, useMethods inherited from interface com.vaadin.browserless.TesterWrappers
popoverFor, popoverFor, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test
-
Constructor Details
-
BrowserlessClassExtension
public BrowserlessClassExtension()Creates a new extension with per-class lifecycle.
-
-
Method Details
-
withViewPackages
Adds packages to scan for@Route-annotated views, derived from the given classes' packages.- Parameters:
classes- classes whose packages should be scanned- Returns:
- this extension instance
-
withViewPackages
Adds packages to scan for@Route-annotated views.- Parameters:
packages- package names to scan- Returns:
- this extension instance
-
withServices
Adds VaadinLookupservice implementation classes.- Parameters:
serviceClasses- service implementation classes to register- Returns:
- this extension instance
-
withComponentTesterPackages
Adds extra packages to scan forComponentTesterimplementations.- Parameters:
packages- package names to scan for testers- Returns:
- this extension instance
-
withComponentTesterPackages
Adds the packages of the given classes to the set of packages to scan forComponentTesterimplementations.- Parameters:
classes- classes whose packages should be scanned for testers- Returns:
- this extension instance
-
withApplicationProperty
Sets a Vaadin application property (init parameter) for the tests using this extension.- Parameters:
name- the property namevalue- the property value- Returns:
- this extension instance
- Since:
- 25.3
-
withApplicationProperties
Sets Vaadin application properties (init parameters) for the tests using this extension.- Parameters:
properties- the properties to set- Returns:
- this extension instance
- Since:
- 25.3
-
withFeatureFlags
Enables the given Vaadin feature flags for the tests using this extension.- Parameters:
featureIds- the identifiers of the features to enable- Returns:
- this extension instance
- Since:
- 25.3
-
withFeatureFlags
Enables the given Vaadin feature flags for the tests using this extension.- Parameters:
features- the features to enable- Returns:
- this extension instance
- Since:
- 25.3
-
withFeatureFlag
Enables or disables the given Vaadin feature flag for the tests using this extension.- Parameters:
featureId- the identifier of the featureenabled-trueto enable the feature,falseto disable it- Returns:
- this extension instance
- Since:
- 25.3
-
withFeatureFlag
Enables or disables the given Vaadin feature flag for the tests using this extension.- Parameters:
feature- the featureenabled-trueto enable the feature,falseto disable it- Returns:
- this extension instance
- Since:
- 25.3
-
withConfiguration
Applies the given custom Vaadin configuration to the tests using this extension.The configuration wins over the one declared by a
BrowserlessTestConfigannotation on the test class. Since the Vaadin environment is shared by all the tests in the class, aBrowserlessTestConfigannotation on a test method is not supported.- Parameters:
configuration- the configuration to apply- Returns:
- this extension instance
- Since:
- 25.3
-
isClassScoped
protected boolean isClassScoped()Tells whether this extension creates a single Vaadin environment shared by all the tests in the class, rather than one per test method.- Returns:
- true if the Vaadin environment is scoped to the test class, false otherwise
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext ctx) - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext ctx) - Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
addViewPackages
-
addViewPackages
-
addServices
-
addComponentTesterPackages
-
addComponentTesterPackages
-
addApplicationProperty
-
addApplicationProperties
-
addFeatureFlags
-
addFeatureFlags
-
addFeatureFlag
-
addFeatureFlag
-
addConfiguration
-
doInit
-
doCleanup
protected void doCleanup() -
find
Gets a query object for finding components of the given type in 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.- Type Parameters:
T- component type- Parameters:
type- component type to search for- Returns:
- a component query
-
find
Gets a query object for finding components nested inside a given component.Searches the same server-side component tree as
find(Class), see there for what that tree does not contain.- Type Parameters:
T- component type- Parameters:
type- component type to search forfromThis- starting component for search- Returns:
- a component query scoped to the given component
-
findInView
Gets a query object for finding components inside the current view.Searches the same server-side component tree as
find(Class), see there for what that tree does not contain.- Type Parameters:
T- component type- Parameters:
type- component type to search for- Returns:
- a component query scoped to the current view
-
getCurrentView
Gets the current view instance shown in the UI.- Returns:
- the current view
-
roundTrip
public void roundTrip()Simulates a server round-trip, flushing pending component changes. -
runPendingSignalsTasks
public boolean runPendingSignalsTasks()Processes all pending Signals tasks with a default max wait of 100 milliseconds.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"); extension.runPendingSignalsTasks(); assertTrue(operation.result().join().successful());- Returns:
trueif any pending Signals tasks were processed
-
runPendingSignalsTasks
Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive.- Parameters:
maxWaitTime- maximum time to wait for the first taskunit- time unit for the timeout- Returns:
trueif any pending Signals tasks were processed
-
fireShortcut
Simulates a keyboard shortcut performed on the browser.- Parameters:
key- primary key of the shortcutmodifiers- key modifiers
-
activateLocatorContext
public void activateLocatorContext()Description copied from interface:LocatorsHook for context-bound implementations to install Vaadin thread-locals before a locator is built. Default is a no-op.- Specified by:
activateLocatorContextin interfaceGeneratedLocators- Specified by:
activateLocatorContextin interfaceLocators
-