Currently Browsing


Cucumber in Web testing (part 8 of 8)

8. Keyword “Examples” and conclusion


Gherkin keyword: Examples

Cucumber provides another useful Gherkin keyword which is used scenario parametrization. A scenario with an “Example” keyword will be executed multiple times with different parameters. Here is an instance:

@init @logout
  Scenario Outline: Successful Login with Valid Credentials
    Given User is on Home Page
    When User Navigate to LogIn Page
    And User enters username "<userName>"
    And User enters password "<password>"
    And Click login
    Then Message displayed Login Successfully

| userName | password |
| username1 | password 1 |
| invalid | invalid |

Cucumber in Web testing (part 4 of 8)

4. TestRunner and Test steps

To run features we need a Java class to start the test run. Here is a simple example:

package cucumberTest;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

features = "Feature",
dryRun = true

public class TestRunner {


The TestRunner class needs to be annotated with @RunWith(Cucumber.class) and a body of it can be totally empty. By annotating the class with @CucumberOptions we can specify extra options to our test run. In this case, we used the annotation to specify the location of the feature file and to set the test run to ‘dry’. Running the test in ‘dry’ mode means that cucumber will not execute the test steps, rather it will just check for test steps implementations. For the previously given feature, we got this output on the console.

Cucumber in Web testing (part 3 of 8)

3. Cucumber features

“Feature” in cucumber is supposed to describe a single feature which is analog with “test group”/”test class” in standard Java world. A feature includes one or more scenarios. A scenario can be represented as a “test case” or a ”test method“ in standard Java world. The code of a cucumber feature need to be placed in a file with “.feature” extension and must be located in a separated folder on the project root.
Creating a new feature file with the previously installed eclipse extension will include a small legend and a simple template for the feature file.

Most important Gherkin keywords are:

Cucumber in Web testing (part 1 of 8)

1. What is cucumber

Cucumber is a testing framework which supports behavior-driven development (BDD). BDD is principally an idea about how software development should be managed by both business interests and technical insight. Implementation of BDD starts with describing the test cases with English like sentences following up with the test case implementation. With this we will have implemented test cases plus detailed test documentation also, which can be really handy at enormous number of test cases.

Cucumber testing framework uses Gherkin DSL to define test cases. The language itself is designed to be non-technical and human readable which enables the whole development team to have insight into the test cases including business analysts and managers also.