Top 20+ Cucumber Interview Questions & Answers – Automation Laboratories

Cucumber Interview Questions & Answers | Automation laboratories

In this post, we will see Top 20+ Cucumber Interview Questions & Answers. Our main focus is on Selenium Integration with cucumber-bdd and to cover all popular questions which can be asked during an Interview.

Questions & Answers cucumber-bdd:

Question 1: What is Cucumber-bdd?

A cucumber is a tool that is based on Behavior Driven Development (BDD) methodology.

Behaviour-driven development, or BDD, is another agile software development process that encourages collaboration in a software project between developers, QA, project managers and the business team. It enables developers, QA, project managers to understand the application without diving deep into the technical aspects.

Question 2: Mention differences between TDD and BDD?

Question 3: Mention Few advantages of cucumber-bdd Framework?

  1. Cucumber is an open-source tool.
  2. The primary advantage of Cucumber is its support of Behaviour Driven Development approach in testing.
  3. This tool helps in eliminating the gap between different technical and non-technical members of the team.
  4. Automation test cases developed using the Cucumber tool are easier to maintain and understand.
  5. Easy to integrate with other tools such as Selenium.

Question 4: What is meant by a Feature file?

A feature file in Cucumber is a starting point of the Cucumber tests execution. A feature file can have a single or multiple scenarios but normally it contains a group of scenarios. A Feature file is the High-level description of the Application Under Test. The feature file format will be like file_name. a feature where a single file contains a single feature.

Question 5: What are different Keywords used in cucumber-bdd for writing a Scenario?

  • Given
  • When
  • Then
  • And

Question 6:What is Scenario Outline in cucumber-bdd?

Scenario outline is a way of parameterization of scenarios. It 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 (| |)

Feature: Application Login
Scenario Outline: Application Website Login
Given Open browser
When NewUser enters "<uname>" and "<password>" and "<send_text>"
Then Message displayed Login Successful
Examples: 
| uname | password | send_text |
| [email protected] | [email protected] | automation laboratories |
| [email protected] | [email protected] | automation laboratories |

Question 7: What is the difference between Scenario and Scenario Outline?

Scenario: Copying and pasting scenarios to use different values can quickly become tedious and repetitive:

Scenario: Eat 5 out of 12
  Given there are 12 cucumbers
  When I eat 5 cucumbers
  Then I should have 7 cucumbers

Scenario: Eat 5 out of 20
  Given there are 20 cucumbers
  When I eat 5 cucumbers
  Then I should have 15 cucumbers

Scenario Outlines:  allow us to more concisely express these examples through the use of a template with placeholders

Scenario Outline: Eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |  12   |  5  |  7   |
    |  20   |  5  |  15  |

The Scenario Outline steps provide a template which is never directly run. A Scenario Outline is run once for each row in the Examples section beneath it (except for the first header row).

Question 8: What is Step Definition?

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. Step definitions file has the actual code implementation of the Scenario or Scenario Outline step.

Feature file:

Feature:
  Scenario:
    Given verify two values 'text', 'test'

Step Definition:

public class Test {
@Given("verify two values '(.*)', '(.*)'")
public void verify_two_values(String arg1, String arg2) {
Assert.assertEquals(arg1,arg2);
}

Question 9: What is Background in a Feature file?

Steps which are 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.

Feature: Validation of Account Balance
Background:
Given I log in to the Application 
Scenario: Verify Positive Balance
Given I have $1000 in my account
When I withdraw $50
Then I should have $950 balance
Scenario: Verify Zero Balance
Given I have $1000 in my account
When I withdraw $1000
Then I should have $0 balance

Question 10: How does the Junit Test runner class look like explain the same?

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features="src/test/resources/features",
        glue= "ca.testing.stepdefinitions",
        tags = @regression,
        dryRun = false,
        strict = true,
        monochrome = true)
public class TestRunner{}

@CucumberOptions are used to set specific properties for your cucumber test.

Properties are,

  • Feature – path to feature file
  • Glue – path to the step definition
  • dryRun – boolean value – check for missing step definition
  • tags – used to group cucumber scenarios in the feature file
  • strict – boolean value – fail the execution if there is a missing step
  • monochrome – boolean value – display console output in a readable way

Question 11: What are Tags in cucumber-bdd?

Cucumber tags are used to organize scenarios in your feature file. Example: @regression, @sanity, @EndtoEnd

Tags are used to

  • Group scenarios
  • Ignore scenarios from execution
  • Logically group (OR & AND)
Feature: Validation of the Account Balance

@regression @sanity
Scenario: Verify Zero Balance
Given I have $1000 in my account
When I withdraw $1000
Then I should have $0 balance

Question 12: Explain Cucumber Hooks?

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.

public class Hooks {

@Before
public void before(){
System.out.println("This will execute before every Scenario");
}
@After
public void after(){
System.out.println("This will execute after every Scenario");
}
}

Question 13:Explain Difference between Examples Table and Data Table?

Question 14: Framework Design which can be implemented in Cucumber?

  • Page Object Model
  • Log4j
  • Extent Reporting
  • Dependency Injection (Example: Pico Container)
  • Object Repository

Question 15: Name any two testing framework that can be integrated with Cucumber?

  • JUnit
  • TestNG

Question 16:What are the two files required to run a cucumber test?

  • Feature file
  • Step Definition file

Question 17:What are the differences between Jbehave and Cucumber?

Although Cucumber and Jbehave are meant for the same purpose, acceptance tests are completely different frameworks

  • Jbehave is, and Cucumber is Ruby-based
  • Jbehave are based on stories while Cucumber is based on features

Question 18:Explain 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.

Question 19: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.

Question 20: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 testing for the steps in scenarios.

q? encoding=UTF8&MarketPlace=IN&ASIN=1784394351&ServiceVersion=20070822&ID=AsinImage&WS=1&Format= SL250 &tag=7033b 21 - June 3, 2023 Automationlaboratoriesir?t=7033b 21&l=am2&o=31&a=1784394351 - June 3, 2023 Automationlaboratories

q? encoding=UTF8&MarketPlace=IN&ASIN=1788473574&ServiceVersion=20070822&ID=AsinImage&WS=1&Format= SL250 &tag=7033b 21 - June 3, 2023 Automationlaboratoriesir?t=7033b 21&l=am2&o=31&a=1788473574 - June 3, 2023 Automationlaboratories

q? encoding=UTF8&MarketPlace=IN&ASIN=1788999762&ServiceVersion=20070822&ID=AsinImage&WS=1&Format= SL250 &tag=7033b 21 - June 3, 2023 Automationlaboratoriesir?t=7033b 21&l=am2&o=31&a=1788999762 - June 3, 2023 Automationlaboratories

q? encoding=UTF8&MarketPlace=IN&ASIN=1788299671&ServiceVersion=20070822&ID=AsinImage&WS=1&Format= SL250 &tag=7033b 21 - June 3, 2023 Automationlaboratoriesir?t=7033b 21&l=am2&o=31&a=1788299671 - June 3, 2023 Automationlaboratories

q? encoding=UTF8&MarketPlace=IN&ASIN=B01EW3N03O&ServiceVersion=20070822&ID=AsinImage&WS=1&Format= SL250 &tag=7033b 21 - June 3, 2023 Automationlaboratoriesir?t=7033b 21&l=am2&o=31&a=B01EW3N03O - June 3, 2023 Automationlaboratories