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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With