Skip to content

Commit e1d6b11

Browse files
authored
Add tests for mjpeg and recording screen (#164)
* add tests for screen recording in functionality * tweak test cases * fix rubocop * tweak a test scenario * tweak android scenario * update changelog
1 parent 8042627 commit e1d6b11

File tree

10 files changed

+86
-20
lines changed

10 files changed

+86
-20
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Read `release_notes.md` for commit level details.
1414
opts = { desired_capabilities: { }, appium_lib: { } }
1515
@driver = Appium::Core.for(opts).start_driver
1616
```
17+
- Update `start_recording_screen` for iOS, Appium 1.10.0
18+
- Add `:video_scale` and update `:video_type`
1719

1820
### Bug fixes
1921

@@ -29,7 +31,7 @@ Read `release_notes.md` for commit level details.
2931
# 2
3032
Appium::Core.for caps: {...}, appium_lib: {...}
3133
```
32-
- Add `videoFps` param for screen recording in iOS(XCUITest) to sync with Appium 1.9.2
34+
- Add `:video_fps` param for screen recording in iOS(XCUITest) to sync with Appium 1.10.0
3335

3436
### Bug fixes
3537

lib/appium_lib_core/android/uiautomator2/device.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Uiautomator2
77
module Device
88
extend Forwardable
99

10-
# @since 1.6.0
10+
# @since Appium 1.6.0
1111
# @!method battery_info
1212
#
1313
# Get battery information.

lib/appium_lib_core/common/base/driver.rb

+6
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
583583
#
584584
# @example
585585
#
586+
# # iOS
587+
# @driver.start_recording_screen video_type: 'libx264'
588+
# @driver.stop_and_save_recording_screen 'example.mp4' # Video type `libx264` can be play as `.mp4` video
589+
#
590+
# # Android
591+
# @driver.start_recording_screen
586592
# @driver.stop_and_save_recording_screen 'example.mp4'
587593
#
588594
def stop_and_save_recording_screen(file_path)

lib/appium_lib_core/common/base/screenshot.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def element_screenshot_as(element, format)
7878
end
7979
end
8080

81-
# @since 1.3.4
81+
# @since Appium 1.3.4
8282
# @!method save_viewport_screenshot
8383
# Save screenshot except for status bar while `@driver.save_screenshot` save entire screen.
8484
#

lib/appium_lib_core/ios/xcuitest/device.rb

+17-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ module Device
3636
# @driver.background_app(-1) #=> the app never come back. https://github.com/appium/appium/issues/7741
3737
#
3838

39-
# @!method start_recording_screen(remote_path: nil, user: nil, pass: nil, method: nil, force_restart: nil, video_type: 'mp4', time_limit: '180', video_quality: 'medium')
39+
# @since Appium 1.9.1
40+
# @!method start_recording_screen(remote_path: nil, user: nil, pass: nil, method: nil, force_restart: nil, video_type: 'mjpeg', time_limit: '180', video_quality: 'medium', video_scale: '320:240')
41+
#
42+
# Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11
43+
# (ffmpeg utility is required: 'brew install ffmpeg').
44+
# We would recommend to play the video by VLC or Mplayer if you can not play the video with other video players.
45+
#
4046
# @param [String] remote_path: The path to the remote location, where the resulting video should be uploaded.
4147
# The following protocols are supported: http/https, ftp.
4248
# Null or empty string value (the default setting) means the content of resulting
@@ -51,21 +57,24 @@ module Device
5157
# @param [Boolean] force_restart: Whether to try to catch and upload/return the currently running screen recording
5258
# (`false`, the default setting on server) or ignore the result of it
5359
# and start a new recording immediately (`true`).
54-
# @param [String] video_type: The format of the screen capture to be recorded.
55-
# Available formats: "h264", "mp4" or "fmp4". Default is "mp4".
56-
# Only works for Simulator.
60+
# @param [String] video_type: The video codec type used for encoding of the be recorded screen capture.
61+
# Execute `ffmpeg -codecs` in the terminal to see the list of supported video codecs.
62+
# 'mjpeg' by default.
5763
# @param [String] time_limit: Recording time. 180 seconds is by default.
5864
# @param [String] video_quality: The video encoding quality (low, medium, high, photo - defaults to medium).
5965
# @param [String] video_fps: The Frames Per Second rate of the recorded video. Change this value if the resulting video
6066
# is too slow or too fast. Defaults to 10. This can decrease the resulting file size.
67+
# @param [String] video_scale: The scaling value to apply. Read https://trac.ffmpeg.org/wiki/Scaling for possible values.
68+
# No scale is applied by default.
6169
#
6270
# @example
6371
#
6472
# @driver.start_recording_screen
65-
# @driver.start_recording_screen video_type: 'h264', time_limit: '260'
73+
# @driver.start_recording_screen video_type: 'mjpeg', time_limit: '260'
74+
# @driver.start_recording_screen video_type: 'libx264', time_limit: '260' # Can get `.mp4` video
6675
#
6776

68-
# @since 1.3.4
77+
# @since Appium 1.3.4
6978
# @!method start_performance_record(timeout: 300000, profile_name: 'Activity Monitor')
7079
#
7180
# This is a blocking application.
@@ -88,7 +97,7 @@ module Device
8897
# @driver.start_performance_record(timeout: 300000, profile_name: 'Activity Monitor')
8998
#
9099

91-
# @since 1.3.4
100+
# @since Appium 1.3.4
92101
# @!method get_performance_record(save_file_path: './performance', profile_name: 'Activity Monitor', remote_path: nil, user: nil, pass: nil, method: 'PUT')
93102
#
94103
# This is a blocking application.
@@ -115,7 +124,7 @@ module Device
115124
# @driver.get_performance_record
116125
# @driver.get_performance_record(save_file_path: './performance', profile_name: 'Activity Monitor')
117126

118-
# @since 1.6.0
127+
# @since Appium 1.6.0
119128
# @!method battery_info
120129
#
121130
# Get battery information.

lib/appium_lib_core/ios/xcuitest/device/screen.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ def self.add_methods
88
::Appium::Core::Device.add_endpoint_method(:start_recording_screen) do
99
# rubocop:disable Metrics/ParameterLists
1010
def start_recording_screen(remote_path: nil, user: nil, pass: nil, method: nil, force_restart: nil,
11-
video_type: 'mp4', time_limit: '180', video_quality: 'medium', video_fps: nil)
11+
video_type: 'mjpeg', time_limit: '180', video_quality: 'medium',
12+
video_fps: nil, video_scale: nil)
1213
option = ::Appium::Core::Base::Device::ScreenRecord.new(
1314
remote_path: remote_path, user: user, pass: pass, method: method, force_restart: force_restart
1415
).upload_option
1516

1617
option[:videoType] = video_type
1718
option[:timeLimit] = time_limit
1819
option[:videoQuality] = video_quality
20+
1921
option[:videoFps] = video_fps unless video_fps.nil?
22+
option[:videoScale] = video_scale unless video_scale.nil?
2023

2124
execute(:start_recording_screen, {}, { options: option })
2225
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'test_helper'
2+
3+
# $ rake test:func:ios TEST=test/functional/android/android/mjpeg_server_test.rb
4+
# rubocop:disable Style/ClassVars
5+
class AppiumLibCoreTest
6+
module Android
7+
class MjpegServerTest < AppiumLibCoreTest::Function::TestCase
8+
def setup
9+
@@core ||= ::Appium::Core.for(Caps.android)
10+
@@driver ||= @@core.start_driver
11+
end
12+
13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
17+
def test_start_recording_screen
18+
to_path = 'recorded_file_android.mp4'
19+
File.delete to_path if File.exist? to_path
20+
21+
@@driver.start_recording_screen time_limit: '2'
22+
@@driver.find_element(:accessibility_id, 'App').click
23+
sleep 2 # second
24+
@@driver.stop_and_save_recording_screen to_path
25+
assert File.exist? to_path
26+
end
27+
end
28+
end
29+
end
30+
# rubocop:enable Style/ClassVars

test/functional/ios/ios/mjpeg_server_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ def test_config
2323
@@driver.update_settings({ mjpegServerScreenshotQuality: -10, mjpegServerFramerate: 60 })
2424
@@driver.update_settings({ mjpegServerScreenshotQuality: 100, mjpegServerFramerate: 60 })
2525
end
26+
27+
def test_start_recording_screen
28+
to_path = 'recorded_file_ios.avi'
29+
File.delete to_path if File.exist? to_path
30+
31+
@@driver.start_recording_screen video_type: 'mjpeg'
32+
@@driver.find_element(:accessibility_id, 'Buttons').click
33+
sleep 2 # second
34+
@@driver.back
35+
@@driver.stop_and_save_recording_screen to_path
36+
assert File.exist? to_path
37+
end
2638
end
2739
end
2840
end

test/unit/ios/device/mjsonwp/commands_test.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_toggle_touch_id_enrollment
3636

3737
def test_start_recording_screen
3838
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
39-
.with(body: { options: { videoType: 'mp4', timeLimit: '180', videoQuality: 'medium' } }.to_json)
39+
.with(body: { options: { videoType: 'mjpeg', timeLimit: '180', videoQuality: 'medium' } }.to_json)
4040
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
4141

4242
@driver.start_recording_screen
@@ -46,21 +46,23 @@ def test_start_recording_screen
4646

4747
def test_start_recording_screen_custom
4848
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
49-
.with(body: { options: { videoType: 'h265', timeLimit: '60', videoQuality: 'medium' } }.to_json)
49+
.with(body: { options: {
50+
videoType: 'libx264', timeLimit: '60', videoQuality: 'medium', videoScale: '320:240'
51+
} }.to_json)
5052
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
5153

52-
@driver.start_recording_screen video_type: 'h265', time_limit: '60'
54+
@driver.start_recording_screen video_type: 'libx264', time_limit: '60', video_scale: '320:240'
5355

5456
assert_requested(:post, "#{SESSION}/appium/start_recording_screen", times: 1)
5557
end
5658

5759
def test_start_recording_screen_custom_force
5860
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
5961
.with(body:
60-
{ options: { forceRestart: true, videoType: 'h265', timeLimit: '60', videoQuality: 'medium' } }.to_json)
62+
{ options: { forceRestart: true, videoType: 'libx264', timeLimit: '60', videoQuality: 'medium' } }.to_json)
6163
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
6264

63-
@driver.start_recording_screen video_type: 'h265', time_limit: '60', force_restart: true
65+
@driver.start_recording_screen video_type: 'libx264', time_limit: '60', force_restart: true
6466

6567
assert_requested(:post, "#{SESSION}/appium/start_recording_screen", times: 1)
6668
end

test/unit/ios/device/w3c/commands_test.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_toggle_touch_id_enrollment
3434

3535
def test_start_recording_screen
3636
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
37-
.with(body: { options: { videoType: 'mp4', timeLimit: '180', videoQuality: 'medium' } }.to_json)
37+
.with(body: { options: { videoType: 'mjpeg', timeLimit: '180', videoQuality: 'medium' } }.to_json)
3838
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
3939

4040
@driver.start_recording_screen
@@ -44,10 +44,12 @@ def test_start_recording_screen
4444

4545
def test_start_recording_screen_custom
4646
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
47-
.with(body: { options: { videoType: 'h265', timeLimit: '60', videoQuality: 'medium', videoFps: '50' } }.to_json)
47+
.with(body: { options: {
48+
videoType: 'libx264', timeLimit: '60', videoQuality: 'medium', videoFps: '50', videoScale: '320:240'
49+
} }.to_json)
4850
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
4951

50-
@driver.start_recording_screen video_type: 'h265', time_limit: '60', video_fps: '50'
52+
@driver.start_recording_screen video_type: 'libx264', time_limit: '60', video_fps: '50', video_scale: '320:240'
5153

5254
assert_requested(:post, "#{SESSION}/appium/start_recording_screen", times: 1)
5355
end

0 commit comments

Comments
 (0)