黄瓜选择多个复选框

时间:2011-11-16 13:35:08

标签: ruby-on-rails-3 cucumber

我正在使用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 个答案:

答案 0 :(得分:0)

据我了解,选择复选框并与UI交互不是Cucumber的工作。 Cucumber解析要素文件并执行匹配的相应步骤定义。您在每个步骤定义块中放置的内容取决于您。

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