Cucumber Interview Questions Flashcards

1
Q

What is Cucumber? What is BDD? Why did you decide to start using Cucumber ?

What is the difference between Cucumber and TestNG?

A

Cucumber is a tool used to run automated acceptance tests created in a BDD format.

One of its most outstanding features of the tool is the ability to carry out plain-text functional descriptions (written in the language called Gherkin) as automated tests.

BDD means explaining the customer requirement in plain text and that enables all stakeholders to be on the same page with requirements which makes acceptance easy.

The best reason for choosing the Cucumber is that we can explain the requirements in simple english.

Cucumber software tool allows the stakeholders of business to be involved in it even if they don’t know how to code. The experience of the users is
prioritized by using the Cucumber tool. Cucumber tool allows the codes to be reused.

Difference between TestNG and Cucumber, TestNG is a testing framework where you specify test classes that need to be executed.

Cucumber is a tool to run acceptance tests written in
Behaviour driven development style.

Gherkin is the language that Cucumber uses to define test cases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How did you use Cucumber in your framework?

A

Main components of Cucumber are step definitions and feature files.

Feature files will have test cases which are written in Gherkin Language using Given When Then.

Step definitions consist of an actual automation code written using Selenium and Java.

All the Step Definitions are stored in a separate folder with naming convention as src/test/java and all the feature files are stored in a separate folder with naming convention as src/test/resources.

And then we will have a TestRunner class that uses JUnit to run our tests.

TestRunner is the starting point of test execution which gathers all tests to be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Feature: Defines what feature you will be testing in the tests below

Scenario: we are describing the test case here
Given: Tells the precondition of the test
When Defines actions to be taken
And: Defines additional/ continues conditions of the test
Then: States the post condition. You can say that it is the expected result of the test.

Example:

#Author: syntax team
Feature: Add Employee
 Background:
 Given I logged in into HRMS
 And I navigated to Add Employee Page
 @smoke
 Scenario: Add new Employee
 When I add "John", "S" and "Smith"
 And I click Save
 Then I see Employee has been successfully added
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two files required to run a Cucumber test?

A

● A feature file.

● A step definition file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a feature file? What is the extension?

What is there in a feature file? What are the keywords used in feature files?

A

A Feature File is an entry point to the Cucumber tests.

This is a file where we describe our tests in Descriptive Language.

It is an essential part of Cucumber, as it serves as an automation test script as well as live documents.

A feature file should start with a Feature keyword and can contain a scenario or many scenarios in a single feature file but it usually contains a list of scenarios.

.feature is the extension of a feature file.

Example:
“AddEmployee.feature” is a feature file name.
In the feature file we will define below keywords:
Feature, Scenario, Background, Scenario Outline,

The keywords defined by Gherkin are Given, When, And, But and Then.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the language used to write scenarios in a feature file?

What is the main purpose?

A

Gherkin is a plain-text language used to write Cucumber scenarios in a feature file.

Gherkin is a business readable, domain-specific language used to describe the behavior of software applications from the user’s perspective so that it’s easy for non-programmers to read and collaborate.

Gherkin is not necessarily used to write automated tests. Gherkin is primarily used to write structured tests which can later be used as project documentation.

The property of being structured gives us the ability to automate them. This automation is done by Cucumber.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is it mandatory to use Given, When, Then keywords while writing scenario? What is the difference?

A

No it is not mandatory to use Gherkin keywords. Gherkin keywords makes our scenario be in a more readable format.

  • can also be used to write steps
    in the feature file.

Using Gherkin keywords provide better readability as each keyword has a specific meaning: Given is for precondition, When is for action, Then is for result.

Feature: Account Balance
Scenario: Verify Positive Balance
 * I have $100 in my account
 * I withdraw $50
 * I should have $50 balance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Name any 2 testing frameworks that can be integrated with Cucumber?

A

● TestNG

● Junit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Name any two build management tools that can be integrated with Cucumber?

A

● Gradle

● Maven

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain Cucumber Tags?

How to run only specific scenarios?

How to run multiple scenarios with tags?

How to exclude tagged scenarios?

A

Cucumber tags are used to organize scenarios in feature files. We can have as many tags as we like before a scenario or feature. @ is used to represent tags.
Example: @regression, @sprint5, @payment

Tags are used to:
● Group scenarios
● Ignore scenarios from execution
● Logically group (OR & AND)

Examples:
To execute specific tags, we have to mention them in CucumberOption in our runner class. @Cucumber.Options(tags=”@smoke “)

To execute multiple tags:
Execute all tests tagged as @smoke OR @regression
@CucumberOptions(tags = “@smoke or @regression”)

Execute all tests tagged as @smoke AND @regression
@CucumberOptions(tags = “@smoke and @regression”)

To skip specific tags
@CucumberOptions(tags = “not @smoke”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the use of the keyword “background” in a feature file?

A

Author: syntaxteam

Background in Cucumber is used to define a step or series of steps which are common to all the tests/scenarios in the feature file.

It allows us to add some context to the scenarios for a feature where it is defined.

A background is much like a scenario containing a number of steps. But it runs before each and every scenario in a feature it is defined.

@sprint6 @addEmployee
Feature: Add new Employee
Background:
Given user is logged with valid admin credentials
And user navigates to AddEmployeePage
@smoke
Scenario: Add Employee with first and last name
When user enters employees “John” and “Doe”
And user clicks save button
Then “John Doe” is added successfully

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain Cucumber Hooks? What’s Before/After hook?

A

Cucumber Hooks are blocks of code that can be used to run before and after the scenarios using @before and @after. It helps us eliminate the redundant code steps that we write for every scenario and also manages our code workflow.

Hooks is a class that must be in the same package as step definitions and hooks will not be executed if dryRun=true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is @CucumberOptions in test runner? List the properties of @CucumberOptions.

A

@CucumberOptions are used to set specific properties for our Cucumber test.

Properties are:

● feature – path to feature file
● glue – path to step definition
● dryRun – boolean value – check for missing step definition
● tags – used to group Cucumber scenarios in the feature file
● monochrome – boolean value – display console output in a readable way
● plugin – What all report formats to use
➔ “Pretty” print details in console about scenario, tags etc
➔ “html” Generates html report in specified folder
➔ “json” Generates json report in specified folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between scenario and scenario outline?

A

Scenario
Represents a particular functionality which is under test. By seeing the scenario, the user should be able to understand the intent behind the scenario and what the test is all about.

Scenario Outline
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 (| |). We can achieve data driven testing using scenario Outline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can we achieve data driven testing in Cucumber?

What is DataTable in Cucumber?

DataTable vs Scenario Outline?

A

To achieve data driven testing in Cucumber we can use:
● Scenario Outline and Examples keyword
● DataTable

Cucumber DataTables lets us store data in a feature file.
There are 2 types of DataTable: with the header and without the header.

DataTable vs Scenario Outline

Scenario Outline:
● uses Example keyword to define the test data for the Scenario
● works for the whole test/scenario
● Cucumber automatically run the complete test the number of times equal to the number of data in the Test Set

Data Table:
● no keyword is used to define the test data
● works only for the single step, below which it is 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When in Cucumber some test scenarios fail and now you want to run failed ones, how would you do it?

A
  1. Modify existing runner class
    Add rerun:target/rerun.txt to your plugin
    This will run all tests and then list all failed scenarios in rerun.txt file
    The file rerun.txt file is located in the target folder.
    Rerun.txt contains path to the feature file and line number for scenario that failed
  2. Create another runner class