【发布时间】:2019-01-06 15:32:20
【问题描述】:
我有一个必要的模式,当用户尚未排除网站的服务条款时显示。我需要测试以确保在查看大量文档后显示引导模式,但我仍然不知道如何执行此操作。
# application.html.haml
.container-fluid
- if user_has_not_accepted_terms?
= render 'parts/terms_modal'
我的模态
.modal#terms_modal{'tabindex': "-1", role: "dialog", 'data-
keyboard':false, 'data-backdrop': "static"}
.modal-dialog{role: "document"}
.modal-content
.modal-header
%h5.modal-title
Our Terms of Service have changed
.modal-body
%p
Please take a minute and review our updated BLAH
.modal-footer
= link_to 'Accept Terms of Service', accept_terms_user_profile_path(current_user.id, current_user), method: :patch, class: 'btn btn-primary mx-auto'
确保模式在页面加载时打开
$(document).on('turbolinks:load', ->
$('#terms_modal').modal('show')
)
$(document).on('page:load', ->
$('#terms_modal').modal('show')
)
我知道我正在测试的用户尚未接受条款并且条件返回 true,当我在测试中运行 call save_and_open_page 时,我会返回包含模态的 html
到目前为止,我已经尝试过类似的测试
# accepting_terms_spec.rb
...
scenario 'user can accept terms of service', js: true do
... #user sign in and visit '/'
within('.modal#terms_modal) do
click_on('Accept Terms of Service')
end
expect(page).to have_content('Success')
end
我从测试中得到了 .modal 不可见的状态。
【问题讨论】:
-
您在 Capybara 中使用什么驱动程序配置?如果您实际使用 Selenium 进行此测试,您应该能够观察浏览器并查看引导模式是否真正打开。
-
Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, browser: :chrome) end Capybara.javascript_driver = :selenium_chrome
-
好的,你还没有用
js: true标记测试 - 该测试实际上是使用 Selenium(浏览器打开)吗?? -
是的,浏览器打开了,即使在场景“可以做”的情况下,js: true {} 我仍然得到相同的结果,还要注意当我运行 rails server 时,我确实看到了模态
-
但是当您在浏览器中观看测试运行时,您会看到模态框吗?
标签: ruby-on-rails twitter-bootstrap selenium rspec capybara