Class: SeleniumScreencast::Configuration
- Inherits:
-
Object
- Object
- SeleniumScreencast::Configuration
- Defined in:
- lib/selenium_screencast/configuration.rb
Overview
Holds the configuration for the recording engine.
Value precedence is "env var > value set via configure > default". Env vars always win, since they're often used to temporarily change behavior in CI, etc. An env var of nil / empty string is treated as "unset" (this does not rely on ActiveSupport's String#blank?).
Constant Summary collapse
- DEFAULT_SLOW_FACTOR =
8.0- DEFAULT_OUTPUT_FPS =
30- DEFAULT_FFMPEG_BIN =
"ffmpeg"- DEFAULT_QUALITY =
80- DEFAULT_EVERY_NTH_FRAME =
1- DEFAULT_LAST_FRAME_DURATION =
0.5- DEFAULT_INFLIGHT_DELAY =
0.2- DEFAULT_FORMAT =
:webm
Instance Attribute Summary collapse
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#every_nth_frame ⇒ Object
Capture every Nth frame.
-
#failed_only ⇒ Object
writeonly
Sets the attribute failed_only.
- #ffmpeg_bin ⇒ Object
-
#format ⇒ Object
The output format (:webm / :mp4).
- #inflight_delay ⇒ Object
- #last_frame_duration ⇒ Object
-
#output_dir ⇒ Object
The output directory.
- #output_fps ⇒ Object
-
#quality ⇒ Object
JPEG quality (0-100).
- #slow_factor ⇒ Object
Instance Method Summary collapse
-
#debug? ⇒ Boolean
Frame images are kept (for debugging) when RECORD_DEBUG is set.
-
#enabled? ⇒ Boolean
Recording is enabled when RECORD_VIDEO is set.
-
#failed_only? ⇒ Boolean
Only failed examples keep their video when RECORD_VIDEO_FAILED_ONLY is set.
-
#recording_target?(spec_file) ⇒ Boolean
Whether the given spec file should be recorded.
Instance Attribute Details
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
22 23 24 |
# File 'lib/selenium_screencast/configuration.rb', line 22 def debug=(value) @debug = value end |
#every_nth_frame ⇒ Object
Capture every Nth frame. Resolved with env > configure > default, then validated to be a positive value.
56 57 58 59 60 |
# File 'lib/selenium_screencast/configuration.rb', line 56 def every_nth_frame raw = env_or("RECORD_EVERY_NTH_FRAME", value_or_default(@every_nth_frame, DEFAULT_EVERY_NTH_FRAME), &:to_i) normalize_int_in_range(raw, "every_nth_frame", 1.., ">= 1") end |
#failed_only=(value) ⇒ Object (writeonly)
Sets the attribute failed_only
22 23 24 |
# File 'lib/selenium_screencast/configuration.rb', line 22 def failed_only=(value) @failed_only = value end |
#ffmpeg_bin ⇒ Object
34 35 36 |
# File 'lib/selenium_screencast/configuration.rb', line 34 def ffmpeg_bin env_or("FFMPEG_BIN", value_or_default(@ffmpeg_bin, DEFAULT_FFMPEG_BIN)) { |v| v } end |
#format ⇒ Object
The output format (:webm / :mp4). Resolved with env > configure > default, then normalized to absorb case, surrounding whitespace, and symbol/string variance. An unsupported value is a config error, so it raises a clear Error.
42 43 44 45 |
# File 'lib/selenium_screencast/configuration.rb', line 42 def format raw = env_or("RECORD_VIDEO_FORMAT", value_or_default(@format, DEFAULT_FORMAT)) { |v| v } normalize_format(raw) end |
#inflight_delay ⇒ Object
66 67 68 |
# File 'lib/selenium_screencast/configuration.rb', line 66 def inflight_delay value_or_default(@inflight_delay, DEFAULT_INFLIGHT_DELAY) end |
#last_frame_duration ⇒ Object
62 63 64 |
# File 'lib/selenium_screencast/configuration.rb', line 62 def last_frame_duration value_or_default(@last_frame_duration, DEFAULT_LAST_FRAME_DURATION) end |
#output_dir ⇒ Object
The output directory. A user-specified value takes priority; otherwise Rails.root/tmp/videos in a Rails environment, or the relative tmp/videos outside Rails.
73 74 75 76 77 |
# File 'lib/selenium_screencast/configuration.rb', line 73 def output_dir return Pathname(@output_dir.to_s) unless @output_dir.nil? defined?(Rails) ? Rails.root.join("tmp/videos") : Pathname("tmp/videos") end |
#output_fps ⇒ Object
30 31 32 |
# File 'lib/selenium_screencast/configuration.rb', line 30 def output_fps value_or_default(@output_fps, DEFAULT_OUTPUT_FPS) end |
#quality ⇒ Object
JPEG quality (0-100). Resolved with env > configure > default, then validated to be within the range CDP accepts.
49 50 51 52 |
# File 'lib/selenium_screencast/configuration.rb', line 49 def quality raw = env_or("RECORD_QUALITY", value_or_default(@quality, DEFAULT_QUALITY), &:to_i) normalize_int_in_range(raw, "quality", 0..100, "between 0 and 100") end |
#slow_factor ⇒ Object
26 27 28 |
# File 'lib/selenium_screencast/configuration.rb', line 26 def slow_factor env_or("RECORD_SLOW_FACTOR", value_or_default(@slow_factor, DEFAULT_SLOW_FACTOR), &:to_f) end |
Instance Method Details
#debug? ⇒ Boolean
Frame images are kept (for debugging) when RECORD_DEBUG is set.
99 100 101 |
# File 'lib/selenium_screencast/configuration.rb', line 99 def debug? env_present?("RECORD_DEBUG") || @debug == true end |
#enabled? ⇒ Boolean
Recording is enabled when RECORD_VIDEO is set.
80 81 82 |
# File 'lib/selenium_screencast/configuration.rb', line 80 def enabled? env_present?("RECORD_VIDEO") end |
#failed_only? ⇒ Boolean
Only failed examples keep their video when RECORD_VIDEO_FAILED_ONLY is set. Recording itself still runs for every example (frames must be captured before the outcome is known); this flag only decides whether the captured frames get encoded into a video at the end. Orthogonal to RECORD_VIDEO_TESTS: when both are set, only the listed specs that also failed produce a video.
109 110 111 |
# File 'lib/selenium_screencast/configuration.rb', line 109 def failed_only? env_present?("RECORD_VIDEO_FAILED_ONLY") || @failed_only == true end |
#recording_target?(spec_file) ⇒ Boolean
Whether the given spec file should be recorded. Always false if the arm (enabled?) is disabled (the target list env vars are not read at all in that case). If neither target list env var is set, records everything (true), as before. If set, normalizes and checks for a match. An effectively empty list is always false (does not fall back to recording everything).
90 91 92 93 94 95 96 |
# File 'lib/selenium_screencast/configuration.rb', line 90 def recording_target?(spec_file) return false unless enabled? return true unless target_list_configured? return false if spec_file.nil? || spec_file.to_s.empty? recording_target_paths.include?(normalize_test_path(spec_file)) end |