Module: SeleniumScreencast::RSpecHelper
- Defined in:
- lib/selenium_screencast/rspec.rb
Overview
A thin RSpec adapter for Capybara system specs (type: :system).
The only dependency on Capybara is page.driver.browser; this module
itself does not require Capybara.
Instance Method Summary collapse
-
#start_screencast_recording ⇒ Object
Starts recording.
-
#stop_screencast_recording ⇒ Object
Stops recording.
Instance Method Details
#start_screencast_recording ⇒ Object
Starts recording. Does nothing if the config is disabled. A failure to start is warned instead of raised, so it does not affect the test result. However, SeleniumScreencast::Error is a contractual exception signaling a configuration problem (e.g. a wrong RECORD_VIDEO_TESTS_FILE path), so it is not swallowed and is re-raised. Any other StandardError (Recorder start failure, an unexpected I/O error while judging the recording target, etc.) is warned and skipped as before, without affecting the test result.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/selenium_screencast/rspec.rb', line 28 def start_screencast_recording config = SeleniumScreencast.config return unless config.recording_target?(current_spec_file) dir = config.output_dir FileUtils.mkdir_p(dir) path = dir.join(screencast_filename(config)) browser = page.driver.browser @screencast_recorder = SeleniumScreencast::Recorder.new(browser, output_path: path) @screencast_recorder.start rescue SeleniumScreencast::Error raise rescue StandardError => e warn "SeleniumScreencast: failed to start recording: #{e.class}: #{e.}" @screencast_recorder = nil end |
#stop_screencast_recording ⇒ Object
Stops recording. A failure to stop is warned instead of raised. However, SeleniumScreencast::Error is a contractual exception signaling a configuration problem (e.g. ffmpeg missing or an invalid format value), so, just like start, it is not swallowed and is re-raised. stop also runs encoding (Encoder#encode) along this path, so without this rescue the intent of "raise a clear Error when ffmpeg is missing" would be swallowed by warn and stop working.
By default the video is kept regardless of pass/fail. When RECORD_VIDEO_FAILED_ONLY is enabled, a passing example stops with encode: false so ffmpeg is never invoked for it: recording (CDP frame capture) cannot be avoided since the outcome is only known afterwards, but the expensive part is skipped, and no file is written to output_dir.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/selenium_screencast/rspec.rb', line 58 def stop_screencast_recording return if @screencast_recorder.nil? @screencast_recorder.stop(encode: keep_video?) rescue SeleniumScreencast::Error raise rescue StandardError => e warn "SeleniumScreencast: failed to stop recording: #{e.class}: #{e.}" ensure @screencast_recorder = nil end |