cucumber jvm varargs support in step definition

540 views
Skip to first unread message

Mrunal Gosar

unread,
Mar 7, 2015, 6:31:26 PM3/7/15
to cu...@googlegroups.com

How to use power of varargs while defining step definitions in cucumber java bindings. I have below step

Given I have following product: prod1, prod2, prod3

Here product list can be variable.

My Step definition

@Given("^I have following product [(exhaustive list of products or pattern of the product names)]$")
public void stepDef(String...args)
{
//Process varargs array "args" in here
}

I know workaround can be to except the complete string after colon and then in the code break the string using split(",") and dump it into array. But i just want to know if cucumber on its own supports varargs pattern.

TIA!!!

aslak hellesoy

unread,
Mar 7, 2015, 7:19:36 PM3/7/15
to Cucumber Users
On Sat, Mar 7, 2015 at 5:33 PM, Mrunal Gosar <predator.t...@gmail.com> wrote:

How to use power of varargs while defining step definitions in cucumber java bindings. I have below step

Given I have following product: prod1, prod2, prod3

I recommend using a data table instead:

Given I have the following products:
  | prod1 |
  | prod1 |
  | prod1 |

Then in your stepdef:

@Given("I have the following products:")
void stepdef(List<String> products) {

 Here product list can be variable.

My Step definition

@Given("^I have following product [(exhaustive list of products or pattern of the product names)]$")
public void stepDef(String...args)
{
//Process varargs array "args" in here
}

I know workaround can be to except the complete string after colon and then in the code break the string using split(",") and dump it into array. But i just want to know if cucumber on its own supports varargs pattern.

It doesn't support varargs. If you don't like the table approach above you can still create a list:

@Given("I have the following products: (.*)")
void stepdef(List<String> products) {


Aslak 

TIA!!!

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mrunal Gosar

unread,
Mar 8, 2015, 10:54:56 AM3/8/15
to cu...@googlegroups.com
Hi Aslak
Thanks for replying. I had my eyes on the solution which you had suggested, but just wanted to get confirmed whether i've missed this feature in cucumber-JVM (if it already exists).
i read your post that varargs implementation is there in ruby bindings, so just thought to lookup if it is there in java bindings.

Thanks
Mrunal

Aslak Hellesøy

unread,
Mar 8, 2015, 11:57:23 AM3/8/15
to cu...@googlegroups.com
I confirm there is no varargs support for Java stepdefs.
Thanks
Mrunal
Reply all
Reply to author
Forward
0 new messages