2011-11-16 87 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