Class BrowserlessUIContext
- All Implemented Interfaces:
GeneratedLocators,Locators,TesterWrappers,AutoCloseable
Represents a single browser window (one UI instance). All DSL methods
(navigate(java.lang.Class<T>), find(java.lang.Class<T>), findInView(java.lang.Class<T>), test(Y))
automatically call activate() before executing, which transparently
switches the thread-local Vaadin state and security context to this window's
user.
Instances of this class are thread-affine: they must be
created, used, and closed on the same thread. The active context is held in a
ThreadLocal and is not visible to other threads. This class is not
safe for concurrent access from multiple threads.
This means you can freely interleave calls on different windows without explicit context switching:
window1.navigate(ViewA.class); window2.navigate(ViewB.class); // auto-switches to window2's user window1.find(Button.class).first(); // auto-switches back to window1's user
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates this UI context on the current thread.voidHook for context-bound implementations to install Vaadin thread-locals before a locator is built.voidclose()Closes this UI context and detaches the UI.<T extends Component>
ComponentQuery<T> Gets a query object for finding components of the given type in this window's UI.<T extends Component>
ComponentQuery<T> Gets a query object for finding components of the given type nested inside the specified component.<T extends Component>
ComponentQuery<T> findInView(Class<T> componentType) Gets a query object for finding components of the given type inside the current view.voidfireShortcut(Key key, KeyModifier... modifiers) Simulates a keyboard shortcut performed on the browser.Gets the current view displayed in this window.Returns the URL from the last external navigation triggered byPage.setLocation(String)orPage.open(String).getExternalNavigationURL(String windowName) Returns the last URL opened with the given window name.Returns a map of all windows opened viaPage.open(String)orPage.open(String, String), excluding navigations that target the current window (_self,_parent,_top, empty, ornull).getUI()Returns the UI managed by this context.getUser()Returns the user context that owns this window.<T extends Component>
TNavigates this window to the given view class.<C,T extends Component & HasUrlParameter<C>>
TNavigates this window to the given view class with a URL parameter.<T extends Component>
TNavigates this window to the given view class with route parameters.<T extends Component>
TNavigates this window to the given location and validates the resulting view.voidSimulates a server round-trip, flushing pending component changes.booleanProcesses all pending Signals tasks with a default max wait time of 100 milliseconds.booleanrunPendingSignalsTasks(long maxWaitTime, TimeUnit unit) Processes all pending Signals tasks, waiting up to the specified timeout for the first task to arrive.<T extends ComponentTester<Y>,Y extends Component>
TWraps a component in the givenComponentTester.<T extends ComponentTester<Y>,Y extends Component>
Ttest(Y component) Wraps a component with the best matchingComponentTester.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, findBigDecimalField, findButton, findCheckbox, findCheckboxGroup, findComboBox, findConfirmDialog, findContextMenu, findDatePicker, findDateTimePicker, findDecimalRangeSlider, findDecimalSlider, findDescriptionList, findDetails, findDialog, findDiv, findEmailField, findEmphasis, findGrid, findH1, findH2, findH3, findH4, findH5, findH6, findHr, findImage, findInput, findIntegerField, findIntegerRangeSlider, findIntegerSlider, findListBox, findListItem, findLoginForm, findLoginOverlay, findMenuBar, findMessageInput, findMessageList, findMultiSelectComboBox, findMultiSelectListBox, findNativeButton, findNativeDetails, findNativeLabel, findNotification, findNumberField, findOrderedList, findParagraph, findPasswordField, findPopover, findPre, findRadioButton, findRadioButtonGroup, findRangeInput, findRouterLink, findSelect, findSideNav, findSpan, findTabs, findTabSheet, findTextArea, findTextField, findTimePicker, 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, 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
-
Method Details
-
activate
public void activate()Activates this UI context on the current thread.Sets all Vaadin thread-locals (
VaadinService,VaadinSession,UI,VaadinRequest,VaadinResponse) to this window's values. If aSecurityContextHandleris configured and the previous active context belonged to a different user, the outgoing user's security context is automatically saved and this user's context is restored.The security context is a per-user snapshot, not per-window: switching between windows of the same user does not save or restore security state, so mutations made by one window are observed by sibling windows.
This method is called automatically by all DSL methods. You only need to call it explicitly if you are accessing Vaadin APIs directly (e.g.
UI.getCurrent()). -
find
Gets a query object for finding components of the given type in this window's UI.- Type Parameters:
T- the component type- Parameters:
componentType- the type of component to search for- Returns:
- a query object
-
find
Gets a query object for finding components of the given type nested inside the specified component.- Type Parameters:
T- the component type- Parameters:
componentType- the type of component to search forfromThis- the component to search within- Returns:
- a query object
-
findInView
Gets a query object for finding components of the given type inside the current view.- Type Parameters:
T- the component type- Parameters:
componentType- the type of component to search for- Returns:
- a query object
-
test
Wraps a component with the best matchingComponentTester. This generic fallback is used for component types not covered by the specificTesterWrappersdefaults.- Type Parameters:
T- the tester typeY- the component type- Parameters:
component- the component to wrap- Returns:
- the component wrapped in a tester
-
test
Wraps a component in the givenComponentTester.- Type Parameters:
T- the tester typeY- the component type- Parameters:
tester- test wrapper to usecomponent- component to wrap- Returns:
- the initialized tester for the component
-
getCurrentView
Gets the current view displayed in this window.- Returns:
- the current view
-
roundTrip
public void roundTrip()Simulates a server round-trip, flushing pending component changes. -
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.
-
runPendingSignalsTasks
public boolean runPendingSignalsTasks()Processes all pending Signals tasks with a default max wait time of 100 milliseconds. Convenience for tests that need to wait for asynchronous Signal effects triggered from background threads or non-UI contexts.If this window's
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.- Returns:
trueif any pending Signals tasks were processed- See Also:
-
runPendingSignalsTasks
Processes all pending Signals tasks, waiting up to the specified timeout for the first task to arrive. Once the first task is found, all remaining tasks in the queue are processed immediately without additional waiting.- 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
-
getOpenedWindows
Returns a map of all windows opened viaPage.open(String)orPage.open(String, String), excluding navigations that target the current window (_self,_parent,_top, empty, ornull).The map keys are window names, and values are lists of URLs opened under that name. For
_blank, the list contains all URLs (each call opens a new window). For named windows, the list typically contains a single entry (the last URL).- Returns:
- an unmodifiable map of window names to URL lists
-
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
-
getUI
Returns the UI managed by this context.- Returns:
- the UI instance
-
getUser
Returns the user context that owns this window.- Returns:
- the parent user context
-
close
public void close()Closes this UI context and detaches the UI.- Specified by:
closein interfaceAutoCloseable
-