mobile-emulator-screencapture 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc0449def559a85389fd5d0fbe0b60671bab7da1fa58920f85e35d364dd52782
4
+ data.tar.gz: a5a7cf70881b017dc4f23cdcc918df3614b122e55f773da5f17cd4e497ed9037
5
+ SHA512:
6
+ metadata.gz: df46951b4ed41f4cf886f81fd35bb674a7dd5b0c55b4312cd9a7730a447c113cf410e264921ed31563a627d44ae27b9affee7e44d22936fc66b8f2769088a937
7
+ data.tar.gz: 07b3b44e00462530d67d4396064cc74017d190ae8f9c47d3f9fffb42eb3f5147002ed8a7145df4bc567b9b2d25c9986ecd5fd9e6b482a6559df1c653b0c2b675
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+
11
+ # Created by https://www.gitignore.io/api/macos
12
+
13
+ ### macOS ###
14
+ *.DS_Store
15
+ .AppleDouble
16
+ .LSOverride
17
+
18
+ # Icon must end with two \r
19
+ Icon
20
+
21
+ # Thumbnails
22
+ ._*
23
+
24
+ # Files that might appear in the root of a volume
25
+ .DocumentRevisions-V100
26
+ .fseventsd
27
+ .Spotlight-V100
28
+ .TemporaryItems
29
+ .Trashes
30
+ .VolumeIcon.icns
31
+ .com.apple.timemachine.donotpresent
32
+
33
+ # Directories potentially created on remote AFP share
34
+ .AppleDB
35
+ .AppleDesktop
36
+ Network Trash Folder
37
+ Temporary Items
38
+ .apdisk
39
+
40
+
41
+ # End of https://www.gitignore.io/api/macos
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ Style/FrozenStringLiteralComment:
4
+ Enabled: false
5
+ Style/StringLiterals:
6
+ Enabled: false
7
+ Metrics/LineLength:
8
+ Enabled: false
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/ClassAndModuleChildren:
13
+ Enabled: true
14
+ Exclude:
15
+ - test/**/*
16
+ Metrics/MethodLength:
17
+ Enabled: true
18
+ Exclude:
19
+ - test/**/*
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ os:
4
+ - linux
5
+ - osx
6
+ rvm:
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mobile-emulator-screencapture.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mobile-emulator-screencapture (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ metaclass (0.0.4)
11
+ minitest (5.11.3)
12
+ mocha (1.3.0)
13
+ metaclass (~> 0.0.1)
14
+ parallel (1.12.1)
15
+ parser (2.5.0.4)
16
+ ast (~> 2.4.0)
17
+ powerpack (0.1.1)
18
+ rainbow (3.0.0)
19
+ rake (10.5.0)
20
+ rubocop (0.53.0)
21
+ parallel (~> 1.10)
22
+ parser (>= 2.5)
23
+ powerpack (~> 0.1)
24
+ rainbow (>= 2.2.2, < 4.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (~> 1.0, >= 1.0.1)
27
+ ruby-progressbar (1.9.0)
28
+ unicode-display_width (1.3.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ minitest
36
+ mobile-emulator-screencapture!
37
+ mocha
38
+ rake (~> 10.0)
39
+ rubocop
40
+
41
+ BUNDLED WITH
42
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kenta Kase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Mobile::Emulator::Screencapture
2
+
3
+ Ruby wrapper for take screenshot and screenrecord on ios/android emulators.
4
+
5
+ ## How to work
6
+ ### Android
7
+ Using `adb screencap` and `adb screenrecord`
8
+ see: https://developer.android.com/studio/command-line/adb.html
9
+
10
+ `adb screenrcord` is only supported: Android >= 4.4(API Level 19)
11
+
12
+ ### iOS
13
+ **Not supported yet**
14
+
15
+ Using `xcrun simctl io screenshot` and `xcrun simctl io recordVideo`
16
+
17
+ see: `xcrun simctl io --help`
18
+
19
+ `xcrun simctl io screenshot` is only supported: Xcode >= 8.2
20
+
21
+ ## Installation
22
+
23
+ ```ruby
24
+ gem 'mobile-emulator-screencapture'
25
+ ```
26
+
27
+ ## Usage
28
+ ### Android
29
+
30
+ ```ruby
31
+ require 'mobile/emulator/screencapture'
32
+
33
+ android = Mobile::Emulator::Screencapture.create(
34
+ platform: "android",
35
+ screenshot_dir: "./screenshot",
36
+ screenrecord_dir: "./screenrecord",
37
+
38
+ # options for adb screenrecord
39
+ width: 720,
40
+ height: 360
41
+ bit_rate: 6_000_000,
42
+ time_limit: 180
43
+ )
44
+
45
+ android.screenshot("test")
46
+ # > ./screenshot/test.png
47
+
48
+ android.start_screenrecord("test")
49
+ sleep 30
50
+ android.stop_screenrecord
51
+ # > ./screenrecord/test.mp4
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Kesin11/mobile-emulator-screencapture.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require 'rubocop/rake_task'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ end
10
+
11
+ RuboCop::RakeTask.new
12
+
13
+ task :lint_test do
14
+ Rake::Task['rubocop'].invoke
15
+ Rake::Task['test'].invoke
16
+ end
17
+
18
+ task default: :lint_test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mobile/emulator/screencapture"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ require "mobile/emulator/screencapture/version"
2
+ require "mobile/emulator/screencapture/android"
3
+ require "mobile/emulator/screencapture/ios"
4
+
5
+ module Mobile
6
+ module Emulator
7
+ module Screencapture
8
+ class << self
9
+ def create(**args)
10
+ if args[:platform] == "android"
11
+ Mobile::Emulator::Screencapture::Android.new(args)
12
+ elsif args[:platform] == "ios"
13
+ Mobile::Emulator::Screencapture::Ios.new(args)
14
+ else
15
+ raise "Not support platform: #{args[:platform]}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,98 @@
1
+ require 'mobile/emulator/screencapture/base'
2
+
3
+ module Mobile
4
+ module Emulator
5
+ module Screencapture
6
+ class Android < Base
7
+ DEVICE_SCREENSHOT_PATH = '/sdcard/screenshot.png'.freeze
8
+ DEVICE_SCREENRECORD_PATH = '/sdcard/screenrecord.mp4'.freeze
9
+
10
+ attr_reader :width, :height, :bit_rate, :time_limit
11
+ def initialize(**args)
12
+ super(args)
13
+ @width = args[:width]
14
+ @height = args[:height]
15
+ @bit_rate = args[:bit_rate]
16
+ @time_limit = args[:time_limit]
17
+
18
+ @screenrecord_path = nil
19
+ end
20
+
21
+ def screenshot(image_name)
22
+ raise "Argument image_name is nil" if image_name.nil?
23
+
24
+ screenshot_path = File.join(@screenshot_dir, "#{image_name}.png")
25
+ _native_screenshot
26
+ _pull_screenshot(screenshot_path)
27
+
28
+ screenshot_path
29
+ end
30
+
31
+ def start_screenrecord(video_name)
32
+ raise "Argument video_name is nil" if video_name.nil?
33
+ raise "Screenrecord process already started. pid: #{@screenrecord_pid}" if @screenrecord_pid
34
+
35
+ @screenrecord_path = File.join(@screenrecord_dir, "#{video_name}.mp4")
36
+ @screenrecord_pid = _native_start_screenrecord
37
+
38
+ @screenrecord_path
39
+ end
40
+
41
+ def stop_screenrecord
42
+ raise 'Any screenrecord process did not started' unless @screenrecord_pid
43
+ screenrecord_path = @screenrecord_path
44
+
45
+ _native_stop_screenrecord
46
+ _pull_screenrecord(screenrecord_path)
47
+
48
+ @screenrecord_pid = nil
49
+ @screenrecord_path = nil
50
+
51
+ screenrecord_path
52
+ end
53
+
54
+ private
55
+
56
+ def _adb(command)
57
+ `adb #{command}`
58
+ end
59
+
60
+ def _adb_spawn(command)
61
+ pid = spawn("adb #{command}", out: '/dev/null')
62
+ Process.detach(pid)
63
+ pid
64
+ end
65
+
66
+ def _native_screenshot
67
+ _adb("shell screencap #{DEVICE_SCREENSHOT_PATH}")
68
+ end
69
+
70
+ def _pull_screenshot(screenshot_path)
71
+ _adb("pull #{DEVICE_SCREENSHOT_PATH} #{screenshot_path}")
72
+ _adb("shell rm #{DEVICE_SCREENSHOT_PATH}")
73
+ end
74
+
75
+ def _native_start_screenrecord
76
+ command = ["shell screenrecord #{DEVICE_SCREENRECORD_PATH}"]
77
+ command << "--size #{@width}x#{@height}" if @width && @height
78
+ command << "--bit-rate #{@bit_rate}" if @bit_rate
79
+ command << "--time-limit #{@time_limit}" if @time_limit
80
+ _adb_spawn(command.join(' '))
81
+ end
82
+
83
+ def _native_stop_screenrecord
84
+ killed_process_num = Process.kill('SIGINT', @screenrecord_pid)
85
+ raise "Kill pid: #{@screenrecord_pid} did not end correctly." unless killed_process_num.positive?
86
+
87
+ # If 'adb pull' after kill recording process soon, the video will be broken.
88
+ sleep 2
89
+ end
90
+
91
+ def _pull_screenrecord(screenrecord_path)
92
+ _adb("pull #{DEVICE_SCREENRECORD_PATH} #{screenrecord_path}")
93
+ _adb("shell rm #{DEVICE_SCREENRECORD_PATH}")
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+
3
+ module Mobile
4
+ module Emulator
5
+ module Screencapture
6
+ class Base
7
+ attr_reader :screenshot_dir, :screenrecord_dir
8
+ def initialize(**args)
9
+ @screenshot_dir = args[:screenshot_dir] || Bundler.root
10
+ @screenrecord_dir = args[:screenrecord_dir] || Bundler.root
11
+
12
+ @screenrecord_pid = nil
13
+
14
+ FileUtils.mkdir_p(@screenshot_dir)
15
+ FileUtils.mkdir_p(@screenrecord_dir)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'mobile/emulator/screencapture/base'
2
+
3
+ module Mobile
4
+ module Emulator
5
+ module Screencapture
6
+ class Ios < Base
7
+ def initialize(**args)
8
+ super(args)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Mobile
2
+ module Emulator
3
+ module Screencapture
4
+ VERSION = "0.1.0".freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mobile/emulator/screencapture/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobile-emulator-screencapture"
8
+ spec.version = Mobile::Emulator::Screencapture::VERSION
9
+ spec.authors = ["Kenta Kase"]
10
+ spec.email = ["kesin1202000@gmail.com"]
11
+
12
+ spec.summary = 'Ruby wrapper for ios/android screen capture'
13
+ spec.description = 'Ruby wrapper for ios/android screen capture using simctl/adb screenshot/screenrecord.'
14
+ spec.homepage = "https://github.com/Kesin11/mobile-emulator-screencapture"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "mocha"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rubocop"
29
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobile-emulator-screencapture
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenta Kase
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper for ios/android screen capture using simctl/adb screenshot/screenrecord.
84
+ email:
85
+ - kesin1202000@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/mobile/emulator/screencapture.rb
101
+ - lib/mobile/emulator/screencapture/android.rb
102
+ - lib/mobile/emulator/screencapture/base.rb
103
+ - lib/mobile/emulator/screencapture/ios.rb
104
+ - lib/mobile/emulator/screencapture/version.rb
105
+ - mobile-emulator-screencapture.gemspec
106
+ homepage: https://github.com/Kesin11/mobile-emulator-screencapture
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.5
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ruby wrapper for ios/android screen capture
130
+ test_files: []