Search code examples
javaspringbddjbehave

how to use Example table (Parametrised Scenarios) with normal "Given" statement


when I am trying to run below story file, statement "a stock of" executing two time but I want that this execution should happen only once and statement "reference data databasetable record with sds id = and swift bic = " should execute twice.

Scenario: Parametrised Scenarios Test

Given scenario parameter - swiftBic = JBEHAVEXXX
Given scenario parameter - receiverBic = JBEHAVEYYY
Given scenario parameter - extSdsId = 1111
Given scenario parameter - sdsId = 22222

Given reference data databasetable record <alias> with sds id = <sId> and swift bic = <bic>
Given a stock of.

Examples:
|alias  |sId            |bic            |
|DEF    |${sdsId}       |${swiftBic}    |
|DEFF   |${extSdsId}    |${receiverBic} |

Solution

  • In cucumber using Examples is a shortcut for writing the same scenario twice with different data. So you code above is equivilent to:

    Scenario: test with fisrt set of data 
        Given reference data databasetable record DEF with sds id = 2222 and swift bic = JBEHAVEXXX
        Given a stock of.
    
    Scenario: test with second set of data 
        Given reference data databasetable record DEF with sds id = 1111 and swift bic = JBEHAVYYY
        Given a stock of.
    

    so if you only want the Given a stock of. step to execute once you cannot use the Example shortcut and will have to have two separate scenarios with explicit steps.