0

我是新来的水豚和功能测试。我一直在尝试测试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" 

按钮本身,当应用程序在本地解雇了工作。一旦在测试中第一次激活,它似乎变得不活跃。

任何洞察力将不胜感激,并感谢阅读。

+0

您是否试过关闭无头,以便您可以看到页面上发生了什么?另外,请注意,您的第一个测试实际上并未验证内容在单击按钮之前是否不可见,因此它并不真正测试按下按钮是否切换内容。 –

+0

@ThomasWalpole感谢您的参与。我已经确实运行了它,并且看到了按钮可以将注释切换到视图中。并感谢第二点。我补充了必要的期望,并且测试仍然通过,谢天谢地。 –

+0

我认为你有一个错字,因为你说你运行它无头,看到按钮......。澄清一下,你是说在非无头模式下测试通过,但是在无头模式下失败? –

回答

0

这里发生了什么是第二个按钮单击发生后,预期的文本变得可见的页面上,但在动画完成之前。然后,引导程序崩溃代码会感到困惑,并且不会折叠注释,因为它认为它们尚未完全打开。在第二个click_button之前立即休息一会儿会解决这个问题,因为它延迟了足够长的时间来完成动画。另一个选项(从测试时间角度来看更好)是在测试模式下禁用动画。