Browser Automation

Cucumber is not a Browser Automation tool, but it works well with Browser Automation tools such as:

Selenium WebDriver

Let's convert the Selenium-Webdriver by Example tutorial to use Cucumber.

We can express the example as the following Scenario:

Scenario: Finding some cheese
  Given I am on the Google search page
  When I search for "Cheese!"
  Then the page title should start with "cheese"

Here are the accompanying Step Definitions:



Serenity BDD

Serenity BDD is an open source reporting library that helps you write better structured, more maintainable automated acceptance criteria, and also produces rich meaningful test reports (or "living documentation") that not only report on the test results, but also what features have been tested. A detailed tutorial on using Cucumber-JVM with Serenity can be found here

The step definitions for the scenario above writing using Serenity might look like this:

In this example, the WebDriver interaction is delegated to Page Object classes. Serenity has built-in support for Page Objects, which might look like this:

Tips and Tricks

Multiple Browsers

Cucumber can run your scenarios with different browsers. Simply select the browser to use based on a configuration property that is loaded at runtime:

Then, simply define the browser property when you run Cucumber:

If you are using Serenity, simply pass the driver system property (no extra coding is required):

Re-using the browser window

Closing and re-opening the browser window between your scenarios will slow them down.

To re-use them you can use the SharedDriver wrapper rather than calling WebDriver directly.

Embedding Screenshots

See the Report Attachments / Screenshots.

Example Projects