-4

I want to know how to implement data tables in cucumber ruby ? need an example to use both data tables and examples together from a feature file.

please provide an example feature with these and their implementation files.

arbaz khan
  • 15
  • 1
  • 5
  • Welcome to SO. Please read and consider http://meta.stackoverflow.com/q/261592/128421. Where have you searched and why didn't those help? SO isn't a "please write documentation for me" site. We expect you to try things and then when that doesn't work show us what you tried and explain why it doesn't do what you need. See "[ask]" including the links at the bottom. – the Tin Man Feb 29 '16 at 21:13

1 Answers1

6

With a scenario like this

Scenario Outline:
  Given I have a username and password and a boolean
    |username | password | boolean    |
    | myname  | mysecret | <boolean>  |
  Then I print them out

  Examples:
    | boolean |
    | true    |
    | false   |

You would use step defs like this:

Given(/^I have a username and password and a boolean$/) do | table |
  @data = table.hashes
end

Then(/^I print them out$/) do
  @data.each { |_k, v| puts v }
  # or
  data_for_row_one_of_table = @data[0]
  username = data_for_row_one_of_table['username']
  # Do something with username here
  ...
end

Does that answer your question?

alannichols
  • 1,496
  • 1
  • 10
  • 20
  • Thanks, do tables also come under scenario outline? i thought they are different from examples? – Emjey Apr 20 '17 at 13:17
  • 1
    They are different things but can be used together. Tables are just a nice way of writing out scenarios that have a lot of data. Tables can be used in Scenarios or in Scenario Outlines. Scenario Outlines (and therefore Examples) are a way of rerunning a Scenario multiple times with different variables. – alannichols Apr 21 '17 at 11:27