Using Selenium with Vaadin application

Hi,

does anyone sucessfully use Selenium for UI-tests of a Vaadin application?

I am currently trying to implement a simple JUnit test, that puts username and password into two input fields and clicks a button to submit the form and do the login.

My test looks like this:

[code]
@Test
public void testSeleniumJava() throws Exception {
driver.get(baseUrl + “/app/”);

    driver.findElement(By.id("gwt-uid-5")).sendKeys("user");
    driver.findElement(By.id("gwt-uid-7")).sendKeys("pass");

    driver.findElement(By.cssSelector("div.v-button.v-widget")).click();

    assertTrue(isElementPresent(By.cssSelector("div.v-slot.v-align-center > img.v-image.v-widget")));
}

[/code]If i run this test, everythings starts up fine (so Selenium is basically working). In the started Firefox, i can see, that both input fields are getting filled with the text and also the button gets clicked. But for some reason the login always fails, because no data (no username and no password) gets send to the server for login.

If I remove the “click” from the JUnit test and manually click, it does not work, too.

But: It works, if I manually click the two input fields, after the text was inserted by the JUnit test. So it seems, that the Vaadin application does not recognize “sendKeys” as real user interaction.

I think javascript change event is not fired; try add a sendKeys(Keys.TAB) after filling the textfield

driver.findElement(By.id("gwt-uid-5")).sendKeys("user");
driver.findElement(By.id("gwt-uid-5")).sendKeys(Keys.TAB);
driver.findElement(By.id("gwt-uid-7")).sendKeys("pass");
driver.findElement(By.id("gwt-uid-7")).sendKeys(Keys.TAB);

HTH
Marco

Hi Marco,

thanks for your reply. I tried your solution, but it did not help. It is still the same behavior. :frowning:

Stefan

I found a solution for this now by switching from Firefox as WebDriver to Chrome.

All I needed to do was to install ChromeDriver (https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver) which works as a server, that uses you local installation of Chrome.

In the JUnit test then you simply have to create the WebDriver with the following line:

driver = new RemoteWebDriver(new URL("http://localhost:9515"), DesiredCapabilities.chrome()); Now the code from my first post works! :slight_smile: