2010-09-04 95 views
5

我堅持用下面的問題,這是我第一次使用水豚,你有一個想法,我怎麼能解決這個問題,謝謝如何解決水豚:: ElementNotFound錯誤

我用導軌3.0 1.0至下面的寶石

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 "[email protected]" 
我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 "[email protected]" # 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 "[email protected]"' 

回答

4

我發現我的錯誤!

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 
2

使用該ID的字段,而不是,它應該像

我用「[email protected]」填寫「customer_email」

如果@客戶是對象客戶模型

+0

感謝Rishav的回答,我已經嘗試過,並得到了同樣的錯誤,有沒有方法來'轉儲'的網頁的HTML,看看如果在正確的代碼水豚搜索? – denisjacquemin 2010-09-05 08:27:40

+0

嘿,看到log/test.log的任何錯誤.. – 2010-09-05 09:44:08

+0

好吧,當我運行黃瓜我沒有在我的日誌文件(開發或測試) – denisjacquemin 2010-09-05 10:05:29