2010-09-01 181 views
2

在我的Rails應用程序,我有與執行JavaScript函數的鏈接頁面:黃瓜,水豚和ElementNotFound

<%= link_to_function("Add an address", "add_fields(this)".html_safe) %> 

在我的黃瓜功能,我有:

And I press "Add an address" 

和消息我得到的是:

Capybara::ElementNotFound: no button with value or id or text 'Add an address' found 

我可能會錯過一些東西,但我找不到它是什麼..

回答

3

你應該做一個,只有一個,如下:

  • 重命名提交按鈕「創建'
  • 更改您的測試 '我按 「保存」,'
  • 添加到您的按鈕的ID,也改變了測試,像這樣:

    視圖
    = f.submit '保存',:ID =>:富

    測試
    我按下「富」

2

通過joaomilho解決:

你應該做一個,只有一個,以下:

重命名提交按鈕「創建」 更改測試「我按‘保存’」 添加到您的按鈕的ID,也改變了測試,像這樣:

視圖 = f.submit '保存',:ID =>:FOO

測試 我按下 「富」

1方案(1後) 3個步驟(3後) 0m2.510s

這裏

相同的行爲,我使用的是:

Rails 3的黃瓜/水豚/ Haml的

Feature: Manage posts 
    In order to [goal] 
    [stakeholder] 
    wants [behaviour] 

    @wip 
    Scenario: Register new post    # features/manage_posts.feature:6 
    Given I am on the new post page  # features/step_definitions/web_steps.rb:19 
    When I fill in "Title" with "title 1" # features/step_definitions/web_steps.rb:40 
    And I fill in "Body" with "body 1" # features/step_definitions/web_steps.rb:40 
    And I uncheck "Published"    # features/step_definitions/web_steps.rb:83 
    And I press "Create"     # features/step_definitions/web_steps.rb:27  
    Then I should see "title 1"   # features/step_definitions/web_steps.rb:108 
    And I should see "body 1"    # features/step_definitions/web_steps.rb:108 
    And I should see "false"    # features/step_definitions/web_steps.rb:108 

步驟:

When /^(?:|I)press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| with_scope(selector) do 
    click_button(button) 
    selenium.wait_for_page_to_load 
    end 
end 

查看新:

%h1 New post 

= render 'form' 

= link_to 'Back', posts_path 

錯誤:

no button with value or id or text 'Create' found (Capybara::ElementNotFound) 
     ./features/step_definitions/web_steps.rb:29 
     ./features/step_definitions/web_steps.rb:14:in `with_scope' 
     ./features/step_definitions/web_steps.rb:28:in `/^(?:|I)press "([^"]*)"(?: within "([^"]*)")?$/' 
     features/manage_posts.feature:11:in `And I press "Create"' 

_form:

= form_for @post do |f| 
    -if @post.errors.any? 
    #errorExplanation 
     %h2= "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:" 
     %ul 
     - @post.errors.full_messages.each do |msg| 
      %li= msg 

    .field 
    = f.label :title 
    = f.text_field :title 
    .field 
    = f.label :body 
    = f.text_area :body 
    .field 
    = f.label :published 
    = f.check_box :published 
    .actions 
    = f.submit 'Save' 
0

塞巴斯蒂安:嘗試將ID添加到您的鏈接,並在測試中引用它。

0

是不是原來的問題,你正在創建一個鏈接但試圖按按鈕

仔細閱讀水豚文檔,你會看到方法是不同的。

1

我相信你想

And I follow "Add an Address"