Capybara :: ElementNotFound:找不到字段

时间:2016-05-31 16:14:58

标签: ruby-on-rails testing rspec

我只是在学习功能规格,而且我遇到了一个我无法弄清楚的问题。当我尝试运行测试时Capybara::ElementNotFound:。这很奇怪,因为我正逐字逐句地遵循模板,但我仍然遇到这个错误。我很乐意帮忙!为清楚起见,这是我的代码和错误。

TEST

require "rails_helper"

RSpec.feature "Create a subscriber" do
 scenario "Customer can sign up as a subscriber" do
  visit "/subscribers/new"

  user = User.create!(email: "user@example.com", password: "password")
  fill_in "Email", with: "user@example.com"
  fill_in "Password", with: "password"
  click_button "Sign in"

  fill_in "first_name", with: 
  fill_in "last_name", with: 
  fill_in "email", with:
  fill_in "phone_number", with: "8269338"

  expect(page).to have_content("Subscriber Has Been Successfully Created")
 end
end

查看

  <%= form_for @subscriber do |form| %>
  <div class="form-group">
  <p>
  <%= form.label :first %>
  <%= form.text_field :first_name %>
  </p>
  <p>
  <%= form.label :last %>
  <%= form.text_field :last_name %>
  </p>
  <p>
  <%= form.label :email %>
  <%= form.text_field :email %>
  </p>
  <p>
  <%= form.label :phone %>
  <%= form.text_field :phone_number %>
  </p>
 </div>
<%= form.submit "Sign Up", class: "btn btn-primary" %>
   

ERROR enter image description here

1 个答案:

答案 0 :(得分:1)

字段'ID将全部以subscriber_为前缀 - 尝试将fill_in "first_name", with: "Cam"更改为fill_in "subscriber_first_name", with: "Cam"并查看是否可以修复它。