Skip to content

Commit

Permalink
Add capybara screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
laurajaime committed Jul 31, 2024
1 parent 8b2138d commit a1c31a0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,16 @@ jobs:
max_attempts: 3
retry_on: error
command: CI=1 RAILS_ENV=test bundle exec rspec --backtrace

# Prepare screenshots for upload
- name: Prepare screenshots for upload
run: RAILS_ENV=test bundle exec rails ci:screenshots:rename
if: always()

# Upload screenshots artifact
- name: Upload screenshots
uses: actions/upload-artifact@v3
if: always()
with:
name: screenshot_artifact
path: /home/runner/work/participa/participa/tmp/screenshots/
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ group :development do
end

group :test do
gem "capybara-screenshot"
gem "database_cleaner"
end
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4)
launchy
carrierwave (2.2.6)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -933,6 +936,7 @@ PLATFORMS
DEPENDENCIES
bootsnap
byebug
capybara-screenshot
daemons
database_cleaner
decidim!
Expand Down
15 changes: 15 additions & 0 deletions lib/tasks/ci_rename_screenshots.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

SCREENSHOT_DIRECTORY = "/home/runner/work/participa/participa/tmp/screenshots"

namespace :ci do
namespace :screenshots do
task rename: :environment do
Dir["#{SCREENSHOT_DIRECTORY}/*"].each do |filename|
new_filename = filename.gsub(":", "").gsub(". .", ".")
File.rename(filename, new_filename)
puts "#{filename} was renamed to #{new_filename}"
end
end
end
end
5 changes: 5 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!

# Change the default screenshots file name
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.gsub(" ", "-").gsub(":", "").gsub(%r{^.*/spec/}, "")}"
end
end

0 comments on commit a1c31a0

Please sign in to comment.