最近,我在我的rspec测试中切换为无头铬。移动之后,与jstree元素交互的所有测试都开始失败。以下是允许重现该错误的最小代码:
Gemfile中有依赖项:
# Gemfile
gem 'capybara', '2.18.0'
gem 'selenium-webdriver', '3.141.0'
这是呈现jstree的简单页面:
# jstree.html
<!doctype html>
<html>
<head>
<script src="https://rawgit.com/jquery/jquery/1.12.4/dist/jquery.min.js"></script>
<script src="https://rawgit.com/vakata/jstree/3.3.7/dist/jstree.min.js"></script>
<link href="https://rawgit.com/vakata/jstree/3.3.7/dist/themes/default/style.min.css" rel="stylesheet"/>
</head>
<body>
<h1>This is a list:</h1>
<ul id="tree"></ul>
<script>
$('#tree').jstree({
core: {
data: [{ "id": 1, "state": {}, "text": "Example", "parent": "#" }]
}
});
</script>
</body>
</html>
有一个ruby脚本可以用Capybara打开页面并保存页面截图:
# script.rb
require 'capybara'
require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new(
args: %w[headless no-sandbox disable-dev-shm-usage window-size=1280,800])
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.default_driver = :chrome
Capybara.app = Rack::File.new File.expand_path('../', __FILE__)
include Capybara::DSL
visit '/jstree.html'
page.save_and_open_screenshot
当我运行bundle exec ruby script.rb
并打开屏幕截图时,我看到以下内容:
但是当我在Chrome浏览器中打开jstree.html时,我看到了正常的树:
当我在脚本末尾添加输出浏览器控制台消息时
puts page.driver.browser.manage.logs.get(type)
并重新运行bundle exec ruby script.rb
我得到
SEVERE 2018-12-27 16:24:23 +0300: blob:http://127.0.0.1:49346/26695642-8b26-494b-a142-54a515db6512 - Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME
我正在使用chrome v71
和chromedriver v2.45
有人知道那里发生了什么吗? 我该如何解决这个问题?
答案 0 :(得分:4)
很遗憾,Chrome 71以无头模式破坏了blob
个URL。如果您是针对Chrome 72 beta运行的,则应予以修复。您可以在木偶问题中看到讨论-https://github.com/GoogleChrome/puppeteer/issues/3463
还请注意,您不需要使用水豚截图的gem来截取屏幕截图-只需致电page.save_and_open_screenshot