Site icon TestingDocs.com

Filter Stories in JBehave

Overview

In this post, we will learn how to filter stories or scenarios during automation dry runs. In real projects, you have many stories under the project folder. It’s important to keep the stories well organized by grouping the scenarios.

When you execute the stories, you have several ways to filter the stories. The most common way to
filter stories are to use the meta filter.

Example

Let’s say your project has hundreds of stories. Consider the fact that you have automated a scenario or story in the project. You may want to quickly run the scenario and verify your automation effort and exclude all the other stories to be executed in the project.

Filtering Stories

Add the meta filter in the story or scenario.

Meta:
@dryrun

For example story we have to run and exclude all other stories in the project.
————

Lookup a definition
Narrative:
In order to do Mathematics better
As a Maths student
I want to look up math word definitions

Meta:
@dryrun

Scenario: Looking up the definition of ‘cosine’
Given the user is on the Wikionary home page
When the user looks up the definition of the word ‘cosine’
Then they should see the definition ‘In a right triangle, the ratio of the length of the side adjacent to an acute angle to the length of the hypotenuse.’

———-

@dryrun is a sample filter. You can pick any filter of your choice. It makes sense to use meaningful words if you are grouping stories. For example, @billing for all billing related stories and scenarios.

Now, add the filter to the run configuration in Eclipse to run the story.

Right click >> Run as >> Run Configuration >> Maven build

Filter Stories

Add the goals to filter:

verify -Dmetafilter=”+dryrun”

Click on Run.

 

View or verify the report for the story.

 

Command line:

/> mvn clean verify -Dmetafilter=”+dryrun”

In this approach you save a lot of time verifying your automation results especially when you are automating new stories and scenarios. In this use case you are not interested about the other stories in the project. The main focus is your newly added automation story verification.

More Info:

https://jbehave.org/reference/latest/meta-filtering.html

 

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