Tuesday, July 14, 2015

In-Container Selenium Tests

Currently I'm evaluating vaadin's testbench selenium framework. But the principles should be working with other frameworks too, as long as you find a way to register your http session while running the test. For the setup, I'm running vaadin with spring boot and the vaadin-spring add-on. The Selenium Tests are running the complete Spring Boot container.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = VaadinApplication.class)
@WebIntegrationTest

In the Main UI class I register the UI instance in a simple List Bean called UIRegsitry:

if (uiRegistry != null) {
    uiRegistry.getRegisteredUIs().add(this);
    addDetachListener(event -> uiRegistry.getRegisteredUIs().remove(this));
}

The Registry is optional and gets injected only when running the selenium tests:

@Autowired(required = false)
private UIRegistry uiRegistry;


Now "inside" the selenium test we can access all of the Vaadin UI Beans in the UI Scope:


UI uiUnderTest = uiRegistry.getRegisteredUIs().get(0);
uiUnderTest.access(() -> bookView = applicationContext.getBean(BookView.class)).get();
productIdentifiers = bookView.getProduct().getProductIdentifiers();

So now we can enter a value with selenium and directly check if all the bindings are working properly by accessing the involved model instances.

It should be possible to do similar stuff with arquillian and the http session for "regular" webapps.

No comments:

Using Mapstruct with Protobuf3