gpt4 book ai didi

ruby-on-rails - 设计/ capybara 模糊匹配

转载 作者:行者123 更新时间:2023-12-04 01:58:31 26 4
gpt4 key购买 nike

我正在使用 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

最佳答案

在版本 2.0 Capybara 中 find方法引发 Capybara::Ambiguous当找到多个与指定定位器匹配的元素时出现异常。 Capybara 不想为您做出模棱两可的选择。

正确的解决方案是使用另一个定位器(例如 find('#id').set('password')fill_in('field_name', with: 'password' )

阅读 Capybara 2.0 Upgrade guide 的“歧义匹配”部分对相同的更长的解释。

关于ruby-on-rails - 设计/ capybara 模糊匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14951124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com