Cucumber with Java Interview Questions

Showing 1 - 10 of 63 results

What is the meaning of Steps in Cucumber tool?

The steps are sequences which help in describing how exactly the test scenario will take place. It also defines the preconditions of the test scenario. It consists of the following commands or keywords- 

  • Given - Before starting the tests, all of its conditions is described by this. 
  • When - The actions during Cucumber tests are described by this. 
  • Then - This is the outcome of the actions which took place When.  
  • And - logical representation of the Cucumber test  
  • But - This is same as And but is negative form.  

How can any scenario in the feature file be written?

The Cucumber test scenarios are written with the help of a very simple language in the feature file. This language is known as Gherkin. This simple programming language is also business readable. The behavior and how the software developmental process works are all described with the help of this language. It is specific to a particular domain of programming and all these are described from the perspective of a user. Hence, easy collaboration can be done by non-programmers too and can be easily read.

Differentiate between TDD and BDD.

The following are the main differences between the Behavior Driven Development and Test Drive Development:

Point of distinction BDD TDD
Development process is centred on Behavior is centred around Test
Written using Gherkin Language and programming language Programming Languages like Ruby or Java
Readbility Readable by both programmer and non-programmer. Both can work on same project Only programmer can work on TDD project

What Is BDD Framework. What are the benefits 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.

What Is Step Definition In Cucumber?

A step definition is the actual code implementation of the step mentioned inside scenario in feature file. A step definition is mentioned inside step definition file. This code can be written in any Cucumber supported language like Java, Ruby etc.

Consider a step: When I fill in "textbox" with "xyz"

Step Definition in Java

@When("^I fill in \"([^\"]*)\" with:$")
public void i_fill_in_with(String elementName, String messageText) 
{
	driver.findElement(By.id("message")).sendKeys(messageText);
}

Give An Example Of Behaviour Driven Test In Plain Text?

Below is the example:

Feature: Verify Login functionality

Scenario : Verify User Login
Given: I am on the homepage
When: I click on "Sign in"
Then: I should see "Login" page
When I fill in "username" with "xyz"
And I fill in "password" with "123"
Then I should see "Welcome..."

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. Example:

$ cucumber features/test.feature:21

Here features is the folder and test.feature is feature file and 21 is the line number.

Subscribe to Cucumber with Java Interview Questions