0

我的黄瓜测试场景有一些问题,不幸的是我有一个错误:

When I follow "More about Star Wars"                        # features/step_definitions/web_steps.rb:56

  no link with title, id or text 'More about Star Wars' found (Capybara::ElementNotFound)
  (eval):2:in `click_link'

  ./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
  features/find_movie_with_same_director.feature:18:in `When I follow "More about Star Wars"'

我猜它与动态链接有关以提取正确的ID。当然,一切都在浏览器中运行,当我测试创建新记录时也是如此。

详细信息在下面添加

有人可以帮我找到我的测试场景的正确解决方案吗?

app/views/movies/index.html.haml

 %tbody
- @movies.each do |movie|

  %tr
    %td= movie.title 
    %td= movie.rating
    %td= movie.release_date
    %td= movie.director
    %td= link_to "More about #{movie.title}", movie_path(movie)
    %td= movie_path(movie)
  =link_to 'Add new movie', new_movie_path

features/step_definition/web_steps.rb

When /^(?:|I )follow "([^"]*)"$/ do |link|
  click_link(link)
end

在我的功能文件中:

Feature: search for movies by director

Scenario: find movie with the same director
 As a movie buff
 So that I can find movies with my favorite director
 I want to include and search on director information in movies I enter

Background: movies in database
  Given the following movies exist:
  | title        | rating | director     | release_date |
  | Star Wars    | PG     | George Lucas |   1977-05-25 |
  | Blade Runner | PG     | Ridley Scott |   1982-06-25 |
  | Alien        | R      |              |   1979-05-25 |
  | THX-1138     | R      | George Lucas |   1971-03-11 |

  Given I am on the home page
  When I follow "More about Star Wars"
  Then  I should be on the details page for "Star Wars"
4

2 回答 2

1

当我关注“更多关于星球大战”# features/step_definitions/web_steps.rb:56

找不到标题、id 或文本“更多关于星球大战”的链接 (Capybara::ElementNotFound) (eval):2:in `click_link'

./features/step_definitions/web_steps.rb:57:in/^(?:|I )follow "([^"]*)"$/' features/find_movie_with_same_director.feature:18:in当我关注“更多关于星球大战”时

Seems Capybara cannot find your link. Try this step in your step definition on that scenario to click the link

    page.find('tr', text: "#{movie.title}") .click
于 2012-11-20T15:35:14.190 回答
0
Feature: search for movies by director

  As a movie buff
  So that I can find movies with my favorite director
  I want to include and search on director information in movies I enter

Background: movies in database
Given the following movies exist:
  | title        | rating | director     | release_date |
  | Star Wars    | PG     | George Lucas |   1977-05-25 |
  | Blade Runner | PG     | Ridley Scott |   1982-06-25 |
  | Alien        | R      |              |   1979-05-25 |
  | THX-1138     | R      | George Lucas |   1971-03-11 |
  | THX-1131     | G      | George Lucas |   1971-03-11 |

Scenario: find movie with same director
  Given I am on the RottenPotatoes home page
  And I check "ratings_PG"
  And I press "Refresh"
  When I follow "More about Star Wars"
于 2012-11-06T07:38:34.713 回答