Filtering with multiple metafilters in JBehave

2019-04-15 07:46发布

Situation:

In my current project we are running all kinds of different JBehave stories. Every ".story" file is related to a product and a flow.

Example:
xyz-cellphone-call.story would be the story describing making a phonecall with a cellphone.
xyz-phone-call.story would be the story describing making a phonecall with a fixed-line phone.
xyz-cellphone-browse.story would be the story describing browsing the internet with a cellphone.

My question: In Jbehave you can add metaFilters to filter on the stories based on meta tags. Assume the tags are @product & @action. (@product cellphone, @action call).
Would it be possible to pass a filter to run the JBehave stories concerning both the phone & cellphone stories, if yes, what would be the syntax?

I've tried adding the following filters (none of which work):

+product cellphone +product phone
+product cellphone|phone
+product cellphone,phone

Same for actions.

Is it possible to filter on multiple meta-tags?

3条回答
家丑人穷心不美
2楼-- · 2019-04-15 07:54

I guess there is easier solution for you using groovy http://jbehave.org/reference/stable/meta-filtering.html

In your case it would be -Dmetafilter="groovy: "product=='cellphone' && action=='call'"

I tried it as "-Dmetafilter=groovy:t2 && t3" for this feature file

Meta:
    @t1

Narrative:
    As a user
    I want to blah-blah-blah


Scenario: test 1
Meta:
    @t2

Given I am on home page


Scenario: test 2
Meta:
    @t2
    @t3

Given I am on home page


Scenario: test 3
Meta:
    @t3

Given I am on home page

Only test 2 scenario is executed in this case

查看更多
爷的心禁止访问
3楼-- · 2019-04-15 08:10

How about:

mvn clean install -P -Djbehave.meta.filter = "+product cellphone&&phone"
查看更多
手持菜刀,她持情操
4楼-- · 2019-04-15 08:15

Yes it is possible. In the API docs you will find this information:

A filter is uniquely identified by its String representation which is parsed and matched by the MetaFilter.MetaMatcher to determine if the Meta is allowed or not.

The MetaFilter.DefaultMetaMatcher interprets the filter as a sequence of any name-value properties (separated by a space), prefixed by "+" for inclusion and "-" for exclusion. E.g.:

MetaFilter filter = new MetaFilter("+author Mauro -theme smoke testing +map *API -skip"); filter.allow(new Meta(asList("map someAPI")));

The use of the MetaFilter.GroovyMetaMatcher is triggered by the prefix "groovy:" and allows the filter to be interpreted as a Groovy expression.

MetaFilter filter = new MetaFilter("groovy: (a == '11' | a == '22') && b == '33'");

So probably if you play with the conditions, you will get your run configuration customized. Try this example:

mvn clean install -P -Djbehave.meta.filter="myCustomRunConf:(+product && +action)"

More info amout the MetaFilter class in the API docs: http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/embedder/MetaFilter.html

查看更多
登录 后发表回答