2013-03-23 132 views
2

我不斷收到此錯誤未找到:元素在水豚

Capybara::ElementNotFound: 
     cannot fill in, no text field, text area or password field with id, name, or label 'Morning' found. 

我已經復位叉勺,做了充分的分貝復位,試圖分配一個ID的表單元素等什麼可能是問題這裏?

days_controller_spec.rb

require 'spec_helper' 

describe DaysController do 

    describe "New" do 

    describe "with valid information" do 

     it "should create a new entry" do 
     visit 'days#new' 
     fill_in "Morning", with: "Test" 
     click_button "Submit" 
     end 
    end 
    end 
end 

days_controller.rb

<%= form_for @day do |f| %> 

    <%= f.label :morning %> 
    <%= f.text_field :morning %> 

    <%= f.button :submit %> 
<% end %> 
+0

您是否添加了'save_and_open_page'命令來確保您位於正確的頁面? – depa 2013-03-23 03:41:06

+0

@mdepolli是的,它正在導航到正確的頁面。我剛剛創建了該應用程序。此表單頁面是迄今爲止創建的兩個頁面之一。 – bwobst 2013-03-23 03:44:09

回答

2

看起來像你的應用程序使用的JavaScript。使用水豚你需要添加:js => true選項到處理JS頁面的塊。

嘗試:

it "should create a new entry", :js => true do 

您可能還需要爲這樣的形式試圖fill_in現場之前被渲染。

此外,我建議你檢查水豚的集成DSL。閱讀更多關於它的信息here

+0

結果顯示「:js => true」不是答案,但是您提到的「集成」讓我記得嘗試將測試放在集成測試規範中。完美工作。 – bwobst 2013-03-23 04:07:30

0

原來,這種語法是正確的,但問題在於測試是在錯誤的RSpec spec文件中。當我將這個測試換成一個integration_test文件時,它完美運行。