Ruby Cucumber Interview Questions and Answers
Last updated on 14th Oct 2020, Blog, Interview Question
Cucumber is a tool that is based on Behavior Driven Development (BDD) framework.
BDD is a methodology to understand the functionality of an application in the simple plain text representation.
This tutorial covers the most common Cucumber interview questions along with their answers and examples when demanded in simple terms for your easy understanding.
1.How Does Cucumber Works With Browser Automation?
Ans:
Cucumber does not provide built in browser automation. However, it does work well with existing gems such as Selenium and WATiR-WebDriver.[24] It does support running tests with transactions through leveraging other gems such as ActiveRecord.
2. What Are Formatter Plugins In Cucumber?
Ans:
Cucumber uses Formatter Plugins to provide output. Several common formats are provided by default, including
- JSON
- HTML
- JUnit
3.What Are Hooks In Cucumber?
Ans:
Hooks are Cucumber’s way of allowing for setup to be performed prior to tests being run and teardown to be run afterward. They are defined as executable Ruby blocks, similar to JUnit methods marked with @Before, @After annotations. Conventionally
they are placed under support/, and are applied globally. Three basic types of hooks exist.
Before –
Runs before a scenario
After –
Runs after a scenario
Around –
Assumes control and runs around a scenario
Additional hooks include
- BeforeStep
- AfterStep
- AfterConfiguration – Runs after Cucumber configuration and is passed an instance of the configuration
4.What Are Steps In Cucumber?
Ans:
Steps in Gherkin’s .feature files can be considered a method invocation. Before Cucumber can execute a step it must be told, via a step definition, how that step should be performed.
Definitions are written in Ruby and conventionally filed under features/step_definitions/*_steps.rb. Definitions start with the same keywords as their invocation (including Gherkin’s full language support). Each definition takes two arguments.
Either a regular expression or string with $variables
A block containing ruby code to execute
5.What Are Tags In Cucumber?
Ans:
Gherkin’s Feature structure forces organization. However, in cases where this default organization is inconvenient or insufficient, Gherkin provides Tags. Tags are @-prefixed strings and can be placed before.
- Feature
- Scenario
- Scenario Outline
- Examples: An element can have multiple tags and inherits from parent elements.
6.What Is A Scenario In Cucumber?
Ans:
Each Feature is made of a collection of scenarios. A single scenario is a flow of events through the Feature being described and maps 1:1 with an executable test case for the system. Keeping with the example ATM withdrawal feature, a scenario might describe how a user requests money and what happens to their account.
7.What Is A Feature In Cucumber?
Ans:
A feature is a Use Case that describes a specific function of the software being tested. There are three parts to a Feature [18]
- The Feature: keyword
- The Feature name (on the same line as the keyword)
- An optional description on the following lines
8.Cucumber Tests Are Divided Into How Many Parts?
Ans:
Cucumber tests are divided into individual Features. These Features are subdivided into Scenarios, which are sequences of Steps.
9.Gherkins Files Have Which File Extension?
Ans:
All Gherkin files have the .feature file extension. They contain a single Feature definition for the system under test and are an executable test script.
10.Cucumber Is Written In Which Programming Language?
Ans:
Cucumber is written in the Ruby programming language. It was originally used exclusively for Ruby testing as a complement to the RSpec BDD framework. Cucumber now supports a variety of different programming languages through various implementations.
11.What Is Gherkin Language?
Ans:
Gherkin is the language that Cucumber uses to define test cases. It is designed to be non-technical and human readable, and collectively describes use cases relating to a software system.
The purpose behind Gherkin’s syntax is to promote Behavior Driven Development practices across an entire development team, including business analysts and managers.
12.What Is Cucumber Tool?
Ans:
Cucumber is a software tool used by computer programmers for testing other software. It runs automated acceptance tests written in a behavior-driven development style. Central to the Cucumber BDD approach is its plain language parser called Gherkin.
Subscribe For Free Demo
Error: Contact form not found.
13.There Are Three Ways To Invoke A Method In Ruby. Can You Give Me At Least Two? Here, I’m Looking For The Dot Operator (or Period Operator), The Object#send Method, Or Method(:foo).call?
Ans:
- object = Object.new
- puts object.object_id
- #=> 282660
- puts object.send(:object_id)
- #=> 282660
- puts object.method(:object_id).call # (Kudos to Ezra)
- #=> 282660
14.What Is Profile In Cucumber?
Ans:
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
15.What Is Support, Env.rb And Hooks.rb?
Ans:
- Support is a foder where we can setup cucumber related support.
- rb file will be used to load the required libraries for cucumber scenario execution
- rb we will add hooks like before, after, beforeStep and afterStep hooks
16.Cucumber Execution Starts From Where?
Ans:
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.
17.What Are Cucumber Tags? Why We Use The Tags?
Ans:
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>
18.Define What Are The Benefits?
Ans:
- It is helpful to involve business stakeholders who can’t easily read code
- Cucumber focuses on end-user experience
- Style of writing tests allow for easier reuse of code in the tests
- Quick and easy set up and execution
- Efficient tool for testing
19.Define Cucumber Report?
Ans:
Cucumber generates its own html format. Define However better reporting can be done using Jenkins or bamboo tool. Details of reporting are covered in next topic of cucumber.
20.Define What Is The Difference Between Class And Module?
Ans:
- P141, P142
Class can do:
inheritance, having instance, while module CAN NOT. Can be required.
Module can do:
make namespace to avoid name clash, can be included.
- #instantiate from class within module
- Module A
- Class B
- End
- b= A::B.new
21.Define What Is Error Handling And Define How Do You Do Error Handling?
Ans:
P584: Raise, Rescue
22.Define What Is Bdd Framework.define What Is The Benefit Of Bdd In Selenium ?
Ans:
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.
23.Define What Software Do You Need To Run A Cucumber Web Test ?
Ans:
- Ruby and its Development Kit
- Cucumber
- IDE like ActiveState
- Watir ( To simulate browser)
- Ansicon and rspec (if required)
24.Define What Does A Features/ Support File Contains?
Ans:
Features/ support file contains supporting ruby code. Files in support load before those in step_definitions, which can be useful for environment configuration.
25.Explain Define What Is Regular Expressions?
Ans:
A regular expression is a pattern describing a certain amount of text. The most basic regular expression consists of a single literal character.
26.Define What Is The Language Used For Expressing Scenario In Feature File?
Ans:
Gherkin language is used to express scenario in feature files and ruby files containing unobtrusive automation for the steps in scenarios
27.Explain When To Use Rspec And When To Use Cucumber?
Ans:
- Rspec is used for Unit Testing
- Cucumber is used behaviour driven development.
- Cucumber can be used for System and Integration Tests
28.Explain Define What Is Test Harness?
Ans:
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.
29.Define What Are The Difference Between Jbehave And Cucumber?
Ans:
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
30.Define What Is Step Definition In Cucumber?
Ans:
A step definition is the actual code implementation of the feature mentioned in feature file.
31.Explain Define What Is Scenario Outline In Feature File?
Ans:
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).
32.Give An Example Of Behaviour Driven Test In Plain Text?
Ans:
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
33.Define What Is Cucumber And Define What Are The Advantages Of Cucumber?
Ans:
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
34.Define How To Generate Cucumber Execution Reports ?
Ans:
We can use the following command to generate html reports.
–format html –out report.html –format pretty
35.Define What Are The Keywords That We Use In Cucumber Scenario Steps ?
Ans:
We use Given,when,Then,And and But keywords in cucumber scenario steps .
36.Define What Is Scenario Outline ?
Ans:
Scenario outline is used to execute the same scenario with different test data.
we will add test data in examples section
37.How To Run A Particular Scenario From A Feature File?
Ans:
We can run particular scenario from a feature file by giving the scenario line number
Ex:
- cucumber features/test.feature:21
38.Define What Is Cucumber Dry Run ?
Ans:
Cucumber dry run is used to compile cucumber feature files and step Definitions. Of there is any compilations errors it will Define How when we use dry run
Ex:
- Cucumber features –dry-run
39.Define What Are Before, After, Beforestep And Afterstep Hooks?
Ans:
- Before: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
40.Cucumber Execution Starts From Where ?
Ans:
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.
Cucumber Basics:-
41.Feature Files:
Ans:
Feature files are essential part of cucumber which is used to write test automation steps or acceptance tests. This can be used as live document. The steps are the application specification. All the feature files ends with .feature extension.
Sample feature file:
Feature: Login Functionality Feature
In order to ensure Login Functionality works,
I want to run the cucumber test to verify it is working
Scenario: Login Functionality
Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER” and Password “PASSWORD”
Then login should be successful
Scenario: Login Functionality
Given user navigates to SOFTWARETETINGHELP.COM
When user logs in using Username as “USER1” and Password “PASSWORD1”
Then error message should be thrown
42.Explain about and, but keywords in Cucumber?
Ans:
“And” is used to combine two or more same type of action.
Cucumber steps beginning with “And” or “But” are exactly the same as all other steps.
Example:
- Given one thing
- And another thing
- When I open my eyes
- Then I see something
- But I don’t see something else
43.What do you mean by grouping in Cucumber?
Ans:
Cucumber will not take care how you name your step definition files and what step definitions you put in which file.
You can create steps.rb file for each Major operation / Features instead of keeping all steps in a single file. This process is called a grouping.
Example
Under features folder
- Adding_steps.rb
- Multiplying_steps.rb
44.How can you generate reports using Cucumber?
Ans:
You can generate the output/report of the cucumber using different cucumber commands.
- cucumber adding.feature –format HTML
- cucumber adding.feature –out report.html
- cucumber adding.feature –format pretty
The report file will be stored in the project folder itself.
45.What is the use of step definition files?
Ans:
Step definition maps the test case steps in the feature files(introduced by Given/When/Then) to code which executes and checks the outcomes from the system under test.
A step definition is analogous to a method defined in any kind of Object Oriented programming language.
Step definition is defined in ruby files under features/step_definitions/*_steps.rb”.
46.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.
47.What symbol is used for parameterization in Cucumber?
Ans:
Pipe symbol (|) is used to specify one or more parameter values in a feature file.
48.How can Cucumber be integrated with Selenium WebDriver?
Ans:
Cucumber can be integrated with the 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
49.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.
Are you looking training with Right Jobs?
Contact Us- Selenium Tutorial
- JUnit Interview Questions and Answers
- Appium Interview Questions and Answers
- Software Testing Interview Questions and Answers
- Jmeter Interview Questions and Answers
Related Articles
Popular Courses
- Selenium Online Training
11025 Learners
- Software Testing Training Course
12022 Learners
- Appium Training
11141 Learners
- What is Dimension Reduction? | Know the techniques
- Difference between Data Lake vs Data Warehouse: A Complete Guide For Beginners with Best Practices
- What is Dimension Reduction? | Know the techniques
- What does the Yield keyword do and How to use Yield in python ? [ OverView ]
- Agile Sprint Planning | Everything You Need to Know