Jbehave boolean named parameter
-
15-04-2021 - |
Question
In the jbehave 3 examples I can see parameters as "double", so I tried to use other types besides string, but when I try to add a boolean parameter like this
public void theUserShouldBeRedirectedToHomePage(@Named("should?") boolean should)
I get an argument type error:
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jbehave.scenario.steps.CandidateStep$1.perform(CandidateStep.java:225)
at org.jbehave.scenario.ScenarioRunner$FineSoFar.run(ScenarioRunner.java:112)
(also, I'm using version 2.3, not 3 of jbehave)
Is it a problem with my jbehave version? which is the right way to use a boolean parameter?
Solution
I try this too. There is no default ParameterConverter for boolean/Boolean. You can easily add one.
http://jbehave.org/reference/stable/parameter-converters.html
OTHER TIPS
If you will pass this parameter to other method anyways, sometimes is easier to do like this:
public void theUserShouldBeRedirectedToHomePage(@Named("should?") String should){
myNextMethod(Boolean.valueOf(should)); }
Jbehave version 3 works well with Boolean. Take the following example it works perfectly fine in my code.
@Then("I verify the response has _success as $_success and _warning as $_warning and _info as $_info and _messages as $_messages")
public void pidOrPidColorDeleteResponse(
@Named("_success") Boolean _success,
@Named("_warning") Boolean _warning,
@Named("_info") Boolean _info,
@Named("_messages") List<String> _messages) {
}
With Jbehave Version 2 need to check.