我的黄瓜测试方案存在一些问题,不幸的是我有一个错误:
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"
答案 0 :(得分:1)
当我按照“关于星球大战的更多信息”#features / step_definitions / web_steps.rb:56
没有与标题,内容或文字相关的链接'更多关于星球大战'的信息(Capybara :: ElementNotFound) (eval):2:在`click_link'
./ features / step_definitions / web_steps.rb:57:in
/^(?:|I )follow "([^"]*)"$/' features/find_movie_with_same_director.feature:18:in
当我关注“有关星球大战的更多信息”时
似乎Capybara无法找到您的链接。 在该场景的步骤定义中尝试此步骤以单击链接
page.find('tr', text: "#{movie.title}") .click
答案 1 :(得分: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"