Browserless Testing in Non-Spring Projects
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.