mattheworiordan / capybara-screenshot

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

prune_strategy don't work, folder with screenshots is not automatic cleared #278

Open Synkevych opened 3 years ago

Synkevych commented 3 years ago

Hello guys. In our application we use your gem and it works great with RSpec, Capybara. It creates screenshots for failed tests on local machine and after running Github Actions. But we have a problem cleaning old screenshots in tmp/screenshots folder. The project is configured with default settings, so images are saved in the screenshots folder. New screenshots of failed tests are added to old ones and are difficult to find and distinguish from others.

The documentation states that capybara-screenshot has a default prune_strategy method for this, but it doesn't seem to work. Do you have any idea why it doesn't work and how you can fix it?

Here some setting from the project that might be useful:

Gemfile:

ruby '2.6.6'
gem 'rails', '5.2.0'

group :test do
  gem 'capybara'
  gem 'capybara-screenshot'
  gem 'webdrivers'
end

spec/rails_helper.rb:

require File.expand_path('../config/environment', __dir__)
abort('The Rails environment is running in production mode!') if Rails.env.production? || Rails.env.staging?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!

require 'capybara/rspec'
require 'capybara-screenshot/rspec'

Capybara.asset_host = 'http://localhost:5000'
Capybara::Screenshot.prune_strategy = :keep_last_run

# Also tried with this config:
# Capybara::Screenshot.prune_strategy = { keep: 20 }

Thanks)