2016-05-31 127 views
0

我只是在学习功能规格,我遇到了一个我无法弄清楚的问题。当我尝试运行我的测试时出现了Capybara::ElementNotFound:。这很奇怪,因为我一直遵循一个模板词,但我仍然得到这个错误。我想要一些帮助!这是我的代码和错误的清晰。水豚:: 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: "[email protected]", password: "password") 
    fill_in "Email", with: "[email protected]" 
    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 

VIEW

<%= 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

字段的ID都将与subscriber_前缀 - 尝试改变fill_in "first_name", with: "Cam"fill_in "subscriber_first_name", with: "Cam",看看是否能解决它。