Pass Array value in cucumber .feature file

11,745

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 }

Share:
11,745
Shobhit Gupta
Author by

Shobhit Gupta

Updated on June 08, 2022

Comments

  • Shobhit Gupta
    Shobhit Gupta almost 2 years

    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?