Pass Array value in cucumber .feature file

Shobhit Gupta picture Shobhit Gupta · Jun 14, 2016 · Viewed 9k times · Source

I want to pass array value as a parameter from cucumber .feature file, so I can access it from step definition file:

I am using this format:

Examples:
|r1|t1|
|abc|[aa,bb,cc]| 

But I'm getting an error undefined methodeach' for "[aa,bb,cc]":String (NoMethodError)`

Is it possible to pass array from .feature file?

Answer

Dave McNulla picture Dave McNulla · Jun 15, 2016

I don't think you need the square brackets.

When I pass this array "aa,bb,cc"

You have to split your string up.

When(/I pass this array "([^"]*)"$/) do |array|
  array.split(',').each{|entry| do something }
end

Note: you may want to strip the entries in case there is whitespace around them {|entry| puts entry.strip }