ruby Cucumber/水豚只保存.html截图,不保存.png

piok6c0g  于 2023-01-16  发布在  Ruby
关注(0)|答案(1)|浏览(151)

我试图得到.png或.jpg图像截图后,测试失败。不幸的是,它只保存.html文件。

导轨7.0.4
Ruby 3.2.0版本.
宝石“ cucumber ”,“~〉8.0”
gem '水豚-屏幕截图','~〉1.0','〉= 1.0.26'.

env.rb文件如下所示:

require 'simplecov'
require 'cucumber/rails'
require 'cucumber/rspec/doubles'
require 'capybara-screenshot/cucumber'
require 'email_spec/cucumber'
require 'selenium-webdriver'
require 'database_cleaner/active_record'

World(FactoryBot::Syntax::Methods)

ActionController::Base.allow_rescue = false

begin
  DatabaseCleaner.strategy = :truncation
rescue NameError
  raise RuntimeError('You need to add database_cleaner to your Gemfile '\
                     '(in the :test group) if you wish to use it.')
end
Around do |_scenario, block|
  DatabaseCleaner.cleaning(&block)
end

Before do
  t = Time.local(2022, 5, 1, 10, 5, 0)
  Timecop.freeze(t)
end

After do
  Timecop.return
end

Cucumber::Rails::Database.javascript_strategy = :truncation

Capybara.register_driver :selenium_chrome_headless do |app|
  browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
    opts.args << '--window-size=1920,1080'
    opts.args << '--headless'
  end
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

Capybara.javascript_driver = :selenium_chrome_headless
Capybara.asset_host = 'http://localhost:3000'

我试图改变webdrivers,但没有工作, selenium 应该正常工作。它使.html完美的截图,但无法得到image/png。宝石更新到最新的。screenshot

hgc7kmma

hgc7kmma1#

好的,我想我找到了这个问题的解决方案。看起来这是一个问题,由于webdrivers。我做了什么:

  1. I安装:
    gem "webdrivers"
    1.在我的 cucumber 配置features/support/env.rb中设置:
    Capybara.default_driver = :selenium_chrome_headless
    现在一切正常了。

相关问题