代码之家  ›  专栏  ›  技术社区  ›  Sebastien Lachance Shail

未发现黄瓜、水豚和元素

  •  2
  • Sebastien Lachance Shail  · 技术社区  · 16 年前

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

    我可能遗漏了什么,但我找不到它是什么。。

    5 回复  |  直到 16 年前
        1
  •  3
  •   joaomilho    16 年前

    您应该执行以下操作中的一项,而且只能执行一项:

    • 将“提交”按钮重命名为“创建”
    • 把你的测试改成'然后我按“保存”'
    • 在按钮中添加一个id,并更改测试,如下所示:

      看法
      =f.submit“保存”,:id=>:foo

      测试
      我按“foo”

        2
  •  2
  •   Daniel Machado    16 年前

    由joaomilho解决:

    把你的测试改成'然后我按“保存”' 在按钮中添加一个id,并更改测试,如下所示:

    =f.submit“保存”,:id=>:foo

    测试

    1个场景(1个通过) 0平方米.510秒

    同样的行为,我使用:

    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'
    
        3
  •  1
  •   oreoshake    15 年前

    我相信你想要

    And I follow "Add an Address"
    
        4
  •  0
  •   joaomilho    16 年前

    塞巴斯蒂安:试着给你的链接添加一个id,并在测试中引用它。

        5
  •  0
  •   Pete O    15 年前

    不是你创造的最初的问题吗 链接 但是试着按 按钮 ?