test-recorder 0.1.4 → 0.1.5

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: db491c5f3e52392c234291c174bbc1fff1bfb67d05a0ba23e50560529ea21d25
4
- data.tar.gz: ae3f23d20992e0ec4e9cc4597fa15e346e52e1d2c31e482eab750d64942f8df1
3
+ metadata.gz: c74ddd16cdffa85784c96e4be8bc549752122364fa729a5cf8cc68fc923d4dc0
4
+ data.tar.gz: 5b9d3ec1a27a641c447ac896a031625153027797a9b5d2a163bdb17f706a88b0
5
5
  SHA512:
6
- metadata.gz: d4964d2703dc893155e0d246843141221e75991c57eb93da21e3c1331c9d9d648f56cf32d88885d4f89fc6da07b3889215549c055c9986aeecd3ac9c43bde1d7
7
- data.tar.gz: d4c944875e4ee763fa6b88c434e700afa63fd1c3380d392e2d18f589a3e6f15aae4c2c83a52ece118829b0b343581efbe8b4a9d982b291921715c4e72f553f31
6
+ metadata.gz: 572f1b6775222278e1e036c8c7e692f1991521fbcc30ecab6e44f7e713252670f62a2b88f308ff0eb6467ee6c65db90966f98f3cffd1a8d2e8bf59372b601199
7
+ data.tar.gz: 397223170511f89678bbf2593586929965a12dd6b1c969d328a18cdc26b818717b39173f818210eb3be457b12f0df9d354718cf4175d12eab4d95d697d99b10e
@@ -11,13 +11,13 @@ jobs:
11
11
  cancel-in-progress: true
12
12
 
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - uses: ruby/setup-ruby@v1
16
16
  with:
17
- ruby-version: '3.0.3'
18
- - uses: actions/setup-node@v1
17
+ ruby-version: '3.2'
18
+ - uses: actions/setup-node@v2
19
19
  with:
20
- node-version: '14'
20
+ node-version: '18'
21
21
  - name: Install ffmpeg
22
22
  run: |
23
23
  sudo apt update && sudo apt install ffmpeg
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-recorder (0.1.4)
4
+ test-recorder (0.1.5)
5
5
  activesupport
6
6
  selenium-devtools
7
7
  selenium-webdriver (>= 4.0)
@@ -9,36 +9,35 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.3)
12
+ activesupport (7.0.4)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
17
  activesupport-testing-metadata (0.1.0)
18
18
  activesupport (>= 4.0)
19
- childprocess (4.1.0)
20
19
  concurrent-ruby (1.1.10)
21
- debug (1.5.0)
22
- irb (>= 1.3.6)
23
- reline (>= 0.2.7)
24
- i18n (1.10.0)
20
+ debug (1.7.1)
21
+ irb (>= 1.5.0)
22
+ reline (>= 0.3.1)
23
+ i18n (1.12.0)
25
24
  concurrent-ruby (~> 1.0)
26
- io-console (0.5.11)
27
- irb (1.4.1)
25
+ io-console (0.6.0)
26
+ irb (1.6.2)
28
27
  reline (>= 0.3.0)
29
- minitest (5.15.0)
28
+ minitest (5.17.0)
30
29
  rake (12.3.3)
31
- reline (0.3.1)
30
+ reline (0.3.2)
32
31
  io-console (~> 0.5)
33
32
  rexml (3.2.5)
34
33
  rubyzip (2.3.2)
35
- selenium-devtools (0.101.0)
36
- websocket (~> 1.0)
37
- selenium-webdriver (4.1.0)
38
- childprocess (>= 0.5, < 5.0)
34
+ selenium-devtools (0.109.0)
35
+ selenium-webdriver (~> 4.2)
36
+ selenium-webdriver (4.7.1)
39
37
  rexml (~> 3.2, >= 3.2.5)
40
- rubyzip (>= 1.2.2)
41
- tzinfo (2.0.4)
38
+ rubyzip (>= 1.2.2, < 3.0)
39
+ websocket (~> 1.0)
40
+ tzinfo (2.0.5)
42
41
  concurrent-ruby (~> 1.0)
43
42
  websocket (1.2.9)
44
43
 
@@ -53,4 +52,4 @@ DEPENDENCIES
53
52
  test-recorder!
54
53
 
55
54
  BUNDLED WITH
56
- 2.2.32
55
+ 2.4.3
data/README.md CHANGED
@@ -5,6 +5,7 @@ Record a video automatically when tests failed. The videos are generated in `tmp
5
5
  [![Build Status](https://github.com/y-yagi/test-recorder/workflows/CI/badge.svg)](https://github.com/y-yagi/test-recorder/actions)
6
6
  [![Gem Version](https://badge.fury.io/rb/test-recorder.svg)](http://badge.fury.io/rb/test-recorder)
7
7
 
8
+ This gem was inspired by [Record video feature of Playwright](https://playwright.dev/docs/videos).
8
9
 
9
10
  ## Requirements
10
11
 
@@ -1,10 +1,13 @@
1
+ require "open3"
1
2
  require "fileutils"
3
+ require "tempfile"
2
4
 
3
5
  module TestRecorder
4
6
  class CdpRecorder
5
7
  def initialize(enabled:)
6
8
  @enabled = enabled
7
- @tmpdir = nil
9
+ @started = nil
10
+ @page = nil
8
11
  setup
9
12
  end
10
13
 
@@ -15,21 +18,20 @@ module TestRecorder
15
18
 
16
19
  def start(page:, enabled: nil)
17
20
  enabled = @enabled if enabled.nil?
18
- return unless enabled
21
+ @started = enabled
22
+ return unless @started
19
23
 
20
- @tmpdir = Dir.mktmpdir("testrecorder")
21
- counter = 1
24
+ @tmp_video = Tempfile.open(["testrecorder", ".webm"])
25
+ 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}"
26
+ @stdin, @wait_thrs = *Open3.pipeline_w(cmd)
27
+ @stdin.set_encoding("ASCII-8BIT")
22
28
 
23
29
  @page = page
24
30
  @page.driver.browser.devtools.page.enable
25
31
 
26
32
  @page.driver.browser.devtools.page.on(:screencast_frame) do |event|
27
33
  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
32
- end
34
+ @stdin.print(decoded_data) rescue nil
33
35
  @page.driver.browser.devtools.page.screencast_frame_ack(session_id: event["sessionId"])
34
36
  end
35
37
 
@@ -37,25 +39,24 @@ module TestRecorder
37
39
  end
38
40
 
39
41
  def stop_and_discard
40
- FileUtils.rm_rf(@tmpdir) unless @tmpdir.nil?
42
+ if @started
43
+ @page.driver.browser.devtools.page.stop_screencast
44
+ @stdin.close
45
+ end
41
46
  end
42
47
 
43
48
  def stop_and_save(filename)
44
- return if @tmpdir.nil? || @page.nil?
49
+ return "" unless @started
45
50
 
46
51
  @page.driver.browser.devtools.page.stop_screencast
52
+ @stdin.close
53
+ @wait_thrs.each(&:join)
54
+
47
55
  video_path = File.join(@video_dir, filename)
56
+ FileUtils.copy(@tmp_video.path, video_path)
57
+ @tmp_video.close(true)
48
58
 
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
59
  video_path
55
- rescue => e
56
- $stderr.puts("[TestRecorder] ffmpeg failed: #{e.message}")
57
- ensure
58
- FileUtils.rm_rf(@tmpdir)
59
60
  end
60
61
  end
61
62
  end
@@ -13,7 +13,7 @@ module TestRecorder
13
13
  if failures.empty?
14
14
  @cdp_recorder.stop_and_discard
15
15
  else
16
- video_path = @cdp_recorder.stop_and_save("failures_#{self.name}.mp4")
16
+ video_path = @cdp_recorder.stop_and_save("failures_#{self.name}.webm")
17
17
  puts "[Video]: #{video_path}" if File.exist?(video_path)
18
18
  end
19
19
  ensure
@@ -10,7 +10,7 @@ module TestRecorder
10
10
 
11
11
  def after_failed_example(example)
12
12
  if example.exception
13
- video_path = cdp_recorder.stop_and_save("failures_#{method_name(example)}.mp4").to_s
13
+ video_path = cdp_recorder.stop_and_save("failures_#{method_name(example)}.webm").to_s
14
14
  if File.exist?(video_path)
15
15
  example.metadata[:extra_failure_lines] = [example.metadata[:extra_failure_lines], "[Video]: #{video_path}"].flatten
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module TestRecorder
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.4
4
+ version: 0.1.5
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-05-11 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.2.32
114
+ rubygems_version: 3.4.1
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Automatically record videos when tests failed.