2013-02-19 9 views
9

私は、サインアップウィザードを作成するために考案使っ が、カピバラ(2.0.2)が工夫/カピバラあいまい一致

Feature: Signing up 
    In order to be attributed for my work 
    As a user 
    I want to be able to sign u 

Scenario: Signing up 
    Given I am on the homepage 
    When I follow "Sign up" 
    And I fill in "Email" with "[email protected]" 
    And I fill in "Password" with "password" 
    Ambiguous match, found 2 elements matching field "Password" (Capybara::Ambiguous) 
./features/step_definitions/web_steps.rb:10:in `/^(?:|I)fill in "([^"]*)" with "([^"]*)"$/' 
features/signing_up.feature:10:in `And I fill in "Password" with "password"' 
    And I fill in "Password confirmation" with "password" 
    And I press "Sign up" 
    Then I should see "You have signed up successfully." 

ステップ定義は、バージョン2.0カピバラさんで

When /^(?:|I)fill in "([^"]*)" with "([^"]*)"$/ do |field, value| 
    fill_in(field, :with => value) 
end 

答えて

8

あるを提起していますfindメソッドは、見つかった特定のロケータに一致するいくつかの要素がある場合には、Capybara::Ambiguous例外を発生させます。カピバラはあいまいな選択をしたくない。

適切な解決策は、別のロケータ(例えばfind('#id').set('password')又はfill_in('field_name', with: 'password')同一のビットより長い説明のためCapybara 2.0 Upgrade guide

読む「曖昧一致」を使用することです。カピバラ2.1で

62

、この作品:hereから

fill_in("Password", with: '123456', :match => :prefer_exact) 
    fill_in("Password confirmation", with: '123456', :match => :prefer_exact) 

を:prefer_exactはカピバラ1.xで動作する存在であります複数の一致が見つかった場合(そのうちのいくつかは正確であり、一致しないものがある場合)、最初に一致する要素が返されます。

+6

fill_in( "パスワード"、: '123456'、:一致=>:最初)も良いです – Norto23