Ruby on rails cucumber测试场景在使用before筛选器时失败?
我已参考链接进行测试 当我在过滤器前使用Ruby on rails cucumber测试场景在使用before筛选器时失败?,ruby-on-rails,rspec,cucumber,capybara,Ruby On Rails,Rspec,Cucumber,Capybara,我已参考链接进行测试 当我在过滤器前使用时:验证用户在我的控制器中,我的所有测试用例都失败了,当我在过滤器前注释时,我的所有测试用例都通过了。我得到以下错误 Scenario: Create Valid Article Given I have no articles And I am on the list of articles
时:验证用户代码>在我的控制器中,我的所有测试用例都失败了,当我在过滤器前注释时,我的所有测试用例都通过了。我得到以下错误
Scenario: Create Valid Article
Given I have no articles
And I am on the list of articles
When I follow "New Article"
Unable to find link "New Article" (Capybara::ElementNotFound)
./features/step_definitions/article_steps.rb:25:in `/^I follow "([^\"]*)"$/'
features/manage_articles.feature:15:in `When I follow "New Article"'
And I fill in "article[title]" with "Spuds"
And I fill in "Content" with "Delicious potato wedges!"
And I press "Create"
Then I should see "New article created."
And I should see "Spuds"
And I should see "Delicious potato wedges!"
And I should have 1 article
Failing Scenarios:
cucumber features/manage_articles.feature:12 # Scenario: Create Valid Article
2 scenarios (1 failed, 1 passed)
14 steps (1 failed, 7 skipped, 6 passed)
第_.rb条
由于您的身份验证失败,所以您的测试场景应该类似于先对用户进行身份验证……因为没有身份验证,它不会进入文章列表页面,所以“新文章”链接没有找到,并出现该错误
Scenario: Create Valid Article
When I am on the login page
Then I filled up username as "abc"
Then I filled up password as "abc"
Then I follow "login"
Given I have no articles
And I am on the list of articles
When I follow "New Article"
或
基于错误,水豚无法在页面上找到链接。因此,根据@gotva,请检查页面上是否有“新算法”链接
正如您将放在\u过滤器之前:验证\u用户代码>这意味着您需要先登录,然后才能尝试访问该页面。但该功能中没有登录场景
因此,我建议您按照@Rajarshi Das的建议在页面中添加登录场景。如果你的登录场景总是包含在每个功能中,那么你可以把它放进去
希望有帮助 你能发布你对/features/step\u definitions/article\u steps.rb的步骤定义吗?
“文章列表”页面上是否有名为“新文章”的链接
将gem启动
添加到gem文件中,并使用保存和打开页面
查看实际情况page@gotva我使用过launchy,但我不知道如何使用save_and_open_page,因为我对cucumber是新手。只需将save_and_open_page
放在正确的位置即可。在您的情况下,是在单击步骤中的
链接之前,/^I遵循…
谢谢您的回答,我将检查并让您知道输出。如果用户登录了不明确匹配,则发现两个元素匹配字段“user\u email”(水豚::不明确)/features/step\u definitions/article\u steps.rb:3:inlogin./features/step\u definitions/article\u steps.rb:62:in
/^用户已登录$/'功能/管理文章。功能:7:in“给定用户已登录”我已完成了u r步骤,但出现了一个错误。实际上我正在学习黄瓜,因此需要更多的时间来完成理解这些事情。如果你能给我推荐一个很好的黄瓜测试教程,这会对我有所帮助。这意味着有一些东西在重复。你可以买一本书给cucumber学习,比如《cucumber的基础知识》,或者浏览cucumber的视频和文档是主要的学习资源。谢谢,我的测试用例现在变绿了,实际上它们是表单字段id的冲突。
Scenario: Create Valid Article
When I am on the login page
Then I filled up username as "abc"
Then I filled up password as "abc"
Then I follow "login"
Given I have no articles
And I am on the list of articles
When I follow "New Article"
Scenario: Create Valid Article
Given User is authenticated
Given I have no articles
And I am on the list of articles
When I follow "New Article"
Feature: Managing Articles
Background:
Given user is logged in
Scenario: Create Valid Article
Given I have no articles
And I am on the list of articles
When I follow "New Article"
And I fill in "article[title]" with "Spuds"
And I fill in "Content" with "Delicious potato wedges!"
And I press "Create"
Then I should see "New article created."
And I should see "Spuds"
And I should see "Delicious potato wedges!"
And I should have 1 article
common_steps.rb
def login user
#stuff of login process
end
Given /^user is logged in$/ do
@user = Factory.create(:user) #if you are using factory_girl
login(@user)
end