Ruby 硒黄瓜杂烩(红宝石)

Ruby 硒黄瓜杂烩(红宝石),ruby,selenium-webdriver,cucumber,Ruby,Selenium Webdriver,Cucumber,我正在编写一些测试功能,我从一个表开始,然后我更改了表中的数据并获得了一个副本,并希望从散列开始填充表单,下面是我的代码: Given /^I start with this table$/ do |table| @hashes = [] table.hashes.each do |hash| Faker::Config.locale = 'en-US' hash['fname'] = "Joe" hash['lname'] = "Doe" @hashes &

我正在编写一些测试功能,我从一个表开始,然后我更改了表中的数据并获得了一个副本,并希望从散列开始填充表单,下面是我的代码:

 Given /^I start with this table$/ do |table|
  @hashes = []
  table.hashes.each do |hash|
  Faker::Config.locale = 'en-US'
    hash['fname'] = "Joe"
  hash['lname'] = "Doe"

    @hashes << hash
  end
end
Given/^I从这个表开始$/do |表|
@散列=[]
table.hashes.each do| hash|
Faker::Config.locale='en US'
散列['fname']=“Joe”
哈希['lname']=“Doe”

@散列如果将问题的原因缩小到一个最小的完整且可验证的示例,则更容易找到问题的原因

问题在于您正在定义:

@hashes = [
  # ...
  { 
    # ...
    'fname' => "Joe",
    # ...
  },
  # ...
]
然后尝试通过以下方式访问值
“Joe”

@hashes['fname']
这不起作用,因为
@hashes
实际上是一个数组。错误消息:

no implicit conversion of String into Integer (TypeError) 
表示只能通过数组元素的
Integer
索引查找数组元素

有多种方法可以解决此问题,例如显式使用列表中用户属性的第一个哈希。(我还建议使用比
@hashes
更具描述性的变量名,但这是另一个问题!)

然后/^I可以从转换的数据中填充全名$/do
@hash.each do| hash|
放入散列
结束
fname=$driver.find_元素(:id,“申请人的名字”)

fname.send_keys(@hashes.first['fname'])#如果将问题的原因缩小到一个最小的、完整的、可验证的示例,则更容易找到问题的原因

问题在于您正在定义:

@hashes = [
  # ...
  { 
    # ...
    'fname' => "Joe",
    # ...
  },
  # ...
]
然后尝试通过以下方式访问值
“Joe”

@hashes['fname']
这不起作用,因为
@hashes
实际上是一个数组。错误消息:

no implicit conversion of String into Integer (TypeError) 
表示只能通过数组元素的
Integer
索引查找数组元素

有多种方法可以解决此问题,例如显式使用列表中用户属性的第一个哈希。(我还建议使用比
@hashes
更具描述性的变量名,但这是另一个问题!)

然后/^I可以从转换的数据中填充全名$/do
@hash.each do| hash|
放入散列
结束
fname=$driver.find_元素(:id,“申请人的名字”)

fname.send_key(@hashes.first['fname'])#请共享行
custom\u步骤。rb:55
brc\u epic03\u emp\u bulk\u pp。功能:23
行55在代码中,我把请共享行
custom\u步骤。rb:55
brc\u epic03\u emp\u bulk\u pp。功能:23
行55在代码中,我把