Site icon TestingDocs.com

JBehave Ambiguous Steps

In this post, we will discuss JBehave Ambiguous Steps.

What is an Ambiguous Step?

If the gherkin matches more than one matching steps, then it is called an Ambiguous Step. An ambiguous step matches multiple methods in step classes. Also, this often happens in large projects while writing a number of stories. However, the story editor, for example, eclipse plugin editor, warns you about ambiguous steps if the steps are statically defined. Furthermore, ambiguous steps lead to undesirable execution if we don’t prioritize them or define a prioritizing strategy.

Example:

We will see some simple examples below to clarify things. Lets us take a simple gherkin text below which matches 2 matching steps:
Given bing search homepage

We have made the above Gherkin text to match 2 steps as shown in the below picture. Two step candidates have been provided i.e two different implementations in step classes for the same gherkin textual step. We may need to resolve this ambiguity either by resolving the ambiguity or setting priority to steps.

 

The warning is shown by the story editor:

Ambiguous step: 2 steps are matching <Given bing search homepage > got: [[GIVEN]bing search homepage, BingSteps#openBing, [GIVEN]bing search homepage, CommonSteps#openBing]

bing search homepage (com.testingdocs.stock.steps.BingSteps.java#openBing)
bing search homepage (com.testingdocs.stock.steps.CommonSteps.java#openBing)

Matching methods as shown below:

step method 1 in BingSteps


@Given("bing search homepage")
    public void openBing()
    {
        //    This is in BingSteps.class
        System.out.println(this.getClass()+ "step method invoked");
   
    }

 

step method 2 in CommonSteps

@Given("bing search homepage")
    public void openBing()
    {

       //This is in CommonSteps.class
        System.out.println(this.getClass()+ "step method invoked");
   
    }

 

JBehave AmbigiousSteps

 

 

JBehave Tutorials on this website can be found at:
https://www.testingdocs.com/jbehave-framework-tutorial/

For more details on the JBehave framework, visit the official JBehave website at:
http://jbehave.org

Exit mobile version