Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

In-Container Selenium Tests

DZone's Guide to

In-Container Selenium Tests

An evaluation of Vaadin's testbench Selenium framework, running on a complete Spring Boot container.

· DevOps Zone ·
Free Resource

In response to accelerated release cycles, a new set of testing capabilities is now required to deliver quality at speed. This is why there is a shake-up in the testing tools landscape—and a new leader has emerged in the just released Gartner Magic Quadrant for Software Test Automation.

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.

Gartner: Digital Transformation, DevOps, and the Future of Testing. Download Now! 

Topics:
selenium ,vaadin ,spring boot ,devops ,web dev

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}