test-recorder 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b7a9be6d6179b7ea6275e1e9b9463817dd0062452ca6b45c95c85dd9a3d8840
4
- data.tar.gz: af977f2a4990f75f107210dd50b3f4c755f5efdbc7779e9c070dc480a715e4d1
3
+ metadata.gz: db491c5f3e52392c234291c174bbc1fff1bfb67d05a0ba23e50560529ea21d25
4
+ data.tar.gz: ae3f23d20992e0ec4e9cc4597fa15e346e52e1d2c31e482eab750d64942f8df1
5
5
  SHA512:
6
- metadata.gz: 9f0faa3366d09f18b142ed4f5c42fa9ae1a7be31c8359eccae8695004920a973188880e0599759fc8b480e4c3e080d3a6985931d5d34fea2e349d36ed4d8005e
7
- data.tar.gz: 634c35482c87795803ed7509d5042c357c440e876f03e6969a80501ca7d6e80b8b71292f1d13e9199e1c37dcf72763026b05e4c07fd91851a50162dc6e309ed8
6
+ metadata.gz: d4964d2703dc893155e0d246843141221e75991c57eb93da21e3c1331c9d9d648f56cf32d88885d4f89fc6da07b3889215549c055c9986aeecd3ac9c43bde1d7
7
+ data.tar.gz: d4c944875e4ee763fa6b88c434e700afa63fd1c3380d392e2d18f589a3e6f15aae4c2c83a52ece118829b0b343581efbe8b4a9d982b291921715c4e72f553f31
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-recorder (0.1.3)
4
+ test-recorder (0.1.4)
5
5
  activesupport
6
6
  selenium-devtools
7
7
  selenium-webdriver (>= 4.0)
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.1)
12
+ activesupport (7.0.3)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
@@ -17,22 +17,22 @@ GEM
17
17
  activesupport-testing-metadata (0.1.0)
18
18
  activesupport (>= 4.0)
19
19
  childprocess (4.1.0)
20
- concurrent-ruby (1.1.9)
21
- debug (1.4.0)
20
+ concurrent-ruby (1.1.10)
21
+ debug (1.5.0)
22
22
  irb (>= 1.3.6)
23
23
  reline (>= 0.2.7)
24
- i18n (1.8.11)
24
+ i18n (1.10.0)
25
25
  concurrent-ruby (~> 1.0)
26
26
  io-console (0.5.11)
27
27
  irb (1.4.1)
28
28
  reline (>= 0.3.0)
29
- minitest (5.14.2)
29
+ minitest (5.15.0)
30
30
  rake (12.3.3)
31
31
  reline (0.3.1)
32
32
  io-console (~> 0.5)
33
33
  rexml (3.2.5)
34
34
  rubyzip (2.3.2)
35
- selenium-devtools (0.100.0)
35
+ selenium-devtools (0.101.0)
36
36
  websocket (~> 1.0)
37
37
  selenium-webdriver (4.1.0)
38
38
  childprocess (>= 0.5, < 5.0)
@@ -1,11 +1,10 @@
1
- require "open3"
2
1
  require "fileutils"
3
- require "tempfile"
4
2
 
5
3
  module TestRecorder
6
4
  class CdpRecorder
7
5
  def initialize(enabled:)
8
6
  @enabled = enabled
7
+ @tmpdir = nil
9
8
  setup
10
9
  end
11
10
 
@@ -18,20 +17,19 @@ module TestRecorder
18
17
  enabled = @enabled if enabled.nil?
19
18
  return unless enabled
20
19
 
21
- @tmp_video = Tempfile.open(["testrecorder", ".mp4"])
22
- cmd = "ffmpeg -loglevel quiet -f image2pipe -avioflags direct -fpsprobesize 0 -probesize 32 -analyzeduration 0 -c:v mjpeg -i - -y -an -r 25 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M -threads 1 #{@tmp_video.path}"
23
- @stdin, @wait_thrs = *Open3.pipeline_w(cmd)
24
- @stdin.set_encoding("ASCII-8BIT")
20
+ @tmpdir = Dir.mktmpdir("testrecorder")
21
+ counter = 1
25
22
 
26
23
  @page = page
27
24
  @page.driver.browser.devtools.page.enable
28
25
 
29
26
  @page.driver.browser.devtools.page.on(:screencast_frame) do |event|
30
- unless @stdin.closed?
31
- decoded_data = Base64.decode64(event["data"])
32
- @stdin.print(decoded_data)
27
+ decoded_data = Base64.decode64(event["data"])
28
+ filename = "%010d.jpeg" % counter
29
+ if Dir.exist?(@tmpdir)
30
+ IO.binwrite("#{File.join(@tmpdir, filename)}", decoded_data)
31
+ counter += 1
33
32
  end
34
-
35
33
  @page.driver.browser.devtools.page.screencast_frame_ack(session_id: event["sessionId"])
36
34
  end
37
35
 
@@ -39,19 +37,25 @@ module TestRecorder
39
37
  end
40
38
 
41
39
  def stop_and_discard
42
- @stdin.close
40
+ FileUtils.rm_rf(@tmpdir) unless @tmpdir.nil?
43
41
  end
44
42
 
45
43
  def stop_and_save(filename)
46
- return if @page.nil?
47
-
48
- @stdin.close
49
- @wait_thrs.each(&:join)
44
+ return if @tmpdir.nil? || @page.nil?
50
45
 
46
+ @page.driver.browser.devtools.page.stop_screencast
51
47
  video_path = File.join(@video_dir, filename)
52
- FileUtils.copy(@tmp_video.path, video_path)
53
- @tmp_video.close(true)
48
+
49
+ args = %W(-loglevel error -f image2 -avioflags direct -fpsprobesize 0
50
+ -probesize 32 -analyzeduration 0 -c:v mjpeg -i #{File.join(@tmpdir, "%010d.jpeg")}
51
+ -y -an -r 25 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M
52
+ -threads 1 #{video_path})
53
+ system("ffmpeg", *args, exception: true)
54
54
  video_path
55
+ rescue => e
56
+ $stderr.puts("[TestRecorder] ffmpeg failed: #{e.message}")
57
+ ensure
58
+ FileUtils.rm_rf(@tmpdir)
55
59
  end
56
60
  end
57
61
  end
@@ -1,10 +1,7 @@
1
- require "fileutils"
2
-
3
1
  module TestRecorder
4
2
  module Rails
5
3
  module SetupAndTeardown
6
4
  def before_setup
7
-
8
5
  @cdp_recorder = TestRecorder::CdpRecorder.new(enabled: TestRecorder.enabled?)
9
6
  enabled = respond_to?(:metadata) ? metadata[:test_recorder] : nil
10
7
  @cdp_recorder.start(page: page, enabled: enabled)
@@ -1,3 +1,3 @@
1
1
  module TestRecorder
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-10 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport