100 Top Cucumber Job Interview Questions and Answers

Cucumber Interview Questions and Answers:-

1. Define what is Cucumber?

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 describe the behavior of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.

2. Cucumber execution starts from where?

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

3. Define what is support, env.rb, and hooks .rb?

  • Support is a folder 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

4. Define what is a profile in cucumber?

  1. We can create Cucumber profiles to run specific features and step definitions
  2. We can use the following command to execute a cucumber profile
  3. cucumber features -p <profile_name>

Ex: cucumber features -p regression

5. Define what is before, after, beforeStep and afterStep hooks?

  • Before: execute before the feature file execution
  • After: executes after the feature file execution
  • BeforeStep: executes before each step execution
  • AfterStep: executes after each step execution

6. Define what are cucumber tags? why we use the tags?

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 the following command to execute cucumber tagged scenarios

cucumber features -t @<tag_name>

Ex: cucumber features -t @test

7. Define what is cucumber dry run?

Cucumber dry run is used to compile cucumber feature files and step definitions. If there are any compilations errors it will define How when we use dry run

Ex: Cucumber features –dry-run

8. Define what is the maximum number of scenarios and scenario steps that we can use in a single feature file?

9. Define what is scenario outline?

  • Scenario outline is used to execute the same scenario with different test data.
  • we will add test data in the examples section

10. Define what are the keywords that we use in cucumber scenario steps?

We use Given, when, Then, And and But keywords in cucumber scenario steps

11. Is it mandatory to use the keywords while writing scenario steps?

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 landing page

12. Define How to generate cucumber execution reports?

We can use the following command to generate HTML reports.

–format HTML –out report.html –format pretty

13. Define How to run a particular scenario from a feature file?

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

Ex: cucumber features/test.feature:21

14. Define what is Cucumber and Define what are the advantages of Cucumber?

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 involve business stakeholders who can not code
  • End user experience is a priority
  • High code reuse

15. Define what are the 2 files required to execute a Cucumber test scenario?

The 2 files required to execute a Cucumber test scenario are

  1. Features
  2. Step Definition

16. Define what is feature file in Cucumber? Define what does feature file consist of?

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

  • Feature
  • Scenario
  • Scenario Outline
  • Given
  • When
  • Then

17. Give an example of a behavior is driven test in plain text?

  • 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

18. Explain Define what is Scenario Outline in feature file?

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

19. Define what is step definition in Cucumber?

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

20. Give the example for step definition using “Given” function?

For example to make visitor visit the site “Yahoo” the command we use for giving

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

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

end – This will visit www.yahoo.com

21. Define what are the difference between Jbehave and Cucumber?

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

22. Explain Define what is test harness?

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

23. Explain when to use RSpec and when to use Cucumber?

  1. Rspec is used for Unit Testing
  2. Cucumber is used for behavior driven development. Cucumber can be used for
  3. System and Integration Tests

24. Define what is the language used for expressing scenario in feature file?

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

25. Explain Define what is regular expressions?

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

26. Explain Define what is BDD (Behaviour Driven Development)?

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

27. Define what software do you need to run a Cucumber Web Test?

  • Ruby and its Development Kit
  • Cucumber
  • IDE like ActiveState
  • Water ( To simulate browser)
  • Ansicon and respect (if required)

28. Define what does a features/ support file contains?

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

29. Define what is BDD Framework. Define what is the benefit of BDD in selenium?

  • BDD is becoming a 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 film. Apart from testing APIs with Cucumber-JVM, we can also test UI level tests by combining Selenium WebDriver.

30. Define How does feature file calls step definitions file in cucumber?

31. Define what is the cucumber.yml file in cucumber?

in a cucumber.yml file, we will create profiles

32. Define what is #{} and Define How do you use it?

P42, interpolation. most case used as puts “#{x} + #{y}” = “#{x+y}”

33. Define what is error handling and Define How do you do error handling?

P584: Raise, Rescue

34. Define what is the difference between class and module?

P141, P142
The class can do: inheritance, having an instance, while module CAN NOT. Can be required.
A module can do: make namespace to avoid a name clash, can be included.
#instantiate from a class within the module
Module A
Class B
End
b= A::B.new

Cucumber Basics:-

35. Define Feature Files:

Feature files are an essential part of cucumber which is used to write test automation steps or acceptance tests. This can be used as a live document. The steps are the application specification. All the feature files end with the .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”
  • The error message should be thrown

36. Define Feature:

This gives information about the high-level business functionality (Refer to the previous example) and the purpose of Application under test. Everybody should be able to understand the intent of a feature file by reading the first Feature step. This part is basically kept brief.

37. Define Scenario:

Basically, a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and Define what the test is all about. Each scenario should follow given, when and then format. This language is called “gherkin”.

  1. Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.
  2. When: This is used when some action is to be performed. As in the above example, we have seen when the user tries to log in using username and password, it becomes an action.
  3. Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.
  4. Background: Whenever any step is required to perform in each scenario then those steps need to be placed in Background. For Instance: If a user needs to clear database before each scenario then those steps can be put in a background.
  5. And: And is used to combine two or more same type of action.
    Example:

Feature: Login Functionality Feature

Scenario: Login Functionality
Given user navigates to SOFTWARETETINGHELP.COM
When a user logs in using Username as “USER”
And password as “password”
Then login should be successful
And the Home page should be displayed

Example of Background:

Background:

  • Given user logged in as the databases administrator
  • And all the junk values are cleared

38. Define Scenario Outline:

Scenario outlines are used when the same test has to be performed with different data set. Let’s take the same example. We have to test login functionality with multiple different sets of username and password.

Feature: Login Functionality Feature

  • In order to ensure Login Functionality works,
  • I want to run the cucumber test to verify it is working

Scenario Outline: Login Functionality

Given user navigates to SOFTWARETESTINGHELP.COM
When user logs in using Username as <username> and Password <password>
Then login should be successful

Examples:
|username |password |
|Tom |password1 |
|Harry |password2 |
|Jerry |password3 |

Note:

  • As defined How in above example column names are passed as a parameter to When statement.
  • In place of Scenario, you have to use Scenario Outline.
  • Examples are used to pass different arguments in a tabular format. Vertical pipes are used to separate two different columns. An example can contain many different columns.

39. Define JUnit Runner:

To run the specific feature file cucumber uses standard JUnit Runner and specify tags in @Cucumber. Options. Multiple tags can be given by using comma separate. Here you can specify the path of the report and type of report you want to generate.

Example of Junit Runner:

import cucumber.api.junit.Cucumber;</pre>
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@Cucumber.Options(format={“SimpleHtmlReport:report/smokeTest.html”},tags={“@smokeTest”})
Public class JUnitRunner {
}
Similarly, you can give instruction to cucumber to run multiple tags. Below example illustrates Define How to use multiple tags in cucumber to run different scenarios.

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@Cucumber.Options(format={“SimpleHtmlReport:report/smokeTest.html”},tags={“@smokeTest”,”@LoginTest”})
Public class JUnitRunner {
}

40. Define Cucumber Report:

Cucumber generates its own HTML format. Define However better reporting can be done using Jenkins or bamboo tool. Details of reporting are covered in the next topic of cucumber.

41. Define what are the benefits?

  1. It is helpful to involve business stakeholders who can’t easily read the code
  2. Cucumber focuses on end-user experience
  3. Style of writing tests allow for easier reuse of code in the tests
  4. Quick and easy setup and execution
  5. An efficient tool for testing

42. Advantages of Cucumber over other tools?