我的Ruby功能文件中的这一步,用于查找和访问客户记录:
When I search with the following details: "<recordReference>", "<secondIdentifier>", "<postcode>":
| recordReference | secondIdentifier| postcode |
| REFABCDE12345678| IDcode1234 | PC11 1PC |
它有这个步骤定义:
When(/^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/) do |recordReference, secondIdentifier, postcode|
find(:css, "#dln").native.send_keys recordReference
find(:css, "#nino").native.send_keys secondIdentifier
find(:css, "#postcode").native.send_keys postcode
check 'confirmation'
click_button 'submit'
end
当它运行时,我收到以下错误:
Cucumber::ArityMismatchError: Your block takes 3 arguments, but the Regexp matched 4 arguments.
features/step_definitions/refactored_commands.rb:207:in `/^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/'
我做错了什么以及如何解决?
有关信息 - 如果从步骤定义中取出了父对象,我会收到相同的错误消息:
When /^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/ do |recordReference, secondIdentifier, postcode|
答案 0 :(得分:1)
第四个参数是DataTable。删除前3个参数并只输入DataTable选项,您将获得DataTable中的所有数据。建议你使用dryRun = true选项让Cucumber创建正确的步骤定义匹配器,这是我的Java知识,不知道这个dryRun选项是如何在ruby中的。 此外,您必须更改要素文件中的步骤以删除上述3个参数
答案 1 :(得分:0)
看起来你正在将场景大纲与传递数据表混合到步骤
从你的表格式来看,你的目标实际上应该是
Scenario Outline: xxx
...
When I search with the following details: "<recordReference>", "<secondIdentifier>", "<postcode>"
...
Examples:
| recordReference | secondIdentifier| postcode |
| REFABCDE12345678| IDcode1234 | PC11 1PC |
然后每个示例的每一行都会调用一次,并填入值 - 所以你的步骤将是
When(/^I search with the following details: "(.*?)", "(.*?)", "(.*?)"$/) do |recordReference, secondIdentifier, postcode|
...
end
侧面说明 - 您是否有任何理由致电.native.send_keys
- 我相信每个驱动程序现在都支持普通的Capybara send_keys API,因此它只是find(:css, '#dln').send_keys recordReference
(当然只有{{} 1}})