ruby-on-rails – Devise / Capybara模糊匹配

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 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异常,当匹配指定的定位器找到的几个元素.水豚不想为你做一个模糊的选择.

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

阅读Capybara 2.0 Upgrade guide的“模糊匹配”部分,对此进行了更长的解释.

原文链接:https://www.f2er.com/ruby/265886.html

猜你在找的Ruby相关文章