使用 Capybara-Webkit 与引导框模式交互

Interacting with bootbox modals with Capybara-Webkit

Gem 版本:Rails 4.1.14.rc2、水豚 2.5.0、水豚-webkit 1.7.1

我们的应用程序使用引导框模态来表达对某些输入的软验证。我正在尝试使用 accept_confirm with block 方法来捕获模态,然后 Webkit 会像这样自动接受它:

modal = accept_confirm do
  fill_in " Date of birth", with: "12/31/2015"
  click_on "Update Spouse"
end

expect(modal).to # have some sort of message

我收到此错误响应:

 Failure/Error: modal = accept_confirm do
 Capybara::ModalNotFound:
   Timed out waiting for modal dialog

有没有人有使用 Webkit 和 bootbox modals 的经验?

***** 更新解决方案 *****

这是一个竞争条件。 Webkit 比 bootbox 移动得更快,并且出于某种原因它没有使用 capybara 的等待时间。在触发引导框模式的事件后添加 sleep 0.5 允许测试正确地 运行 。请参见下面的示例:

fill_in " Date of birth", with: "12/31/2015"
click_on "Add benefit"
sleep 0.5

expect(page).to have_content "some warning message..."
click_on "Make Correction"

sleep 0.5
fill_in " Date of birth", with: "12/31/1905"
click_on "Add benefit"

sleep 0.5
expect(page).to have_content "some warning message..."
click_on "Make Correction"

Capybara 模态 API 用于与系统模态交互——通过在 JS 中调用 window.alert/confirm/prompt 生成——bootbox 模态不是系统模态,它们是只是标准的 html 元素。您可以像页面上的任何其他元素一样与它们互动。