gpt4 book ai didi

ruby-on-rails - 如何解决 Capybara::ElementNotFound 错误

转载 作者:行者123 更新时间:2023-12-03 03:11:41 24 4
gpt4 key购买 nike

我遇到了以下问题,这是我第一次使用 capybara ,你知道我如何解决这个问题吗,谢谢

我使用 Rails 3.0.0 和以下 gem

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'

我的场景中有以下内容

When I go to the new customer page
And I fill in "Email" with "john@example.com"

在我的 customer_steps.rb 中我有

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
fill_in arg1, :with => arg2
end

在我看来

- form_for @customer do |f|
= f.label :email, 'Email'
= f.text_field :email
= f.submit

当我运行我的场景时,我收到此错误消息

 Scenario: Register new customer                  # features/manage_customers.feature:7
When I go to the new customer page # features/step_definitions/customer_steps.rb:1
And I fill in "Email" with "john@example.com" # features/step_definitions/customer_steps.rb:5
cannot fill in, no text field, text area or password field with id, name, or label 'Email' found (Capybara::ElementNotFound)
./features/step_definitions/customer_steps.rb:6:in `/^I fill in "([^"]*)" with "([^"]*)"$/'
features/manage_customers.feature:9:in `And I fill in "Email" with "john@example.com"'

最佳答案

我发现我的错误了!!!

When I go to the new customer page

执行此步骤之前

When /^I go to (.+)$/ do |page_name|
path_to page_name
end

我忘记了访问...

When /^I go to (.+)$/ do |page_name|
visit path_to(page_name)
end

关于ruby-on-rails - 如何解决 Capybara::ElementNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3642467/

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