2011-11-16 86 views
1

我正在使用Cucumber 1.1.1开发Rails 3应用程序,并试图在我的黄瓜场景中选择多个复选框。黄瓜选择多个复选框

这是我在HAML多个复选框:

- for diocese in Diocese.all 
    = check_box_tag "clergy[diocese_ids][]", diocese.id, @clergy.dioceses.include?(diocese) 
    = f.label diocese.name 
    %br 

这是我的黄瓜步

When /^I check the (\d+)(st|nd|rd|th) of the "([^"]*)" checkboxes$/ do |index, junk, group| 
    page.all("input[id=\"clergy_diocese_ids_\"]")[index.to_i - 1].check('clergy_diocese_ids_') 
end 

这里是我的黄瓜测试:

@wip 
    Scenario: New Clergy 
    Given I am on the clergies page 
    When I follow "New Clergy" 
    And I fill in "Surname" with "Wells" 
    And I fill in "Given names" with "Robin" 
    And I check the 1st of the "diocese" checkboxes 
    And I check the 2nd of the "diocese" checkboxes 
    And I press "Create Clergy" 
    Then I should see "Clergy was successfully created." 

我得到的错误运行时我的测试:

And I check the 1st of the "diocese" checkboxes         # fea 
tures/step_definitions/clergy_steps.rb:37             
     cannot check field, no checkbox with id, name, or label 'clergy_diocese_ids_' found (C 
apybara::ElementNotFound)                 
     ./features/step_definitions/clergy_steps.rb:38:in `/^I check the (\d+)(st|nd|rd|th) of 
the "([^"]*)" checkboxes$/'                
     features/clergy_new.feature:17:in `And I check the 1st of the "diocese" checkboxes' 

我试着玩了page.all选择器,但我无法解决它。

+1

您是否检查了呈现的页面输出以检查复选框上的id属性的格式? –

+0

是的,我用firefox下firebug来检查我的复选框的ID。 – map7

+0

从你的黄瓜步骤的外观看,你的测试看起来像所有的复选框共享相同的ID。你是否需要使用字符串插值来为需要选择的复选框形成正确的ID? –

回答

0

据我所知,它不是Cucumber的工作来选择复选框并与UI交互。黄瓜分析功能文件并执行匹配的相应步骤定义。您在每个步骤定义块中放置的内容取决于您。

由于您的步骤定义代码似乎使用水豚,我建议查看this solution