我是 Capybara 和功能测试的新手。我一直在尝试在 Rails 应用程序上测试一个小功能,该功能可以将帖子的评论切换到视图中和视图之外。将评论切换到视图中的第一个测试通过,但将它们切换到视图之外的第二个测试没有通过。(我正在使用无头铬网络驱动程序)。
context 'viewing comments', js: true do
scenario 'toggling comments into view' do
@post.comments.create(body: 'This is a comment.', user_id: @commenter.id)
visit authenticated_root_path
click_button 'Toggle comments'
expect(page).to have_content('This is a comment')
end
scenario 'toggling comments out of view' do
@post.comments.create(body: 'This is a comment.', user_id: @commenter.id)
visit authenticated_root_path
click_button 'Toggle comments'
expect(page).to have_content('This is a comment')
click_button 'Toggle comments'
expect(page).to_not have_content('This is a comment')
end
end
最初,我有click_button 'Toggle comments'
两次,背靠背。测试工作的迭代都没有。我也尝试sleep n
在这两个动作之间使用,但无济于事。
Failures:
1) Comment management viewing comments toggling comments out of view
Failure/Error: expect(page).to_not have_content('This is a comment')
expected not to find text "This is a comment" in "OdinFB PROFILE REQUESTS 0 LOG OUT The Feed Create post Luna Lovegood said... Body of post 0 Likes 1 Comments Like Comment Share Toggle comments This is a comment. Morfin Gaunt on Sep 18 2017 at 4:22PM"
当应用程序在本地启动时,按钮本身会起作用。一旦在测试中第一次被激活,它似乎就变得不活跃了。
任何见解将不胜感激,并感谢您的阅读。