How to selectively run, in jBehave, stories tagged with multiple words in a meta field.

Prerequisites:
1) a working jBehave based project
This short tutorial is based on an jbehave-tutorial project available on github: https://github.com/jbehave/jbehave-tutorial.
To be precise I used the “java-spring” submodule from the “etsy-selenium” module, available here: https://github.com/jbehave/jbehave-tutorial/tree/master/etsy-selenium/java-spring, to run the modified story presented below.
2) Maven

OK, let’s consider a situation when we have stories belonging to multiple features, categories etc.
Below is an example story, tagged with multiple categories and features:

anExampleStoryWithMultipleWordsInAMetaKeyword.story

Meta:
@categories category1 category2 category3
@features feature1 feature2 feature3 feature_4

Scenario: scenario description
Given I'm on the homepage
....

Now, we’d like to run stories only for a selected category or a feature.
To accomplish this we’ll use the value pattern matching mechanism implemented in the jBehave meta matcher and described here.

Examples:
Run stories covering only category3:

mvn clean install -Dmeta.filter="+categories *category3*"

Run stories covering only feature_4:

mvn clean install -Dmeta.filter="+features *feature_4*"

And finally, run stories matching feature2 and category1:

mvn clean install -Dmeta.filter="+features *feature2* +categories *category1*"

Notice:
It seems that jBehave is not handling “-” hyphens in the keyword value properly, but it works fine with “_” underscores, separate words and camelCase notation 🙂

4 thoughts on “How to selectively run, in jBehave, stories tagged with multiple words in a meta field.

  1. Thanks for this tutorial,
    If I have a case as below:

    story1.story
    Meta:
    @categories category1 category2 category3
    scenario: 1
    scenario: 2

    story2.story
    Meta:
    @categories category5 category6
    scenario: 1
    scenario: 2

    what should be the metafilter parameter if i want to run category1, and category5
    e.g. -Dmeta.filter=”+categories *category1*,*category5*” does not work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s