我正在尝试编写测试。有一个带有元素和删除按钮的站点,用于删除该元素。如果手动完成,它将按预期工作。
目前,测试看起来像这样:
visit "/argumentation#!/overview"
expect(page).to have_content("Philosophie")
save_screenshot
click_button "Delete"
save_screenshot
click_button "Yes, delete it!"
save_screenshot
sleep 5
save_screenshot
expect(page).not_to have_content("Philosophie")
(截图的图片如下)。
为了确保click_button "Yes, delete it!"
实际上与弹出窗口中显示的按钮相同,我在click_button "Yes, delete it!"
- 操作之前添加了click_button "Delete"
。这会发生:
Capybara::ElementNotFound:
Unable to find button "Yes, delete it!"
有谁知道,为什么测试失败?
在其他stackoverflow-questions中,有些人询问了rails_helper.rb中的配置,这是我的:
Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :poltergeist
答案 0 :(得分:0)
我想通了:click_button“是的,删除它!”发生得太快了。延迟,它的工作原理:
click_button "Delete"
sleep 5
click_button "Yes, delete it!"