Question

I have my test cases with some duplicate steps

Given user 123456 with amount USD50
When charge request made by User
Then Charge request should be success

When refund request made by user for USD50
Then Refund request should be success

When refund request made by user for USD50
Then Refund request should be fail

I was expecting to use tabular parameters as explained in http://jbehave.org/reference/stable/parametrised-scenarios.html.

But instead of splitting test in to two scenarios I wanted to keep it as one scenario

Finally it should look similar to the below. Ex:

Given user <user> with amount <charge>
When charge request made by the user
Then Charge request should be success

When refund request made by user for <refund>
Then Refund request should be <result>

When refund request made by user for <refund>
Then Refund request should be <result>
Examples:
|user|charge|refund|result|refund|result|
|123456|USD50|USD50|success|USD50|fail|
|123456|USD50|USD20|success|USD10|fail|

But when executed the result page shows the parameter table as

user        charge  refund  result  refund  result
postpaid    USD50   USD50   fail    USD50   fail
postpaid    USD50   USD10   fail    USD10   fail

It seems the fields are assigned in to the last value.

I can not name the fileds in two different names ( ex: refund1, refund2) as the method is written with named parameters

@When("refund request made by user for $refund)
@Alias("refund request made by user for <refund>")
public void refundRequest(@Named("refund") String refund){

    //refund code

}

Please Help

Was it helpful?

Solution

For achieving that you need to change the parameter controls to use delimiter named parameters as follow:

 public ParametrisationByDelimitedName() {
        useConfiguration(new MostUsefulConfiguration()
                .useParameterControls(new ParameterControls().useDelimiterNamedParameters(true))
                .useStoryReporterBuilder(
                        new StoryReporterBuilder().withFormats(Format.CONSOLE)));
    }

See the following links for the full example:

https://github.com/jbehave/jbehave-core/blob/master/examples/core/src/main/java/org/jbehave/examples/core/stories/parametrisation_by_delimited_name.story

https://github.com/jbehave/jbehave-core/blob/master/examples/core/src/main/java/org/jbehave/examples/core/stories/ParametrisationByDelimitedName.java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top