Skip to content

Commit

Permalink
add screen record commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Nov 3, 2017
1 parent 0f5ecee commit cdb02c2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
27 changes: 27 additions & 0 deletions lib/appium_lib_core/android/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ module Device
# @driver.get_performance_data package_name: package_name, data_type: data_type, data_read_timeout: 2
#

# @!method start_recording_screen(package_name:, data_type:, data_read_timeout: 1000)
# Record the display of devices running Android 4.4 (API level 19) and higher.
# It records screen activity to an MPEG-4 file. Audio is not recorded with the video file.
# @param [String] file_path A path to save the video. `/sdcard/default.mp4` is by default.
# @param [String] video_size A video size. '1280x720' is by default.
# @param [String] time_limit Recording time. 180 second is by default.
# @param [String] bit_rate The video bit rate for the video, in megabits per second. 3000000(3Mbps) is by default.
#
# @example
#
# @driver.start_recording_screen file_path: '/sdcard/default.mp4', video_size: '1280x720', time_limit: '180', bit_rate: '3000000'
#

# @!method stop_recording_screen
# Stop recording the screen.
#
# @example
#
# @driver.stop_recording_screen
#

####
## class << self
####
Expand Down Expand Up @@ -138,6 +159,12 @@ def get_performance_data(package_name:, data_type:, data_read_timeout: 1000)
dataReadTimeout: data_read_timeout
end
end

Appium::Core::Device.add_endpoint_method(:start_recording_screen) do
def start_recording_screen(file_path: '/sdcard/default.mp4', video_size: '1280x720', time_limit: '180', bit_rate: '3000000')
execute :start_recording_screen, {}, filePath: file_path, videoSize: video_size, timeLimit: time_limit, bitRate: bit_rate
end
end
end
end
end # module Device
Expand Down
5 changes: 3 additions & 2 deletions lib/appium_lib_core/common/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Commands
is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'.freeze],
get_network_connection: [:get, 'session/:session_id/network_connection'.freeze],
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze],

stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'.freeze]
# iOS
}.freeze

Expand Down Expand Up @@ -58,7 +58,8 @@ module Commands
start_activity: [:post, 'session/:session_id/appium/device/start_activity'.freeze],
end_coverage: [:post, 'session/:session_id/appium/app/end_test_coverage'.freeze],
set_network_connection: [:post, 'session/:session_id/network_connection'.freeze],
get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'.freeze]
get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'.freeze],
start_recording_screen: [:post, 'session/:session_id/appium/start_recording_screen'.freeze]
}.freeze

COMMAND_IOS = {
Expand Down
9 changes: 6 additions & 3 deletions test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ def test_open_notifications
@@driver.open_notifications
# shouldn't see the elements behind shade

assert_raises Selenium::WebDriver::Error::NoSuchElementError do
@@driver.find_element :accessibility_id, ':-|'
end
# Sometimes, we should wait animation
@@core.wait {
assert_raises Selenium::WebDriver::Error::NoSuchElementError do
@@driver.find_element :accessibility_id, ':-|'
end
}

# should see the notification
@@core.wait_true { text 'Mood ring' }
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/webdriver/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_dismiss_alert
# assert @@driver.switch_to.alert.text.start_with?('Lorem ipsum dolor sit aie consectetur')
# assert @@driver.switch_to.alert.dismiss

assert_equal 'Cancel', @@driver.find_element(:id, 'android:id/button2').name
assert_equal 'CANCEL', @@driver.find_element(:id, 'android:id/button2').name
assert @@driver.find_element(:id, 'android:id/button2').click
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Caps
platformName: :android,
automationName: 'uiautomator2',
app: 'test/functional/app/api.apk',
platformVersion: '7.1.1',
platformVersion: '6.0',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis',
appActivity: 'io.appium.android.apis.ApiDemos',
Expand Down
18 changes: 18 additions & 0 deletions test/unit/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ def test_get_performance_data_types
assert_requested(:post, "#{SESSION}/appium/performanceData/types", times: 1)
end

def test_stop_recording_screen
stub_request(:post, "#{SESSION}/appium/stop_recording_screen")
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)

@driver.stop_recording_screen

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

## with args

def test_available_contexts
Expand Down Expand Up @@ -444,6 +453,15 @@ def test_get_perfoemance_data

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

def test_start_recording_screen
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)

@driver.start_recording_screen

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

0 comments on commit cdb02c2

Please sign in to comment.