Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise/Capybara Ambiguous match

I am using devise to create a sign up wizard, but capybara(2.0.2) raises

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."

step definition is

When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
  fill_in(field, :with => value)
end
like image 509
Aydar Omurbekov Avatar asked Feb 19 '13 06:02

Aydar Omurbekov


2 Answers

With Capybara 2.1, this works:

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

From here :prefer_exact is the behaviour present in Capybara 1.x. If multiple matches are found, some of which are exact, and some of which are not, then the first eaxctly matching element is returned.

like image 64
Anoel Avatar answered Nov 08 '22 23:11

Anoel


In version 2.0 Capybara's find method raises a Capybara::Ambiguous exception when several elements matching specified locator where found. Capybara doesn't want to make an ambiguous choice for you.

The proper solution is to use another locator (e.g. find('#id').set('password') or fill_in('field_name', with: 'password')

Read "Ambiguous Matches" section of Capybara 2.0 Upgrade guide for a bit longer explanation of the same.

like image 23
Andrei Botalov Avatar answered Nov 09 '22 00:11

Andrei Botalov