Package com.vaadin.browserless
Class BrowserlessClassExtension
java.lang.Object
com.vaadin.browserless.BrowserlessClassExtension
- All Implemented Interfaces:
TesterWrappers,org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension
public class BrowserlessClassExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
JUnit 5 extension for browserless Vaadin testing with per-class lifecycle.
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.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new extension with per-class lifecycle. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddComponentTesterPackages(Class<?>... classes) protected voidaddComponentTesterPackages(String... packages) 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.<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.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.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.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
-
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
-
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
-
doInit
-
doCleanup
protected void doCleanup() -
find
Gets a query object for finding components of the given type in the UI.- 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.- 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.- 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.- 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
-