Cucumber
Cucumber
com
9123820085
Selenium with
Cucumber
Framework
Interview
Questions &
Answers
kasper-analytics
kasperanalytics.com
9123820085
The main aim of the 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.
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 applications such as Feature, Scenario,
Scenario Outline, Given, When, Then, etc.
A feature file may include multiple scenarios within the same file. A feature file has
the extension .feature.
4) What are the various keywords that are used in Cucumber for writing a
scenario?
Mentioned below are the keywords that are used for writing a scenario:
o Given
o When
o Then
o And
kasper-analytics
kasperanalytics.com
9123820085
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 like, Gherkin,
Step Definition files are written in programming languages such as Java, .Net,
Ruby, etc.
Given below are the advantages of the Cucumber Gherkin framework that make
Cucumber an ideal choice for rapidly evolving Agile methodology in today’s
corporate world.
kasper-analytics
kasperanalytics.com
9123820085
4. Automation test cases developed using the Cucumber tool are easier to
maintain and understand as well.
5. Easy to integrate with other tools such as Selenium and Capybara.
Following is an example of a feature file for the scenario ‘Login into the
application:
Scenario Outline:
1. Upload a file
2. Given that the user is on upload file screen.
3. When a user clicks on the Browse button.
4. And user enters <filename> onto the upload textbox.
5. And user clicks on the enter button.
6. Then verify that the file upload is successful.
Example:
kasper-analytics
kasperanalytics.com
9123820085
The main aim of the Behavior Driven Development framework is to make various
project roles such as Business Analysts, Quality Assurance, Developers, and
Support Teams understand the application without diving deep into the technical
aspects.
12) What is the limit for the maximum number of scenarios that can be included
in the feature file?
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.
Pipe symbol (|) is used to specify one or more parameter values in a feature file.
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.
kasper-analytics
kasperanalytics.com
9123820085
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.
Step definition corresponding to the step “Open Chrome browser and launch the
application” may look like the code mentioned below:
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.
@CucumberOptions(features="Features",glue={"StepDefinition"})
Given below are the list of JAR files that are to be downloaded for using
Cucumber with Selenium web driver:
kasper-analytics
kasperanalytics.com
9123820085
o cucumber-core-1.2.2.jar
o cucumber-java-1.2.2.jar
o cucumber-junit-1.2.2.jar
o cucumber-jvm-deps-1.0.3.jar
o cucumber-reporting-0.1.0.jar
o gherkin-2.12.2.jar
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.
23) Explain the purpose of keywords that are used for writing a scenario in
Cucumber.
o “Given” keyword is used to specify a precondition for the scenario.
o “When” keyword is used to specify an operation to be performed.
o “Then” keyword is used to specify the expected result of a performed
action.
o “And” keyword is used to join one or more statements together into a single
statement.
kasper-analytics
kasperanalytics.com
9123820085
24) What is the name of the plugin that is used to integrate Eclipse with
Cucumber?
Cucumber Natural Plugin is the plugin that is used to integrate Eclipse with
Cucumber.
TestRunner class is used to provide the link between the feature file and the step
definition file. The next question provides a sample representation of how the
TestRunner class will look like. A TestRunner class is generally an empty class with
no class definition.
Package com.sample.TestRunner
importorg.junit.runner.RunWith;
importcucumber.api.CucumberOptions;
importcucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features",glue={"StepDefinition"})
When integrated with Selenium, the starting point of execution must be from the
TestRunner class.
kasper-analytics
kasperanalytics.com
9123820085
No code should be written under the TestRunner class. It should include the tags
@RunWith and @CucumberOptions.
29) What is the use of features property under the Cucumber Options tag?
Features property is used to let the Cucumber framework identify the location of
the feature files.
30) What is the use of glue property under the Cucumber Options tag?
Glue property is used to let the Cucumber framework identify the location of step
definition files.
31) What is the maximum number of steps that are to be written within a
scenario?
3-4 steps.
In other words, we can say that "Cucumber is a software tool used by the testers
to develop test cases for the testing of behavior of the software."
kasper-analytics
kasperanalytics.com
9123820085
33) What is the main aim of the Behavior Driven Development (BDD)
framework?
The main aim of the 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.
34) What are the two files required to execute a Cucumber test scenario?
Following are the two files required to execute a Cucumber test scenario:
o Features
o Step Definition
Although Cucumber and Jbehave are designed for the same purpose, the most
distinctive difference between them is that Jbehave is based on stories while
Cucumber is based on features.
kasper-analytics
kasperanalytics.com
9123820085
In Cucumber, the test harness allows for separating responsibility between setting
up the context and interacting with the browser, and cleaning up the step
definition files. It collects stubs, drivers, and other supporting tools required to
automate test execution in testing.
39) What is the difference between RSpec and Cucumber? When should we
use RSpec and when to use Cucumber?
RSpec and Cucumber both are the example of testing frameworks. RSpec uses
traditional Unit Testing. It means it uses testing a class or part of the application in
isolation from the rest of the application. So your model does what your model is
supposed to do, the controller does what it is supposed to do, etc. RSpec and
Cucumber both are used for Acceptance Testing, also called ATDD, BDD, etc.
The main difference between RSpec and Cucumber is the business readability
factor.
RSpec is mainly used for Unit Testing. On the other hand, Cucumber is mainly
used for Behavior-driven development. We can also use it for System and
Integration Testing.
In Cucumber, the specifications or features are separate from the test code, so
the product owners can provide or review the specification without going through
the code. These are the .feature files that you make in Cucumber.
RSpec also has a similar mechanism, but instead of describing a step with a
Describe or Context, it uses the business specification to execute that statement.
This approach is a little easier for developers to work with but a bit harder for non-
technical guys.
kasper-analytics
kasperanalytics.com
9123820085
For a core developer, it is the best choice to use RSpec. It is easier to understand
for a technical person and offers a few advantages in keeping things scoped and
under control because you don't have to mess up with RegExs for test steps.
If you are building this for a client, you should choose Cucumber for Acceptance
Testing and use RSpec for Unit Testing.
Selenium is a web browser automation tool widely used for Functional Testing of
web- based applications. Selenium supports different programming languages
such as Java, Python, Ruby, C#, etc.
Selenium and Cucumber are both open-source testing tools, and both are used
for functional testing. But there are some differences between them.
➢ Selenium is a web browser automation tool for web apps, while Cucumber
is an automation tool for behavior-driven development that can be used
with Selenium (or Appium).
➢ Selenium is used for automated UI testing, while Cucumber is used for
acceptance testing.
➢ Selenium is preferred by technical teams (SDETs/programmers), while
Cucumber is typically preferred by non-technical teams (business
stakeholders and testers).
➢ Selenium can work independently of Cucumber. Cucumber depends on
Selenium or Appium for step-definition implementation.
➢ In Selenium, the script creation is complex, while Cucumber is simpler than
Selenium.
kasper-analytics
kasperanalytics.com
9123820085
43) What do you understand by TDD, and what are the different processes
used in TDD?
First, write the test case: You have to write an automated test case according to
your requirements.
Run all the test cases: Now, run these automated test cases on the currently
developed code.
Develop the code for that test case: In this process, you must write the code to
make that test case work as expected if the test case fails.
kasper-analytics
kasperanalytics.com
9123820085
Run test cases again: Now, you have to rerun the test cases and check if all the
test cases developed so far are implemented.
Refactor your code: This is an optional step. But, it is advised to refactor your code
to make it more readable and reusable. That's why it is essential.
Repeat steps 1- 5 for new test cases: This is the last step. Here, you have to repeat
the cycle for the other test cases until all the test cases are implemented.
kasper-analytics