Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for mjpeg and recording screen #164

Merged
merged 6 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Read `release_notes.md` for commit level details.
opts = { desired_capabilities: { }, appium_lib: { } }
@driver = Appium::Core.for(opts).start_driver
```
- Update `start_recording_screen` for iOS, Appium 1.10.0
- Add `:video_scale` and update `:video_type`

### Bug fixes

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

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/android/uiautomator2/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Uiautomator2
module Device
extend Forwardable

# @since 1.6.0
# @since Appium 1.6.0
# @!method battery_info
#
# Get battery information.
Expand Down
6 changes: 6 additions & 0 deletions lib/appium_lib_core/common/base/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
#
# @example
#
# # iOS
# @driver.start_recording_screen video_type: 'libx264'
# @driver.stop_and_save_recording_screen 'example.mp4' # Video type `libx264` can be play as `.mp4` video
#
# # Android
# @driver.start_recording_screen
# @driver.stop_and_save_recording_screen 'example.mp4'
#
def stop_and_save_recording_screen(file_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base/screenshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def element_screenshot_as(element, format)
end
end

# @since 1.3.4
# @since Appium 1.3.4
# @!method save_viewport_screenshot
# Save screenshot except for status bar while `@driver.save_screenshot` save entire screen.
#
Expand Down
25 changes: 17 additions & 8 deletions lib/appium_lib_core/ios/xcuitest/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ module Device
# @driver.background_app(-1) #=> the app never come back. https://github.com/appium/appium/issues/7741
#

# @!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')
# @since Appium 1.9.1
# @!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')
#
# Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11
# (ffmpeg utility is required: 'brew install ffmpeg').
# We would recommend to play the video by VLC or Mplayer if you can not play the video with other video players.
#
# @param [String] remote_path: The path to the remote location, where the resulting video should be uploaded.
# The following protocols are supported: http/https, ftp.
# Null or empty string value (the default setting) means the content of resulting
Expand All @@ -51,21 +57,24 @@ module Device
# @param [Boolean] force_restart: Whether to try to catch and upload/return the currently running screen recording
# (`false`, the default setting on server) or ignore the result of it
# and start a new recording immediately (`true`).
# @param [String] video_type: The format of the screen capture to be recorded.
# Available formats: "h264", "mp4" or "fmp4". Default is "mp4".
# Only works for Simulator.
# @param [String] video_type: The video codec type used for encoding of the be recorded screen capture.
# Execute `ffmpeg -codecs` in the terminal to see the list of supported video codecs.
# 'mjpeg' by default.
# @param [String] time_limit: Recording time. 180 seconds is by default.
# @param [String] video_quality: The video encoding quality (low, medium, high, photo - defaults to medium).
# @param [String] video_fps: The Frames Per Second rate of the recorded video. Change this value if the resulting video
# is too slow or too fast. Defaults to 10. This can decrease the resulting file size.
# @param [String] video_scale: The scaling value to apply. Read https://trac.ffmpeg.org/wiki/Scaling for possible values.
# No scale is applied by default.
#
# @example
#
# @driver.start_recording_screen
# @driver.start_recording_screen video_type: 'h264', time_limit: '260'
# @driver.start_recording_screen video_type: 'mjpeg', time_limit: '260'
# @driver.start_recording_screen video_type: 'libx264', time_limit: '260' # Can get `.mp4` video
#

# @since 1.3.4
# @since Appium 1.3.4
# @!method start_performance_record(timeout: 300000, profile_name: 'Activity Monitor')
#
# This is a blocking application.
Expand All @@ -88,7 +97,7 @@ module Device
# @driver.start_performance_record(timeout: 300000, profile_name: 'Activity Monitor')
#

# @since 1.3.4
# @since Appium 1.3.4
# @!method get_performance_record(save_file_path: './performance', profile_name: 'Activity Monitor', remote_path: nil, user: nil, pass: nil, method: 'PUT')
#
# This is a blocking application.
Expand All @@ -115,7 +124,7 @@ module Device
# @driver.get_performance_record
# @driver.get_performance_record(save_file_path: './performance', profile_name: 'Activity Monitor')

# @since 1.6.0
# @since Appium 1.6.0
# @!method battery_info
#
# Get battery information.
Expand Down
5 changes: 4 additions & 1 deletion lib/appium_lib_core/ios/xcuitest/device/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ def self.add_methods
::Appium::Core::Device.add_endpoint_method(:start_recording_screen) do
# rubocop:disable Metrics/ParameterLists
def start_recording_screen(remote_path: nil, user: nil, pass: nil, method: nil, force_restart: nil,
video_type: 'mp4', time_limit: '180', video_quality: 'medium', video_fps: nil)
video_type: 'mjpeg', time_limit: '180', video_quality: 'medium',
video_fps: nil, video_scale: nil)
option = ::Appium::Core::Base::Device::ScreenRecord.new(
remote_path: remote_path, user: user, pass: pass, method: method, force_restart: force_restart
).upload_option

option[:videoType] = video_type
option[:timeLimit] = time_limit
option[:videoQuality] = video_quality

option[:videoFps] = video_fps unless video_fps.nil?
option[:videoScale] = video_scale unless video_scale.nil?

execute(:start_recording_screen, {}, { options: option })
end
Expand Down
30 changes: 30 additions & 0 deletions test/functional/android/android/mjpeg_server_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'test_helper'

# $ rake test:func:ios TEST=test/functional/android/android/mjpeg_server_test.rb
# rubocop:disable Style/ClassVars
class AppiumLibCoreTest
module Android
class MjpegServerTest < AppiumLibCoreTest::Function::TestCase
def setup
@@core ||= ::Appium::Core.for(Caps.android)
@@driver ||= @@core.start_driver
end

def teardown
save_reports(@@driver)
end

def test_start_recording_screen
to_path = 'recorded_file_android.mp4'
File.delete to_path if File.exist? to_path

@@driver.start_recording_screen time_limit: '2'
@@driver.find_element(:accessibility_id, 'App').click
sleep 2 # second
@@driver.stop_and_save_recording_screen to_path
assert File.exist? to_path
end
end
end
end
# rubocop:enable Style/ClassVars
12 changes: 12 additions & 0 deletions test/functional/ios/ios/mjpeg_server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ def test_config
@@driver.update_settings({ mjpegServerScreenshotQuality: -10, mjpegServerFramerate: 60 })
@@driver.update_settings({ mjpegServerScreenshotQuality: 100, mjpegServerFramerate: 60 })
end

def test_start_recording_screen
to_path = 'recorded_file_ios.avi'
File.delete to_path if File.exist? to_path

@@driver.start_recording_screen video_type: 'mjpeg'
@@driver.find_element(:accessibility_id, 'Buttons').click
sleep 2 # second
@@driver.back
@@driver.stop_and_save_recording_screen to_path
assert File.exist? to_path
end
end
end
end
Expand Down
12 changes: 7 additions & 5 deletions test/unit/ios/device/mjsonwp/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_toggle_touch_id_enrollment

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

@driver.start_recording_screen
Expand All @@ -46,21 +46,23 @@ def test_start_recording_screen

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

@driver.start_recording_screen video_type: 'h265', time_limit: '60'
@driver.start_recording_screen video_type: 'libx264', time_limit: '60', video_scale: '320:240'

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

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

@driver.start_recording_screen video_type: 'h265', time_limit: '60', force_restart: true
@driver.start_recording_screen video_type: 'libx264', time_limit: '60', force_restart: true

assert_requested(:post, "#{SESSION}/appium/start_recording_screen", times: 1)
end
Expand Down
8 changes: 5 additions & 3 deletions test/unit/ios/device/w3c/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_toggle_touch_id_enrollment

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

@driver.start_recording_screen
Expand All @@ -44,10 +44,12 @@ def test_start_recording_screen

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

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

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