Book Image

Cucumber Cookbook

By : Shankar Garg
Book Image

Cucumber Cookbook

By: Shankar Garg

Overview of this book

Table of Contents (13 chapters)
Cucumber Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Identifying Duplicate and Ambiguous Step Definitions


Sometimes when we are writing Cucumber Step Definitions files, we get either Duplicate Step Definitions errors or Ambiguous Step Definitions errors. Let's try and understand the reasons why these errors arise, and how we can remove them through this recipe.

How to do it…

We will use the same Feature file from previous recipe. Perform the following Steps:

  1. Let's create one more class in the StepDefinitions package, called DuplicateAmbiguous.java, with the following content:

    package com.StepDefinitions;
    
    import cucumber.api.java.en.Given;
    
    public class DuplicateAmbiguous {
      
      //Duplicate Steps
      @Given("^user is on Application landing page$")
      public void user_is_on_Application_landing_page_duplicate() throws Throwable {
        //sample code goes here
        System.out.println("Duplicate");
      }
    
    }

    When you try to run the Feature file, observe the Cucumber output:

    Exception in thread "main" cucumber.runtime.DuplicateStepDefinitionException: Duplicate...