Capybara是一个用于Ruby的Web测试库,它有一个方法Capybara::Session.save_and_show_page,可以在浏览器中显示当前的网页。这似乎是异步工作 - 在调用之后的某个时间显示网页。没问题,但如果在调用#save_and_show_page后测试结束太快,则不会显示任何网页。
鉴于此Gemfile:
source "https://rubygems.org"
gem "launchy"
gem "poltergeist"
然后此代码不显示网页:
require "capybara/poltergeist"
session = Capybara::Session.new(:poltergeist)
session.visit("http://www.google.com")
session.save_and_open_page
在代码末尾添加一个简短的睡眠会导致网页显示,如下所示:
require "capybara/poltergeist"
session = Capybara::Session.new(:poltergeist)
session.visit("http://www.google.com")
session.save_and_open_page
sleep 1
# => Opening "/home/wayne/homesmart/franchise-manager-qa/capybara-201610141504469160970532.html" with Google Chrome (text/html)
# => [10253:10281:1014/150446:ERROR:nss_util.cc(809)] After loading Root Certs, loaded==false: NSS error code: -8018
# => Created new window in existing browser session.
如何让Capybara的#save_and_open_page方法始终显示页面,而无需在调用方法后插入睡眠?