JBehave Ambiguous Steps
JBehave Ambiguous Steps
In this post, we will discuss JBehave Ambiguous Steps. If the gherkin matches more than one matching step, then it is called an Ambiguous Step. An ambiguous step matches multiple methods in step classes. This often happens in large projects while writing a number of stories. However, the story editor, for example, the Eclipse plugin editor, warns you about ambiguous steps if the steps are statically defined. This may 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. Let 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 story editor shows the warning:
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 Tutorial
JBehave Tutorials on this website can be found at:
For more details on the JBehave framework, visit the official JBehave website at: