2016-08-19 98 views
0

這一步在我的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: "(.*?)", "(.*?)", "(.*?)":$/' 

我做了什麼錯,怎麼解決?

對於信息 - 我得到同樣的錯誤消息,如果parenthases被取出步驟定義的:

When /^I search with the following details: "(.*?)", "(.*?)", "(.*?)":$/ do |recordReference, secondIdentifier, postcode| 

回答

1

第四個參數是數據表。刪除前三個參數並放入DataTable選項,您將從DataTable中獲取所有數據。建議您使用dryRun = true選項讓Cucumber創建適當的步驟定義匹配器,這是從我的Java知識中不知道這個dryRun選項是如何在ruby中。 另外,你將不得不改變你的步伐在特徵文件與傳遞數據表的步驟

從你的表的格式刪除提到的3個參數

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任何理由 - 我相信每一個驅動程序支持正常的水豚send_keys API,因此這純粹是find(:css, '#dln').send_keys recordReference(或當然只是fill_in('dln', with: recordReference)