Docs

Browserless Testing in Non-Spring Projects

How to write browserless tests in plain Java projects without Spring.

If your project doesn’t use Spring or Spring Boot, you can write browserless tests by extending the BrowserlessTest base class directly. This base class instantiates a UI along with all the necessary Vaadin environment, which is available to your test methods.

Dependencies

Add the browserless-test-junit6 dependency with a test scope. Assuming you have imported the Vaadin Bill-of-Materials (BOM) and have a Maven project, all you need is:

Source code
XML
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-junit6</artifactId>
    <scope>test</scope>
</dependency>

No other test framework dependencies are required.

Writing Tests

Create a test class that extends BrowserlessTest:

Source code
Java
class HelloWorldViewTest extends BrowserlessTest {

    @Test
    public void setText_clickButton_notificationIsShown() {
        final HelloWorldView helloView = navigate(HelloWorldView.class);

        test(helloView.name).setValue("Test");
        test(helloView.sayHello).click();

        Notification notification = find(Notification.class).single();
        Assertions.assertEquals("Hello Test", test(notification).getText());
    }

}

All the features described in the Getting Started guide — package scanning, navigation, component testing, and component queries — work the same way with BrowserlessTest. Replace SpringBrowserlessTest with BrowserlessTest and remove the @SpringBootTest annotation.

Tip
Already Have a Test Base Class?
If your project already has its own test base class, you can still get the Vaadin environment without extending BrowserlessTest. See JUnit 6 Extensions for the composition-based setup.
Tip
Multiple Users or Windows?
This setup drives a single user with a single window. For tests that need several concurrent users or multiple windows of the same user, see Multi-User and Multi-Window Testing.

Running Tests

Testing with BrowserlessTest doesn’t require any particular setup. Run the test directly from your IDE or use Maven, for example by typing mvn test in the terminal.

D68CAC9E-6131-45C9-84E6-6D1CA1E44E81

Updated