- Mar 01, 2019
Cucumber is a software tool used by computer programmers for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style. Central to the Cucumber BDD approach is its plain language parser called Gherkin. It allows expected software behaviors to be specified in a logical language that customers can understand. As such, Cucumber allows the execution of feature documentation written in business-facing text.
Most Frequently asked Cucumber Interview Questions
Q #1) Explain Cucumber shortly.
Ans: Cucumber is a tool that is based on Behavior Driven Development (BDD) methodology.
The main aim of Behavior Driven Development framework is to make various project roles such as Business Analysts, Quality Assurance, Developers etc., understand the application without diving deep into the technical aspects.
Q#2) What language is used by Cucumber?
Ans: Gherkin is the language that is used by the Cucumber tool. It is a simple English representation of the application behavior. Gherkin language uses several keywords to describe the behavior of application such as Feature, Scenario, Scenario Outline, Given, When, Then etc.
Q #3) What is meant by a feature file?
Ans: A feature file must provide a high-level description of an Application Under Test (AUT). The first line of the feature file must start with the keyword ‘Feature’ following the description of the application under test.
A feature file may include multiple scenarios within the same file. A feature file has the extension .feature.
Q #4) What are the various keywords that are used in Cucumber for writing a scenario?
Ans: Mentioned below are the keywords that are used for writing a scenario:
Q #5) What is the purpose of Scenario Outline in Cucumber?
Ans: Scenario outline is a way of parameterization of scenarios. This is ideally used when the same scenario needs to be executed for multiple sets of data, however, the test steps remain the same. Scenario Outline must be followed by the keyword ‘Examples’, which specify the set of values for each parameter.
Q #6) What programming language is used by Cucumber?
Ans: Cucumber tool provides support for multiple programming languages such as Java, .Net, Ruby etc. It can also be integrated with multiple tools such as Selenium, Capybara etc.
Q #7) What is the purpose of Step Definition file in Cucumber?
Ans: A step definition file in Cucumber is used to segregate the feature files from the underlying code. Each step of the feature file can be mapped to a corresponding method on the Step Definition file.
While feature files are written in an easily understandable language such as Gherkin, Step Definition files are written in programming languages such as Java, .Net, Ruby etc.
Q #8) What are the major advantages of Cucumber framework?
Ans: Given below are the advantages of Cucumber Gherkin framework that make Cucumber an ideal choice for rapidly evolving Agile methodology in today’s corporate world.
- Cucumber is an open source tool.
- Plain Text representation makes it easier for non-technical users to understand the scenarios.
- It bridges the communication gap between various project stakeholders such as Business Analysts, Developers, and Quality Assurance personnel.
- Automation test cases developed using the Cucumber tool are easier to maintain and understand as well.
- Easy to integrate with other tools such as Selenium and Capybara.
Q #9) Provide an example of a feature file using the Cucumber framework.
Ans: Following is an Example of a feature file for the scenario ‘Login into the application’:
Feature: Login to the application under test.
Scenario: Login to the application.
Given Open Chrome browser and launch the application.
When User enters the username onto the UserName field.
And User enters the password into the Password field.
When User clicks on the Login button.
Then Validate if the user login is successful.
Q #10) Provide an example of Scenario Outline using Cucumber framework.
Ans: The following is an Example of Scenario Outline keyword for the scenario ‘Upload a file’. Number of parameter values to be included in the feature file is based on the tester’s choice.
Scenario Outline: Upload a file
Given that the user is on upload file screen.
When a user clicks on the Browse button.
And user enters <filename> onto the upload textbox.
And user clicks on the enter button.
Then verify that the file upload is successful.
Q #11) What is the purpose of Behaviour Driven Development (BDD) methodology in the real world?
Ans: BDD is a methodology to understand the functionality of an application in simple plain text representation.
The main aim of Behavior Driven Development framework is to make various project roles such as Business Analysts, Quality Assurance, Developers, Support Team understand the application without diving deep into the technical aspects.
Q #12) What is the limit for the maximum number of scenarios that can be included in the feature file?
Ans: A feature file can contain a maximum of 10 scenarios, but the number can vary from project to project and from one organization to another. But it is generally advisable to limit the number of scenarios included in the feature file.
Q #13) What is the use of Background keyword in Cucumber?
Ans: Background keyword is used to group multiple given statements into a single group. This is generally used when the same set of given statements are repeated in each scenario of the feature file.
Q #14) What symbol is used for parameterization in Cucumber?
Ans: Pipe symbol (|) is used to specify one or more parameter values in a feature file.
Q #15) What is the purpose of Examples keyword in Cucumber?
Ans: Examples keyword is used to specify values for each parameter used in the scenario. Scenario Outline keyword must always be followed by the keyword Examples.
Q #16) What is the file extension for a feature file?
Ans: File Extension for a feature file is .feature. A feature file is ideally written in a notepad file and is saved with the extension feature.
Q #17) Provide an example of step definition file in Cucumber.
Ans: Step definition corresponding to the step “Open Chrome browser and launch the application” may look like the code mentioned below:
@Given(“^Open Chrome browser and launch the application$”)
public void openBrowser()
driver = new ChromeDriver();
Q #18) What is the purpose of Cucumber Options tag?
Ans: Cucumber Options tag is used to provide a link between the feature files and step definition files. Each step of the feature file is mapped to a corresponding method on the step definition file.
Below is the syntax of Cucumber Options tag:
Q #19) How can Cucumber be integrated with Selenium WebDriver?
Ans: Cucumber can be integrated with Selenium webdriver by downloading the necessary JAR files.
Given below are the list of JAR files that are to be downloaded for using Cucumber with Selenium web driver:
Q #20) When is Cucumber used in real time?
Ans: Cucumber tool is generally used in real time to write acceptance tests for an application. It is generally used by non-technical people such as Business Analysts, Functional Testers etc.
Q #21) Provide an example of Background keyword in Cucumber.
Background: Given user is on the application login page.
Q #22) What is the use of Behavior Driven Development in Agile methodology?
Ans: The advantages of Behavior Driven Development are best realized when non-technical users such as Business Analysts use BDD to draft requirements and provide the same to the developers for implementation.
In Agile methodology, user stories can be written in the format of feature file and the same can be taken up for implementation by the developers.
Q #23) Explain the purpose of keywords that are used for writing a scenario in Cucumber.
Ans: “Given” keyword is used to specify a precondition for the scenario. When a keyword is used to specify an operation to be performed. The keyword is used to specify the expected result of a performed action. “And” keyword is used to join one or more statements together into a single statement.
Q #24) What is the name of the plugin that is used to integrate Eclipse with Cucumber?
Ans: Cucumber Natural Plugin is the plugin that is used to integrate Eclipse with Cucumber.
Q #25) What is the meaning of TestRunner class in Cucumber?
Ans: TestRunner class is used to provide the link between feature file and step definition file. Below is the sample representation of how TestRunner class will look like. A TestRunner class is generally an empty class with no class definition.
Q #26) Provide an example of TestRunner class in Cucumber.
public class Runner
Q #27) What is the starting point of execution for feature files?
Ans: When integrated with Selenium, the starting point of execution must be from TestRunner class.
Q #28) Should any code be written within TestRunner class?
Ans: No code should be written under the TestRunner class. It should include the tags @RunWith and @CucumberOptions.
Q #29) What is the use of features property under Cucumber Options tag?
Ans: Features property is used to let Cucumber framework identify the location of the feature files.
Q #30) What is the use of glue property under Cucumber Options tag?
Ans: Glue property is used to let Cucumber framework identify the location of step definition files.
Q #31) What is the maximum number of steps that are to be written within a scenario?
Ans: The maximum number of steps to be written in a scenario is 3-4 steps.