Docs

Documentation versions (currently viewingVaadin 25.1 (pre-release))

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 = $(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.

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