Cucumber Interview Questions & Answers

Cucumber is a Behavior Driven Development (BDD) tool. Cucumber is a tool that executes plain-text functional descriptions as automated tests. The language that Cucumber understands is called Gherkin.

In BDD, users (business analysts, product owners) first write scenarios or acceptance tests that describes the behavior of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.

Cucumber execution will starts from support. In support first it will load the env.rb file then it will load hooks.rb and then it will start execute feature file scenario steps.

  • Support is a foder where we can setup cucumber related support.
  • Env.rb file will be used to load the required libraries for cucumber scenario execution
  • hooks.rb we will add hooks like before, after, beforeStep and afterStep hooks.

We can create Cucumber profiles to run specific features and step definitions

We can use following command to execute a cucumber profile

cucumber features -p <profile_name>

Ex: cucumber features -p regression

efore: execute before the feature file execution

After: executes after the feature file execution

BeforeStep: executes before the each step execution

AfterStep: executes after the each step execution

cucumber tags used to filter the scenarios. We can tag the scenarios and we can execute the scenarios based on tags, We can add tags to scenarios with @ We can use following command to execute a cucumber tagged scenarios.

cucumber features -t @<tag_name>

Ex: cucumber features -t @test

Cucumber dry run is used to compile cucumber feature files and stepDefinitions. If there is any compilations errors it will show when we use dry run

Ex: Cucumber features –dry-run

Scenario outline is used to execute the same scenario with different test data.

No it is not mandatory to used keywords while writing scenario steps.

We can write the scenario steps like the following without using keywords

* I am on the landed page

We can use the following command to generate html reports.

–format html –out report.html –format pretty.

We can run particular scenario from a feature file by giving the scenario line number

Ex: cucumber features/test.feature:21

To run functional tests written in a plain text Cucumber tool is used. It is written in a Ruby programming language.

Advantages of Cucumber:

  • You can inolve business stakeholders who can not code
  • End user experience is priority
  • High code reuse

The 2 files required to execute a Cucumber test scenario are

  1. Features
  2. Step Definition

Feature file in cucumber consist of parameters or conditions required for executing code, they are:

  1. Feature
  2. Scenario
  3. Scenario Outline
  4. Given
  5. When
  6. Then

Feature: Visit XYZ page in abc.com

Scenario : Visit abc.com

Given: I am on abc.com

When: I click on XYZ page

Then: I should see ABC page

  1. Scenario Outline: Same scenario can be executed for multiple sets of data using scenario outline. The data is provided by a tabular structure separated by (I I).

A step definition is the actual code implementation of the feature mentioned in feature file.

For example to make visitor visit the site “wisdomjobs” the command we use for given:

Given (/^ I am on www.wisdomjobs.com$/) do

Browser.goto “http://www.wisdomjobs.com”

end – This will visit www.wisdomjobs.com

  • Although Cucumber and Jbehave are meant for the same purpose, acceptance tests are completely different frameworks
  • Jbehave is Java based and Cucumber is Ruby based
  • Jbehave are based on stories while Cucumber is based on features.

A test harness for cucumber and rspec allows for separating responsibility between setting up the context and interacting with the browser and cleaning up the step definition files.

  • Rspec is used for Unit Testing.
  • Cucumber is used behaviour driven development. Cucumber can be used for System and Integration Tests.

 

Gherkin language is used to express scenario in feature files and ruby files containing unobtrusive automation for the steps in scenarios.

A regular expression is a pattern describing a certain amount of text. The most basic regular expression consists of a single literal character.

BDD or Behaviour driven development is a process of developing software based on TDD (Test Driven Development) which focusses on behavioural specification of software units.

Ruby and its Development Kit
Cucumber
IDE like ActiveState
Watir ( To simulate browser)
Ansicon and rspec (if required)

Features/ support file contains supporting ruby code. Files in support load before those in step_definitions, which can be useful for environment configuration.

BDD is becoming widely accepted practice in agile software development, and Cucumber-JVM is a mainstream tool used to implement this practice in Java. Cucumber-JVM is based on Cucumber framework, widely used in Ruby on Rails world as well as in Java and .Net.

Cucumber-JVM allows developers, QA, and non-technical or business participants to write features and scenarios in a plain text file using Gherkin language with minimal restrictions about grammar in a typical Given, When, and Then structure.

The feature file is then supported by a step definition file, which implements automated steps to execute the scenarios written in a feature file. Apart from testing APIs with Cucumber-JVM, we can also test UI level tests by combining Selenium WebDriver.