I'm trying to get.png or.jpg image screenshots after test failing. Unfortunately it saves only.html file.
Rails 7.0.4
Ruby 3.2.0 .
gem 'cucumber', '~> 8.0' .
gem 'capybara-screenshot', '~> 1.0', '>= 1.0.26' .
env.rb file looks like below:
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'
I was trying to change webdrivers but didn't work out, Selenium should work correctly. It's making screenshot of.html perfectly but couldnt get image/png. Gems updated to newest ones. screenshot
Ok, I think I found a solution to this issue. It looks like it was a problem due to webdrivers. What I did:
I Installed:
gem "webdrivers"
In my cucumber config features/support/env.rb
sets up:
Capybara.default_driver =:selenium_chrome_headless
Now everything works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.