我正在使用设计创建一个注册向导, 但是水豚(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
答案 0 :(得分:65)
使用Capybara 2.1,这有效:
fill_in("Password", with: '123456', :match => :prefer_exact)
fill_in("Password confirmation", with: '123456', :match => :prefer_exact)
来自here:prefer_exact是Capybara 1.x中存在的行为。如果找到多个匹配,其中一些是精确的,而其中一些不匹配,则返回第一个eaxctly匹配元素。
答案 1 :(得分:8)
在版本2.0中,Capybara的find
方法在找到匹配指定定位符的多个元素时引发Capybara::Ambiguous
异常。 Capybara不想为你做出暧昧的选择。
正确的解决方案是使用其他定位器(例如find('#id').set('password')
或fill_in('field_name', with: 'password'
)
阅读Capybara 2.0 Upgrade guide的“不明确的匹配”部分,以获得更长的解释。