Search code examples
jbehavethucydides

How to filter jbehave examples table rows based on scenario meta data


Is there a way we can filter jbehave examples table rows at runtime using the scenario meta data? For e.g

Scenario: my scenario title Meta:

@id 1

Examples:

|Meta:|col1|col2|
|id 1 |val1|val2|
|id 2| val |val |
|id 1| val |val |

When we run this scenario it should iterate only for the 1st and 3rd row, based on the meta data set on the scenario. What I am trying to do is to externalize data across scenarios/ stories and try to use filtered data rows applicable for particular scenario.

I found some similar topics based meta filtering but not specific to this.

Appreciate any help. Thanks


Solution

  • A meta character @ must be used in the example table, in this way:

    Scenario: some scenario
    
    Meta:  @id
    
    Given I pass value '1'
    
    Examples: 
    |Meta:|col1|col2|
    |@id 1|val1|val2|
    |@id 2| val|val |
    |@id 1| val|val |
    

    Then you need to define the filter in the configuration, for example:

     configuredEmbedder().useMetaFilters(Arrays.asList("+id 1"));
    

    More on this topic can be found here: http://jbehave.org/reference/stable/meta-filtering.html