如何解决Capybara :: ElementNotFound错误

den*_*min 5 ruby-on-rails cucumber capybara

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

我使用rails 3.0.0和以下宝石

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'
Run Code Online (Sandbox Code Playgroud)

我在Senario中有以下内容

When I go to the new customer page
And I fill in "Email" with "john@example.com"
Run Code Online (Sandbox Code Playgroud)

在我的customer_steps.rb我有

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

在我看来

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit
Run Code Online (Sandbox Code Playgroud)

当我运行我的方案时,我收到此错误消息

 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"'
Run Code Online (Sandbox Code Playgroud)

den*_*min 4

我发现我的错误了!!!

When I go to the new customer page
Run Code Online (Sandbox Code Playgroud)

在该步骤之前

When /^I go to (.+)$/ do |page_name|
  path_to page_name 
end
Run Code Online (Sandbox Code Playgroud)

我忘记了访问...

When /^I go to (.+)$/ do |page_name|
  visit path_to(page_name) 
end
Run Code Online (Sandbox Code Playgroud)