Skip to content

WebDriver

aslakhellesoy edited this page May 25, 2011 · 4 revisions

WebDriver (or Selenium 2.0) is a perfect match for Cuke4Duke. You can use it with any of Cuke4Duke’s supported programming languages.

Here is a step definition written in Java:

@When("^I search for \"([^\"]*)\"$")
public void search(String query) {
    WebElement searchField = facade.getBrowser().findElement(By.name("q"));
    searchField.sendKeys(query);
    // WebDriver will find the containing form for us from the searchField element
    searchField.submit();
}

See the Java WebDriver example project for a full example.

-Or maybe you want to use Groovy instead:

When(~"I search for \"(.*)\"") { String query ->
  searchField = browser.findElement(By.name("q"))
  searchField.sendKeys(query)
  // WebDriver will find the containing form for us from the searchField element
  searchField.submit()
}

See the Groovy WebDriver example project for a full example.

Something went wrong with that request. Please try again.