Cucumber / Capybara找不到simple_form字段

时间:2015-09-16 16:15:04

标签: ruby-on-rails-4 cucumber capybara bdd

当我查看源代码时,文本字段的id与我在测试中要求的内容相匹配。

以下是表单字段: <fieldset class="fsStyle">
<legend class="legendStyle">*** Summarize Your Edits for History/Timeline ***</legend> <%= f.input :latest_update, input_html: { id: 'blurb' } %> <%= f.input :send_update %> </fieldset>

这是cuke功能:

```

Feature: Edit article with blurbs
  In order to send a clear update
  As an editor
  I want to add a summary of my edits

Scenario: Article Edit With Blurb
  Given I am on the show page
  And I follow "Edit"
  When I fill in "blurb" with "This is my edit summary"
  And I press "Update Article"
  And visit the history page
  Then I should see "This is my edit summary"

```

步骤定义: Given(/^I follow "(.*?)"$/) do |link_name| click_link link_name end

观点来源: ```

<fieldset class="fsStyle">              
        <legend class="legendStyle">*** Summarize Your Edits for History/Timeline ***</legend>
        <div class="form-group text optional article_latest_update"><label class="text optional control-label" for="blurb">Latest update</label><textarea id="blurb" class="text optional form-control" name="article[latest_update]">
a test update to check boolean</textarea></div>
        <div class="form-group boolean optional article_send_update"><div class="checkbox"><input value="0" type="hidden" name="article[send_update]" /><label class="boolean optional" for="article_send_update"><input class="boolean optional" type="checkbox" value="1" checked="checked" name="article[send_update]" id="article_send_update" />Send update</label></div></div>
    </fieldset>

```

以下是包含错误的测试输出: ```

Using the default profile...
Feature: Edit article with blurbs
  In order to send a clear update
  As an editor
  I want to add a summary of my edits

  Scenario: Article Edit With Blurb                       # features/edit_with_blurbs.feature:6
    Given I am on the show page                           # features/step_definitions/path_steps.rb:4
    And I follow "Edit"                                   # features/step_definitions/general_steps.rb:4
    When I fill in "blurb" with "This is my edit summary" # features/step_definitions/general_steps.rb:8
      Unable to find field "blurb" (Capybara::ElementNotFound)
      ./features/step_definitions/general_steps.rb:9:in `/^I fill in "(.*?)" with "(.*?)"$/'
      features/edit_with_blurbs.feature:9:in `When I fill in "blurb" with "This is my edit summary"'
    And I press "Update Article"                          # features/step_definitions/general_steps.rb:12
    And visit the history page                            # features/step_definitions/path_steps.rb:10
    Then I should see "This is my edit summary"           # features/step_definitions/general_steps.rb:16

Failing Scenarios:
cucumber features/edit_with_blurbs.feature:6 # Scenario: Article Edit With Blurb

1 scenario (1 failed)
6 steps (1 failed, 3 skipped, 2 passed)
0m1.739s

``` ...

1 个答案:

答案 0 :(得分:0)

如果您确定该页面已打开,则可以通过以下方式设置字段:

find(:id, "blurb").set("This is my edit summary")