ruby - cucumber 从 3 列表中读取数据?

标签 ruby automation selenium-webdriver cucumber bdd

我正在尝试从 Cucumber 中的三列内联数据表中读取数据。

特征文件:

Then  I should see grades,exteriors, interiors and engines available:
  |grades            |exteriors         |  engine |
  |xdata-id-Elegance |xdata-id-NH-788p  |  12345  |
  |                  |xdata-id-NH737M   |         |
  |                  |xdata-id-NH731P   |         |
  |                  |xdata-id-R-539P   |         |

步骤定义:

 Then(/^I should see grades,exteriors, interiors and engines available:$/) do |table|
      data = table.rows_hash
      puts data['exteriors']
    end

这给我的错误只允许 2 行。

有谁知道我可以访问的另一种方式,所有三列都使用表对象?

最佳答案

以更简单的方式为我工作,三列数据表如下:

  Scenario: I am able to select a date range

    Given I am on the rejections tracker page as a superuser
    Then the date range filters work as expected
      | dateFrom   | dateTo     | variance    |
      | 12/05/2014 | null       | lesser than |
      | null       | 12/07/2014 | lesser than |
      | null       | null       | equal to    |

这对我有用:

    Then(/^the date range filters work as expected$/) do |table|

      data = table.hashes
      date_from = []
      date_to = []
      variance = []

      data.each do |row|
        row.each do |key, value|
          if key.eql? "dateFrom"
            date_from << value
          elsif key.eql? "dateTo"
            date_to << value
          elsif key.eql? "variance"
            variance << value
          end
        end
      end

      puts date_from
      puts date_to
      puts variance
   end

输出:

  ["12/05/2014", "null", "null"]
  ["null", "12/07/2014", "null"]
  ["lesser than", "lesser than", "equal to"]

关于ruby - cucumber 从 3 列表中读取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19909912/

相关文章:

java - Selenium WebDriver : Wait for complex page with JavaScript to load

selenium - 如何通过Selenium打开Firefox Developer Edition

ruby - 如何在 Curses 中获取 Shift+X/Alt+X 键?

java - 如何在通用方法中添加等待点击功能?

ruby-on-rails - 在 Rails 中使用 XML 发出 SOAP 请求

selenium - driver.quit() 不会关闭浏览器窗口

linux - 如果服务器重新启动,如何使 couchbase 服务自动启动?

triggers - 邮件黑猩猩 : Automation Workflow does not trigger

ruby - 使用 https 连接到具有由我创建的 CA 签名的证书的服务器

ruby - 如何使用 Sinatra、Datamapper、DM-Paperclip 和 S3?