Skip to content
MM

Medzida Mustafic

1 article

April 9, 2020

BDD Test Automation with Cucumber-JVM

QA/Test Automation

BDD Test Automation with Cucumber-JVM

Writing the scenario Cucumber is a popular BDD test automation tool. Cucumber-JVM is the Java implementation of Cucumber. In Cucumber, you express acceptance criteria in a natural, human-readable form. In Cucumber, scenarios are stored in Feature Files, which contains an overall description of a feature as well as a number of scenarios. For example there is feature file called search_by_keyword.feature, and looks something like this: Feature: Searching by keyword In order to find items that I would like to purchase As a potential buyer I want to be able to search for items containing certain words Scenario: Should list items related to a specified keyword Given I want to buy a wool scarf When I search for items containing 'wool' Then I should only see items related to ‘wool’ Step definitions In Cucumber, each line of the Gherkin scenario maps to a method in a Java class, known as a Step Definition. These use annotations like @Given, @Whenand @Then, that match lines in the scenario to Java methods. You define simple expressions to indicate parameters that will be passed into the methods: public class SearchByKeywordStepDefinitions { @Steps BuyerSteps buyer; @Given("I want to buy (.*)") public void buyerWantsToBuy(String article) { buyer.opens_etsy_home_page(); } @When("I search for items containing '(.*)'") public void searchByKeyword(String keyword) { buyer.searches_for_items_containing(keyword); } @Then("I should only see items related to '(.*)'") public void resultsForACategoryAndKeywordInARegion(String keyword) { buyer.should_see_items_related_to(keyword); } } "BDD Test Automation with Cucumber-JVM" Tech Bite was brought to you by Medžida Mustafić, Junior Test Engineer at Atlantbh.  (more…)

Ready to Achieve More?

We’ll help you reach your goals quickly with an easy and straightforward process to kick off our collaboration. Here’s what happens next.

STEP 1

Discovery Call

Let’s chat to understand your company, project needs, and answer any questions along the way.

STEP 2

Free Consultation

Work closely with our experts to explore the right solutions for your business.

STEP 3

Collaboration Proposal

We'll recommend the best strategy for your goals, ensuring you get the most from our expertise.

STEP 4

30-Day Cancellation
Policy Contract

Spoiler: It’s Never Been Used

Enjoy peace of mind while we deliver excellence from day one—our track record speaks for itself.

Services you're interested in (Optional)