Vaadin TestBench can usually test Vaadin applications as they are, especially if just taking screenshots. However, assertions on HTML elements require a DOM path to the element and this path is vulnerable to even small changes in the DOM structure. They might change because of your layout or UI logic, or if a new Vaadin version has some small changes. To make such problems less common, you can use debug IDs to refer to components.
public class ApplicationToBeTested extends Application { public void init() { final Window main = new Window("Test window"); setMainWindow(main); // Create a button Button button = new Button("Push Me!"); // Optional: give the button a unique debug ID button.setDebugId("main.button"); // Do something when the button is clicked button.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { // This label will not have a set debug ID main.addComponent(new Label("Thanks!")); } }); main.addComponent(button); } }
The application is shown in Figure 20.5, “A Simple Application To Be Tested”, with the button already clicked.
The button would be rendered as a HTML element: <div
id="main.button" ...>...</div>
. The DOM element would then
be accessible from the HTML page with:
driver.findElement(By.id="main.button")
. For the label,
which doesn't have a debug ID, the path would be from the page root. A
recorded test case stub for the above application is given in Section 20.5.1, “Starting From a Stub”, which is further refined in this
chapter.