Skip to content

Add an opt-in screenshot hook for feature specs - #442

Draft
cycomachead wants to merge 1 commit into
mainfrom
visual-screenshots
Draft

cycomachead wants to merge 1 commit into
mainfrom
visual-screenshots

Conversation

@cycomachead

Copy link
Copy Markdown
Member

Summary

Adds spec/support/screenshots.rb, the first step of the visual regression plan in #441.

SCREENSHOTS=1 bundle exec rspec spec/features

With the flag set, every feature spec runs in a 1280×900 headless Chrome and saves full-page screenshots to tmp/screenshots (or SCREENSHOT_DIR), named <spec file>/<example>/<NN>-<controller>-<action>.png. Without the flag, the file does nothing and the suite runs as before.

How it works

  • Capture points: just before the spec navigates away (visit, click_link, click_button, click_on) and once more when the example ends.
  • Waits for requests: the hook waits for jQuery's in-flight requests before each capture. This is required, not only nice to have: leaving a page while its DataTable is still loading makes DataTables raise an "Ajax error" alert, which breaks the browser session for every later example.
  • Own driver: the default spec window is narrow enough to collapse the navbar and sidebar, so screenshot mode registers its own 1280-wide Chrome.
  • Repeatable data: Faker, rand, factory sequences, SecureRandom.urlsafe_base64 and the clock are pinned per example.
  • Failures: a failing example contributes no images and gets a fresh browser for the next example.

Why this is a draft

Measured locally with two full runs of the feature suite in screenshot mode:

  • About 485 images per run; 405 were byte-identical between runs and 74 differed, mostly admin/events#index, admin/roles and admin/tracks#index. The causes have not been looked at yet.
  • 10–11 of 155 examples fail in screenshot mode (all pass in the normal suite). Seven fail every time because they were written for rack_test: unaccepted delete confirmations, and flash messages or record changes that do not appear after a form submit (venues_spec, tickets_spec, event_types_spec, resource_spec). event_schedules_spec.rb:41 fails once time is frozen, and a few others come and go.

Nothing runs this in CI yet.

Testing

  • Normal mode: spec/features/lodgings_spec.rb passes with the hook file present (3 examples, 0 failures).
  • Screenshot mode: results above.
  • rubocop spec/support/screenshots.rb is clean.

🤖 Generated with Claude Code

With SCREENSHOTS=1, every feature spec runs in a 1280-wide headless
Chrome and saves full-page screenshots to tmp/screenshots, named by
spec, example and route. A page is captured just before the spec
navigates away and once more when the example ends.

The hook waits for in-flight jQuery requests first: leaving a page while
its DataTable is still loading raises an "Ajax error" alert that breaks
the browser session. Faker, rand, factory sequences, SecureRandom short
titles and the clock are pinned so two runs mostly match.

Without the flag the suite is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant