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?
BDD | TDD |
---|---|
It is a Behavior centred development process | IT is Test centred development process |
BDD tests are written in a readable format using Given-When-Then steps | TDD tests are written using programming languages like Ruby, JAVA etc |
BDD tests are readable by non-programmers | TDD tests are difficult to read by non-programmers |
Question 3: Mention Few advantages of cucumber-bdd Framework?
- Cucumber is an open-source tool.
- The primary advantage of Cucumber is its support of Behaviour Driven Development approach in testing.
- This tool helps in eliminating the gap between different technical and non-technical members of the team.
- Automation test cases developed using the Cucumber tool are easier to maintain and understand.
- 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?
Scenario Outline | Data Table |
---|---|
This uses Example keyword to define the test data for the Scenario | No keyword is used to define the test data |
This works for the whole test | This works only for the single step, below which it is defined |
Cucumber automatically run the complete test  the number of times equal to the number of data in the Test Set | A separate code needs 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 |
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.