@Test
public void testCase1() throws Exception { driver.get(baseUrl + "/book-examples/tobetested");
//Get the button's element.
//(Actually the caption element inside the button.)
//Use the debug ID given with setDebugId(). WebElement button = driver.findElement(By.xpath( "//div[@id='main.button']/span/span"));
//Get the caption text
assertEquals("Push Me!", button.getText());
//And click it. It's OK to click the caption element. button.click();
//Get the Label's element.
//Use the automatically generated ID.
WebElement label = driver.findElement(By.xpath( "//div[@id='myapp-949693921']" + "/div/div[2]/div/div[2]/div/div"));
// Make the assertion assertEquals("Thanks!", label.getText());
}
You can also use URI fragments in the URL to open the application at a specific state. For information about URI fragments, see Section 11.10, “URI Fragment and History Management with
UriFragmentUtility”.
You should use the JUnit assertion commands. They are static methods defined in the org.junit.Assert class, which you can import (for example) with:
import static org.junit.Assert.assertEquals;
P l e a s e s e e t h e S e l e n i u m A P I d o c u m e n t a t i o n [http://seleniumhq.org/docs/03_webdriver.html#selenium-webdriver-api-commands-and-operations] for a complete reference of the element search methods in the WebDriver and By classes and for the interaction commands in the WebElement class.
TestBench has a collection of its own commands, defined in the TestBenchCommands interface. You can get a command object that you can use by calling testBench(driver) in a test case.
23.5.9. Waiting for Vaadin
Selenium is intended for regular web applications that load a page that is immediately rendered by the browser. Vaadin, on the other hand, is an Ajax framework where page is loaded just once and rendering is done in JavaScript. This takes more time so that the rendering might not be finished when the WebDriver continues executing the test. Vaadin TestBench allows waiting until the rendering is finished.
The waiting is automatically enabled. You can disable waiting by calling disableWaitForVaadin() in the TestBenchCommands interface. You can call it in a test case as follows:
testBench(driver).disableWaitForVaadin();
When disabled, you can wait for the rendering to finish by calling waitForVaadin() explicitly.
testBench(driver).waitForVaadin();