Cucumber Intro

In this post we will discuss about Cucumber tool, its usage and different features.
we will discuss how to set up a cucumber project and also about integration of selenium WebDriver with Cucumber.

Introduction : (For more details visit https://cucumber.io )

Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.

Cucumber feature files can serve as a good document for all. There are many other tools like Behave , spekflow, fitness which also support BDD framework. Initially Cucumber was implemented in Ruby and then extended to Java framework. Both the tools support native Unit. We will discuss more about the BDD and style of writing BDD tests.

Cucumber can be used along with Selenium, Watir, and Ruby etc. Cucumber supports many other languages like Perl, PHP, Python, .Net etc. In this tutorial we will concentrate on Cucumber with Java as a language.

Basics Cucumber :

Before get into the details we need to understand cucumber feature file. Feature files are essential part of cucumber which is used to write test automation steps or acceptance tests. All the feature files ends with .feature extension.

Sample File :



Understanding the file :

Basically a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”.
  1. Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.
  2. When: This is used when some action is to be performed. As in above example we have seen when the user tries to log in using username and password, it becomes an action.
  3. Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.
  4. And: And is used to combine two or more same type of action

Step Definition for feature file :

For each feature step we need to develop a step definition class file. Need to create a class which contains those given, when and then statements. Cucumber uses its annotations and all the steps are embedded in those annotations (given, when, then).Each phrase starts with “^” so that cucumber understands the start of the step. Similarly each step ends with “$”. User can use regular expressions to pass different test data. 

Example:

Below example is to illustrate how feature files can be implemented.


How to run cucumber scripts :

To run the specific feature file cucumber uses standard Junit Runner and specify tags in @Cucumber. Options. Multiple tags can be given by using comma separate. Here you can specify the path of the report and type of report you want to generate.

@RunWith(Cucumber.class)
@CucumberOptions(
features = "yourprojectpath/src/test/resources",

plugin = {"pretty", "html:target/cucumber-html-report"},
tags = {}
)

public class RunCukesTest {


}

Cucumber Report :

Cucumber generates its own html format. However better reporting can be done using Cucumber Sandwich plugin,  Details of reporting are covered in next topic of cucumber.


What next, we will cover in next port how to setup cucumber with eclipse set by step.

Thanks