如何在 Cucumber ruby 中实现数据表,我需要一个示例来同时使用特征文件中的数据表和示例

how to implement data tables in cucumber ruby ,i need an example to use both data tables and examples together from a feature file

我想知道如何在 Cucumber 中实现数据表 ruby? 需要一个示例来同时使用特征文件中的数据表和示例。

请提供这些及其实现文件的示例功能。

像这样的场景

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   |

您可以像这样使用步骤定义:

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

这是否回答了您的问题?