mattheworiordan / capybara-screenshot

Automatically save screen shots when a Capybara scenario fails
MIT License
1.02k stars 168 forks source link

Saving only .html screenshots without .png #292

Closed Bar2d2 closed 1 year ago

Bar2d2 commented 1 year ago

Hi, 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'
Bar2d2 commented 1 year ago

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.