300+ TOP CUCUMBER Interview Questions and Answers

CUCUMBER Interview Questions and Answers for freshers experienced :-

1. 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 describes 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 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.

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

  • Support is a foder 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. What is profile in cucumber ?

  • 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

5. What are before, after, beforeStep and afterStep hooks?

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

6. 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 following command to execute a cucumber tagged scenarios

cucumber features -t @<tag_name>

Ex: cucumber features -t @test

7. what is cucumber dry run ?

Cucumber dry run is used to compile cucumber feature files and stepDefinitions. If there is any compilations errors it will show when we use dry run

Ex: Cucumber features –dry-run

8. 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.

9. What is scenario outline ?

Scenario outline is used to execute the same scenario with different test data.

we will add test data in examples section

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

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

CUCUMBER Interview Questions
CUCUMBER Interview Questions

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

12. How to generate cucumber execution reports ?

We can use the following command to generate html reports.

–format html –out report.html –format pretty

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

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

Ex: cucumber features/test.feature:21

14. What is Cucumber and 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 inolve business stakeholders who can not code
  • End user experience is priority
  • High code reuse

15. 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. What is feature file in Cucumber? What does feature file consist of ?

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

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

17. Give an example of behaviour 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 what is Scenario Outline in feature file?

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).

19. What is step definition in Cucumber?

A step definition is the actual code implementation of the feature mentioned in 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 given

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

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

end – This will visit www.yahoo.com

21. 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 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?

Rspec is used for Unit Testing
Cucumber is used behaviour driven development. Cucumber can be used for System and Integration Tests

24. 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 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 what is BDD (Behaviour Driven Development) ?

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

27. What softare do you need to run a Cucumber Web Test ?

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

28. 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. What is BDD Framework.what is the benefit of BDD in selenium ?

  • 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.

30. What is the purpose of Examples keyword in Cucumber?

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.

31. What is cucumber.yml file in cucumber ?

in cucumber.yml file we will create profiles

32. What is #{} and how do you use it?

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

33. what is error handling and how do you do error handling?

P584: Raise, Rescue

34. what is the difference between class and module?

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

Cucumber Basics:-

35. Feature Files:

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

36. Feature:

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

37. 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 what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”.

Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.
When: This is used when some action is to be performed. As in above example we have seen when the user tries to log in using username and password, it becomes an action.
Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.
Background: Whenever any step is required to perform in each scenario then those steps needs to be placed in Background. For Instance: If user needs to clear database before each scenario then those steps can be put in background.
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 user logs in using Username as “USER”
And password as “password”
Then login should be successful
And Home page should be displayed

Example of Background:

Background:

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

38. Scenario Outline:

Scenario outlines are used when 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 set 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 shown in above example column names are passed as parameter to When statement.
In place of Scenario, you have to use Scenario Outline.
Examples are used to pass different arguments in tabular format. Vertical pipes are used to separate two different columns. Example can contain many different columns.

39. 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 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. Cucumber Report:

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

41. What are the benefits?

  1. It is helpful to involve business stakeholders who can’t easily read 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 set up and execution
  5. Efficient tool for testing

42. What Is Cucumber And 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:

  1. You can inolve business stakeholders who can not code
  2. End user experience is priority
  3. High code reuse

CUCUMBER Interview Questions and Answers pdf Download

Leave a Reply

Your email address will not be published. Required fields are marked *