Just double checking, there isn't a way to accept an arbitrary number of accepted values in a @Then definiton, right? #2217
Unanswered
AndrasBallai-ITNatives
asked this question in
Q&A Java
Replies: 2 comments
-
You could use either an examples table or a data table to pass in something more concrete dynamic and then parse that? |
Beta Was this translation helpful? Give feedback.
0 replies
-
There are many ways to write a list of strings. So Cucumber won't guess. You can define a parameter type for your list of strings: @ParameterType("(?:[^,]*)(?:,\\s?[^,]*)*")
public List<String> listOfStrings(String arg){
return Arrays.asList(arg.split(",\\s?"));
} Then you can use this parameter type in a step definition with a Cucumber Expression: @Given("a list of strings \"{listOfStrings}\"")
public void a_list_of_strings_cucumber_expression(List<String> list) {
System.out.println(list);
} But the nice way would be to use a table:
And then Given("a list of things")
public void a_list_of_things(List<String> things) {
...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm very new to Cucumber, Gherkin and BDD/integration testing in general. As a java developer I'm always looking to increase reusability and strive for generalisation, from what I've seen, this clashes with Cucumber's, and in general, BDD's design philosophy, which is fine, I just wanted to explain my background a bit.
Is there a way for a general
@Then
definition?What I'd like to achieve is something like this
But in a way, where the string in the
@Then
is dynamic, accepting any number of supplied strings. Is this achievable with Cucumber/Gherkin, or, even if it is, I should not persue it and focus on concrete cases?Beta Was this translation helpful? Give feedback.
All reactions