Cucumber Interview
Cucumber Interview
Cucumber Interview
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.
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.
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:
Given
When
Then
And
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.
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.
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.
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.
Ans: Following is an Example of a feature file for the scenario ‘Login into the application’:
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.
Examples:
|filename|
|file1|
|file2|
Q #11) What is the purpose of Behaviour Driven Development (BDD) methodology in the real
world?
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.
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.
Ans: Pipe symbol (|) is used to specify one or more parameter values in a feature file.
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.
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.
Ans: Step definition corresponding to the step “Open Chrome browser and launch the application”
may look like the code mentioned below:
driver.manage().window().maximize();
driver.get("www.facebook.com");
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.
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:
cucumber-core-1.2.2.jar
cucumber-java-1.2.2.jar
cucumber-junit-1.2.2.jar
cucumber-jvm-deps-1.0.3.jar
cucumber-reporting-0.1.0.jar
gherkin-2.12.2.jar
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.
Ans:
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.
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.
Ans:
Package com.sample.TestRunner
importorg.junit.runner.RunWith;
importcucumber.api.CucumberOptions;
importcucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features",glue={"StepDefinition"})
Ans: When integrated with Selenium, the starting point of execution must be from 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?
Summary
Cucumber is a tool that uses Behaviour Driven Development to write acceptance tests of an
application. It is used to bridge the communication gap between various project
stakeholders.
The main use of Cucumber lies in its simplicity to understand and usage of feature files by
the non-technical users.
12) Explain what is regular expressions?
BDD TDD
BDD tests are written in readable format TDD tests are written using programming
using Given-When-Then steps languages like Ruby, JAVA etc
BDD tests are readable by non-programmers TDD tests are difficult to read by non-
programmers
Cucumber
JBehave
Specflow
6. What is Cucumber?
Cucumber is a testing framework written in BDD style. Cucumber lets us define the system
behavior from user’s perspective in plain English text called Gherkin. Cucumber by itself is
written in Ruby programming language but it can be used to test the code written in other
8. What are the two files required to run a cucumber test?
Feature file
Step Definition file1
Feature file is an entry point of Cucumber execution. Cucumber scenarios are written inside
the feature file using a plain-text language called Gherkin. It can contain a scenario or
multiple scenarios. All the acceptance tests are written in feature file using Given-When-
Then statements.
.feature is the extension of feature file. Example, “Test.feature” is a feature file name.
Gherkin is a plain-text language used to write cucumber scenario in the feature file. Gherkin
is a business readable, domain-specific language used to describe the behavior of software
application from user’s perspective so that its easy for non-programmers to read and
collaborate.
12. What is the two main purpose of using Gherkin?
Documentation
Automated tests
Feature
Background
Scenario
Scenario Outline
Given
When
Then
And
But
14. Is it mandatory to use Given, When, Then keywords while writing scenario?
15. What is the difference between Given, When, Then steps in feature file?
Scenario Outline keyword in feature file is used to execute scenarios multiple times using a
different set of test data. Multiple sets of test data are provided by using ‘Examples’ in a
tabular structure separated by pipes (| |)
Example Scenario Outline below:
Steps written under the Background keyword are executed before every scenario.
For example: If you want to execute the same steps for every scenario like login to the
website, you just write those common steps under the background keyword. While executing
every scenario, steps written under background will be executed first.
Step definitions file has the actual code implementation of the scenario step.
Feature file
1 Feature:
2
3 Scenario:
4 Given verify two values 'text', 'test'
Cucumber tags are used to organize scenarios in your feature file. You can have as many tags
as you like before a scenario or feature. @ is used to represent tags. Example: @regression,
@sprint5, @EndtoEnd
Group scenarios
Ignore scenarios from execution
Logically group (OR & AND)
23. Name any two testing framework that can be integrated with Cucumber?
JUnit
TestNG
24. Name any two build management tools that can be integrated with Cucumber?
Gradle
Maven
1 import cucumber.api.CucumberOptions;
2 import cucumber.api.junit.Cucumber;
3 import org.junit.runner.RunWith;
4
5 @RunWith(Cucumber.class)
6 @CucumberOptions(
7 features="src/test/resources/features",
8 glue= "ca.testing.stepdefinitions")
9
10 public class TestRunner{
11 }
@CucumberOptions are used to set specific properties for your cucumber test.
Properties are,
1 import cucumber.api.CucumberOptions;
2 import cucumber.api.junit.Cucumber;
3 import org.junit.runner.RunWith;
4
5 @RunWith(Cucumber.class)
6 @CucumberOptions(
7 features="src/test/resources/features",
8 glue= "ca.testing.stepdefinitions",
9 tags = @regression,
10 dryRun = false,
11 strict = true,
12 monochrome = true)
13
14 public class Runfeatures {
15 }
28. Name any advanced framework design that can be used with Cucumber?
Cucumber Hooks are blocks of code that can be used to run before and after the scenarios
using @before and @after methods. It helps us eliminates the redundant code steps that we
write for every scenario and also manages our code workflow.
Note: @After will be executed even though the scenario is failed. @Before will be executed
before ‘Background’ steps in the feature file.
Know anyone who is preparing for Cucumber or BDD Interview? Help your friends by
sharing this article on Facebook, Twitter, or Google Plus.
BDD BDD INTERVIEW QUESTIONS CUCUMBER CUCUMBER
INTERVIEW CUCUMBER INTERVIEW QUESTIONS CUCUMBER INTERVIEW
QUESTIONS AND ANSWERS CUCUMBER QUESTIONS
Post navigation
PREVIOUS POST Software Testing Methods
NEXT POST How to download Katalon Studio?