//And click it button.click();
//Get the Label's element by full path WebElement label = driver.findElement(By.vaadin(
"bookexamplestobetested::/VVerticalLayout[0]/"+
"ChildComponentContainer[1]/VLabel[0]"));
//Make the assertion
assertEquals("Thanks!", label.getText());
Finding by CSS Class
An element with a particular CSS style class name can be selected with the By.className() method. CSS selectors are useful for elements which have no ID, nor can be found easily from the component hierarchy, but do have a particular unique CSS style. Tooltips are one example, as they are floating div elements under the root element of the application. Their v-tooltip style makes it possible to select them as follows:
// Verify that the tooltip contains the expected text String tooltipText = driver.findElement(
By.className("v-tooltip")).getText();
For a complete example, see the AdvancedCommandsITCase.java file in the examples.
23.5.3. Running JUnit Tests in Eclipse
The Eclipse IDE integrates JUnit with nice control features. To run TestBench JUnit test cases in Eclipse, you need to do the following:
1.Add the TestBench JAR to a library folder in the project, such as lib. You should not put the library in WEB-INF/lib as it is not used by the Vaadin web application. Refresh the project by selecting it and pressing F5.
2.Right-click the project in Project Explorer and select Properties, and open the Java Build Path and the Libraries tab. Click Add JARs, navigate to the library folder, select the library, and click OK.
3.Switch to the Order and Export tab in the project properties. Make sure that the TestBench JAR is above the gwt-dev.jar (it may contain an old httpclient package), by selecting it and moving it with the Up and Down buttons.
4.Click OK to exit the project properties.
5. Right-click a test source file and select Run As JUnit Test.
A JUnit view should appear, and it should open the Firefox browser, launch the application, run the test, and then close the browser window. If all goes well, you have a passed test case, which is reported in the JUnit view area in Eclipse, as illustrated in Figure 23.12, “Running JUnit Tests in Eclipse”.