Module: SeleniumScreencast

Defined in:
lib/selenium_screencast.rb,
lib/selenium_screencast/rspec.rb,
lib/selenium_screencast/encoder.rb,
lib/selenium_screencast/version.rb,
lib/selenium_screencast/recorder.rb,
lib/selenium_screencast/frame_store.rb,
lib/selenium_screencast/configuration.rb,
sig/selenium_screencast.rbs

Overview

CDP screencast recording engine, independent of Capybara. Provides access to config and creation/reset of Configuration.

Defined Under Namespace

Modules: RSpecHelper Classes: Configuration, Encoder, Error, FrameStore, Recorder

Constant Summary collapse

VIDEO_FORMATS =

ffmpeg settings per output format. Both Configuration (which formats are allowed) and Encoder (which codec builds the argv per format) treat this as the single source of truth. Letting either side hold its own allowlist would let them drift apart, passing validation but raising KeyError when building argv, so it lives here in a neutral location instead. ext : output file extension (the container is inferred by ffmpeg from it) codec : video codec passed to -c:v extra : codec-specific extra options (mp4/H.264 pins yuv420p for playback compatibility, and scales to even dimensions since libx264 with yuv420p requires the width and height to be divisible by 2 — an odd-sized capture otherwise aborts encoding, e.g. exit 187) format_spec returns this entry as-is and ffmpeg_argv reads from it, so nested Hash / Array values are frozen too, preventing an accidental mutation from corrupting global state (it raises FrozenError instead, so it gets noticed).

{
  webm: { ext: "webm", codec: "libvpx-vp9", extra: [].freeze }.freeze,
  mp4: {
    ext: "mp4", codec: "libx264",
    extra: ["-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-pix_fmt", "yuv420p"].freeze
  }.freeze
}.freeze
VERSION =

Returns:

  • (String)
"0.1.0"

Class Method Summary collapse

Class Method Details

.clean_output_dir!Object

Empties output_dir at the start of a run so this run's videos aren't mixed with stale files from a previous run. No-op unless recording is enabled (RECORD_VIDEO), preserving the "disabled -> nothing happens" contract. Wipes at most once per process, so registering it in a before(:suite) hook is idempotent. Does nothing if the directory does not exist yet.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/selenium_screencast.rb', line 59

def clean_output_dir!
  return unless config.enabled?
  return if @output_dir_cleaned

  @output_dir_cleaned = true
  dir = config.output_dir
  return unless File.directory?(dir)

  # Enumerate entries with Dir.children instead of interpolating dir into a
  # Dir.glob pattern: a dir path containing glob metacharacters ([, {, *,
  # ...) would otherwise be misparsed and silently clean nothing.
  Dir.children(dir).each { |name| FileUtils.rm_rf(File.join(dir, name)) }
end

.configObject



44
45
46
# File 'lib/selenium_screencast.rb', line 44

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



39
40
41
42
# File 'lib/selenium_screencast.rb', line 39

def configure
  yield config
  config
end

.reset_config!Object



48
49
50
51
# File 'lib/selenium_screencast.rb', line 48

def reset_config!
  @config = Configuration.new
  @output_dir_cleaned = false
end