2

在我的 rails 应用程序中,我有一个带有执行 javascript 函数的链接的页面:

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

我可能错过了一些东西,但我找不到它是什么..

4

5 回答 5

3

您应该执行以下一项且仅一项:

  • 将您的提交按钮重命名为“创建”
  • 将您的测试更改为“我按“保存””
  • 向您的按钮添加一个 id,并更改测试,如下所示:

    view
    = f.submit '保存', :id => :foo

    测试
    然后我按“foo”

于 2010-09-02T14:53:39.333 回答
2

由 joaomilho 解决:

您应该执行以下一项且仅一项:

将您的提交按钮重命名为“创建”将您的测试更改为“我按“保存””添加到您的按钮一个 id,并更改测试,如下所示:

view = f.submit '保存', :id => :foo

测试然后我按“foo”

1个场景(1个通过)3个步骤(3个通过)0m2.510s

这里的行为相同,我正在使用:

Rails 3 黄瓜/水豚/火腿

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_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'
于 2010-09-02T10:48:25.480 回答
1

我相信你想要

And I follow "Add an Address"
于 2011-06-22T18:41:36.170 回答
0

Sebastian:尝试在您的链接中添加一个 id,并在您的测试中引用它。

于 2010-09-02T18:51:43.193 回答
0

您创建链接但尝试按下按钮的原始问题不是吗?

仔细阅读 capybara 文档,你会发现方法不同。

于 2011-06-22T09:48:44.753 回答