9

サインアップウィザードを作成するためにdeviseを使用していますが、capybara(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 "user@ticketee.com"
    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."

ステップの定義は

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

2 に答える 2

66

Capybara 2.1では、これは機能します。

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

ここから:prefer_exactは、Capybara1.xに存在する動作です。複数の一致が見つかった場合、その一部は正確であり、一部はそうではない場合、最初の正確に一致する要素が返されます。

于 2013-06-05T00:27:40.837 に答える
8

バージョン2.0では、Capybaraのfindメソッドは、Capybara::Ambiguous指定されたロケーターに一致するいくつかの要素が見つかった場合に例外を発生させます。カピバラはあなたのために曖昧な選択をしたくありません。

適切な解決策は、別のロケーター(例find('#id').set('password')またはfill_in('field_name', with: 'password')を使用することです

同じことのもう少し長い説明については、Capybara2.0アップグレードガイドの「あいまいな一致」セクションをお読みください。

于 2013-02-19T07:25:43.717 に答える