Top 50 Cucumber Interview Questions and Answers 2025

  • By Prajakta Desai
  • February 21, 2025
  • Software Testing
Top 50 Cucumber Interview Questions and Answers 2025

Top 50 Cucumber Interview Questions and Answers 2025

Prepare for interviews with Top 50 Cucumber Interview Questions and Answers 2025 covering key concepts, frameworks, and best practices for automation testing.

 

1. What is TDD

Test Driven Development is a Testing methodology or programming practice that tests nothing but test cases of every functionality of an application based on requirements specified in the documents designed first. And then the code will be designed. 

It is an iterative process that has the following steps: 

✔ Set of tests are written for a new functionality  

✔ Application code is written based on a set of tests  

✔ Tests are run on an application code once ready  

Code is added/improved as the tests fail  

The cycle is repeated till all the tests PASS and Generate an application code that is bug-free

 

2. Why TDD? 

Unit-level testing actually proves that code is  

working 

Application code gets improved 

The process creates low-level Regression Test suit 

Reduces the cost of fixing bugs

 

3. What are the Drawbacks of TDD? 

⮚ Developers may consider it a time-consuming activity 

⮚ Tests are more targeted at checking classes and methods rather  than what code should really do 

⮚ Tests become part of the maintenance overhead for the project 

⮚ Tests need to be re-written as requirements change

 

4. What is BBD? 

BBD stands for Behavior Driven Development it is a testing approach that is derived from TDD. Like TDD even in BDD Tests are written first and then the application code. It defines various ways to develop a feature based on its behavior. In this tests are mainly based on systems behavior. 

 

5. How BDD is different from TDD? 

Tests are explained as a Behavior of the Application and are more  User-focused  

Tests are designed in plain descriptive English type grammar  Helps in clarifying requirements

 

6. What are the Features of Behavior Driven  Development? 

Need to Shift in thinking from “tests” to thinking as “behavior”  Behavior specified in a language that is easy to describe  Extension of Test Driven Development by Utilizing language that  

non-technical members and stakeholders can understand  Ensures collaboration between QA team, Development team,  Stakeholders, Business Analyst

 

7. What is a Cucumber.? 

It’s a testing framework that supports Behavior Driven  Development 

It is written in Ruby and can test code written in any language ∙ The Language that it understands is Gherkin

 

8. Why there is a BDD Language Requirements? 

All teams in the project need a common language to express requirements.  

Gherkin language should be simple enough to be understood by  Business team members  

With this language will remove most of the ambiguities for  developers and testers  

Here we should open up the thinking of team members to come up  with more scenarios  

It will be used as project documentation

 

9. What is Gherkin? 

Gherkin is a Business-readable, domain-specific language used to create  the behavior descriptions  

Gives users the ability to remove logic details from behavior tests  It serves as your project’s documentation and as automated tests  It is a line-oriented language that uses indentation to define the structure

 

10. What is a Cucumber Feature File? 

A Feature File is an entry point to the Cucumber tests  

This is a file where you will describe behaviors in Gherkin  It serves as a link to automation test script as well as live documents  

A feature file can contain a scenario or can contain many scenarios in a  single feature file

 

11. Which are the keywords from Gherkin? 

Given  

This keyword is used to puta system in a known state before the user starts interacting with the system. 

It is a set of pre-conditions that need to be fulfilled before we write our  use cases  

E.g. Given User is on the ome page  

When  

This keyword is used to describe the user action that he/she performs E.g. When the User navigates to the login page  

Then  

This keyword is used to describe the outcome of the previous user action   E.g. The message displayed Log in successfully 

And  

the keyword is used to add conditions to your steps  

Supposed in your particular scenario you need to write Given, When , Then multiple times which can lead to confusion  

To avoid this we can use the And keyword instead of multiple Given,  When, and Then  

E.g. When User Navigate to LogIn Page And User enters UserName  and Password 

But  

It is used to add negative type comments though it’s not a hard & fast rule 

It makes sense to use But when you try to add a condition that is  opposite to what your test is trying to set 

A given User is on the Home Page When the User Navigate to the LogIn Page  And User enters their UserName and Password But The user credentials are  wrong Then the Message displays the Wrong UserName & Password 

*  

It defies the whole purpose of having Given, When, Then,and all the  other keywords  

All the keywords will be replaced by the * keyword  

E.g. Feature: Login Action Test 

Description: This feature will test a Login functionality  Scenario: Successful Login with Valid Credentials  

* User is on the Home Page  

* User Navigate to Login Page  

* User enters the UserName and Password  

* Message displayed Login Successfully

 

12. How feature file will be created? What it can include? 

Every *.feature file can have only one feature.  

Lines starting with the keyword Feature:  

  • It contains multiple scenarios and a scenario outline 
  • Feature title follows the colon (:)  
  • The next line(s) sentences are the feature description 

Scenario: starts on a new line  

  • Text after colon(:) is called Scenario Title 
  • Every scenario consists of a list of steps which must start with keywords  Given  

When  

Then  

But  

And 

 

13. How Cucumber Test will run?  

Cucumber uses junit framework to run  

by using Junit annotation @RunWith(), which tells JUnit what is the  test runner class, the test will be run 

 

14 . What is Step Definition? 

  • It is a small piece of code with a pattern attached to it  
  • It is a Java method in a class with an annotation above it  ● It will give the implementation to gherkin steps 

 

15 . What is the use of @CucumberOptions? 

@CucumberOptions are like property files or settings for our cucumber  test ‘cucumber.api.CucumberOptions‘ imports the @CucumberOptions  annotation  

This annotation tells the Cucumber a lot of things like  Where to look for feature files 

What reporting system to use  

Console output readable format  

Paths of the step definition file  

Check if the steps have a definition 

 

Note: Do read Most Asked Software Testing Interview Questions and Answers

 

16. What is the use of DryRun? 

dryRun option can be either set as true or false  

  • if we set as true it will check the feature file steps code has been  implemented in the step definition file or not 
  • ‘dryRun = true‘ in TestRunner class  
  • @CucumberOptions(features = “Feature”, dryRun = true) 

 

17. What is the use of Glue code? 

It is used to locate the stepdefinition file  

It can be specified like as glue = “STEPDEFINITION“ Or if the Step  Definition file is in the deep folder structure glue =  

“src/test/STEPDEFINITION“  

@CucumberOptions(features = “Feature”, glue =  

{“STEPDEFINITION”}) 

 

18. What is the use of Monochrome?

This option can be set as true or false  

If it is true then the console output for the Cucumber test is much more  readable  

We just add the code ‘monochrome = true‘ in TestRunner class  @CucumberOptions(features = “Feature”, monochrome = true) 

 

19. What is the use of Format/plugin? 

Format Option is used to display output reports in different formats There are various options that can be used as for-matters  

Pretty: output will display with trace outing some error with different colors. 

Use format = {“pretty“}  

HTML: This will generate an HTML report at the location mentioned in the formatter itself. 

Use format = {“html:Folder_Name“} 

 

20. What is Data Driven Testing? 

Executing the same test case with different sets of data is called Data-driven testing  Cucumber inherently supports data-driven testing concepts using  Scenario Outline 

 

21. What are the ways to insert the data within cucumber? 

Following are the ways of data insertion. 

  1. Parameterization without example keyword 
  2. Parameterization with example keyword 
  3. Parameterization with Data Tables 
  4. Maps in data table with header 

 

22. what are the Differences between the Scenario Outline and Data Table? 

Scenario Outline:  

It will use the Example keyword to define the test data for the Scenario  It will work for the complete test  

Cucumber will automatically run the complete test the number of times  equal to the number of data in the Test Set  

Data Tables:  

There is No Example keyword is used to define the test data  It will work only for sa ingle step. which has been defined 

A separate code is needed to understand the test data and then it can be  run single or multiple times but again just for the single step, not for the  complete test

 

23. What are Cucumber Tags?  

if you do not want to run all the scenarios together and like to run a few  selected scenarios from different feature files together  

Define each scenario with a useful tag  

In the TestRunner file, we can decide which specific tag (and the  scenario(s)) we want Cucumber to execute  

Tag starts with “@”. After “@” we can have to give any name to that  tag  

e.g. @SmokeTests  

Target these tagged scenarios for execution by just specifying tag names in the CucumberOptions as tags = {“@SmokeTests”}  

Tagging also works with Features. You can also tag your feature files.  The tag that exists on a Feature will be inherited by Scenario, Scenario  Outline ,or Examples 

 

24. How you can Logically ANDing and ORing the  Tags? 

Execute all tests with the name given to the tagged as @SmokeTest OR  @RegressionTest  

Tags which are comma-separated are Ored  

@CucumberOptions(features = “Feature”, tags =  

{“@SmokeTest,@RegressionTest”})  

Execute all tests tagged as @SmokeTest AND @RegressionTest  The Tags which are having separate quotes are ANDed  

@CucumberOptions(features = “Feature”, tags =  

{“@SmokeTest”,”@RegressionTest”})

 

25. How to Ignore the Cucumber Tests? 

Execute all tests of the feature tagged as @Functional_Tests but  skip scenarios tagged as @Regression_Test  

@CucumberOptions(features = “Feature”, tags =  

{“@Functional_Tests”,”~@Regression_Test”})

 

26. What are Cucumber Hooks?  

Hooks a blocks of code that run before or after each scenario  

They can be defined anywhere in the tep definition file, using the methods  @Before and @After  

Cucumber Hooks helps us to reduce the code redundancy  @Before hook gets executed before any test scenario  

@After hook gets executed after executing every scenario

 

27. What can go in @Before hook?

Starting a webdriver  

Navigating to a certain page  

Login to the application or any pre-steps to be performed

 

28. What can go in @After hook? 

Killing the web driver  

Clearing the test data  

Clearing browser cookies  

Logging out from the application  

Taking screenshots of error

 

29. How to decide the Execution order of hooks 

@Before(order = int) :

It will run in increment order, which means value 0 would run first and 1  would be after 0  

@After(order = int) :  

It will run in decrements order, which means the opposite of @Before. first value  1 and then 0. 

@Before(order=1)  

public void beforeScenario() 

{  

 // before the Scenario it will run 

@Before(order=0)  

public void beforeScenarioStart() 

{  

//” before Scenario getting Start” 

}  

@After(order=0)  

public void afterScenarioFinish() 

{  

 //After Scenario End it will run 

}  

@After(order=1) 

public void afterScenario() 

{  

 //after scenario, it will run 

}

 

30. What is the Background in Cucumber? 

Given..when… Then… in Background instead of in Scenario executes  steps for every scenario in the feature  

When you have Background and @Before hook, Background gets  executed after @Before hooks execution gets completed 

 

31. What is the difference between Background and Hooks in a Cucumber? 

Any feature-level dependency should be handled with the use of  background and any scenario-level dependency should be handled with  hooks

 

32. How to run the Cucumber Test as a TestNG Test?

Add the following .jar files in the build path of your project

Cucumber-testng  

Testng  

Install TestNG component in Eclipse  

Comment/remove @RunWith annotation of Junit 

Extend TestRunner class with AbstractTestNGCucumberTests Abstract  class AbstractTestNGCucumberTests class will use TestNG to execute  the scenarios

 

33. How to set the Maven project for Cucumber? 

  • Maven is a build tool which helps us to manage our Project and  Project dependencies  
  • All dependencies are mentioned in POM.XML file  

POM stands for Project Object Model  

  • Create a new Maven project  

Group id is the name of the group/company  

Artifact id is the project name  

  • Add all dependencies for cucumber and selenium

 

34. How to run the Cucumber Test as Maven Test? We need two plugins as follows:

Maven compiler plugin 

Maven surefire plugin required to execute Java file 

Right-click on POM.XML select Run as Maven Clean  

Right-click on POM.XML select Run as Maven Install 

After running of test “Refresh” project to get reports in folder “Target” 

 

35. What is TestNG? 

It is a testing framework that is inspired by JUnit and NUnit but has some new functionality which makes it more powerful and easier to use. 

It is an open-source framework for Automation testing, where NG stands for Next Generation. 

This is similar to JUnit but comparatively, it is much more powerful than  JUnit but still, it’s inspired by JUnit.  

It has been designed to be better than JUnit, especially when we are testing integrated classes. It has been developed by Cedric Beust.

 

36. Why TestNG? 

⮚ There are many more benefits of TestNG but from a Selenium  perspective, the major advantages of TestNG are : 

⮚ It will produce the test reports in the HTML Format 

⮚ TestNG Annotations made testers’ lives easy 

⮚ Here the Test cases can be Grouped & Prioritized more easily ⮚ Parallel testing is possible by TestNG 

⮚ It Generates Logs 

⮚ Data Parameterization is also possible

 

37. Which are the Annotations available in TestNG? 

@Test  

This annotated method is one part of a test case without this tests are  not executed only 

@BeforeMethod  

This annotated method will be run before each test method is run 

 @AfterMethod  

It will be run after each test method from the class has run

@BeforeClass  

The annotated method will be run before the first test method in the class  get run 

@AfterClass  

It will be run after all the test methods from the class have run  @BeforeTest  

The annotated method will be run before running the test method from the  class  

@AfterTest  

This will be run after all the test methods from the classes have run @BeforeSuite  

The annotated method will be run before the first test from the suite has  been run 

@AfterSuite  

The annotated method will be run after all tests from the suite have run

 

38. In which Order TestNG AnnotationsExecuted? 

⮚ @BeforeSuite  

⮚ @BeforeTest  

⮚ @BeforeClass  

⮚ @BeforeMethod  

⮚ @Test  

⮚ @AfterMethod  

⮚ @AfterClass  

⮚ @AfterTest  

⮚ @AfterSuite

 

39. How to set the order of execution of tests in  TestNG? 

 In TestNG multiple tests can be included and all are executed in  Alphabetical order by default. But if we want to define the order use  parameter “priority” 

@Test(priority=0)  

TestNG will execute the @Test annotation with the lowest priority value  up to the largest

 

40. How we can specify the Dependencies to TestNG  Tests? 

TestNG allows to specify dependencies with attributes  

dependsOnMethods  

@Test(dependsOnMethods={‘openBrowser’}  

public void closeBrowser()  

{  

 driver.close();  

}  

@Test  

Public void openBrowser()  

{  

 driver=new ChromeDriver(); 

}

 

41. What is Test Suite? 

The collection of TestNG Tests together is called a Test Suite. 

By creating a Test suite, we can run multiple tests at a single test suite execution. These tests can be dependent on each other or may have to be executed in a specific order independently.  

It is important to remember that we need to create a TestNG XML  file for the test suite to be run

 

42. What is the Grouping of Tests? 

It Is a process where we need to group different tests together into a straightforward group and run all the tests from that group by just running that group in a single command.  

<?xml version=”1.0″ encoding=”UTF-8″?> 

<suite name=”Sample Suite”> 

<test name=”testing”> 

<groups> 

<run> 

<include name=”Regression”/> 

</run> 

</groups> 

<classes> 

<class name=”” />

 

43. What is meant by passing Parameters? 

 Like other programming languages whenever we are designing the methods then some inputs we required to perform some operations. So those operations can be performed on different values and that can be only possible by passing the parameters to methods. Here when the method or functions get invoked values will be passed. 

 

44. How to pass the Parameters in TestNG? There are two ways to Pass the Parameters in TestNG by:

1.TestNG Parameters 

2.TestNG DataProviders 

 

45. How is the value passed by Parameters Annotation in  TestNG? 

import org.testng.annotations.Parameters; 

import org.testng.annotations.Test;  

public class DemoPara 

@Test @Parameters ({“value1”, “value2”})  

public void add(int val1, int val2) 

 int add_res = val1 + val2;  

 System.out.print(“The addition of the given values is ”  +add_res);  

 }  

@Parameters({“ ”}) 

In .xml file use  

<parameter name=”” value=”” /> 

 

46. How is the value passed by DataProviderAnnotation in TestNG? 

public class DemoDp 

{  

@DataProvider (name = “d-provider”)  

public Object[][] dataproMethod() 

{  

 return new Object[][] {{10, 2 , 12}, {34, 5, 29}};  

}  

@Test (dataProvider = “d-provider”,dataProviderClass=DemoDp.class)  public void showTest (int a, int b, int ans)  

 int sumres = a + b;  

Assert.assertEquals(ans, sumres);  

}  

}

 

47. What is the difference between @Parameters and  @DataProvider in TestNG? 

DataProviders will pass the different parameters on a single test in a single execution, whereas parameters will pass the parameters only once per execution in TestNG.

 

48. What is Assertion? 

 It is a checkpoint to verify whether the expected result and actual result are matched or not. It will help in testing to validate the application behavior and update the tests as passed or failed. 

 

49. What are the Types of Assertions? 

 There are two types of Assertions 

 1. Hard Assertions 

 2 . Soft Assertions 

 

50. What is assertEquals()? 

 This is a method that will take two arguments and compare the actual result with the expected result. If both the results get matched, asserssion is passed and the test passed otherwise test failed. 

 

Do visit our channel to learn more: Click Here 

Author:-

Prajakta Desai

Call the Trainer and Book your free demo Class For Software Testing Call now!!!

 | SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd.