Skip to content

Commit cdb02c2

Browse files
committed
add screen record commands
1 parent 0f5ecee commit cdb02c2

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

lib/appium_lib_core/android/device.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ module Device
7777
# @driver.get_performance_data package_name: package_name, data_type: data_type, data_read_timeout: 2
7878
#
7979

80+
# @!method start_recording_screen(package_name:, data_type:, data_read_timeout: 1000)
81+
# Record the display of devices running Android 4.4 (API level 19) and higher.
82+
# It records screen activity to an MPEG-4 file. Audio is not recorded with the video file.
83+
# @param [String] file_path A path to save the video. `/sdcard/default.mp4` is by default.
84+
# @param [String] video_size A video size. '1280x720' is by default.
85+
# @param [String] time_limit Recording time. 180 second is by default.
86+
# @param [String] bit_rate The video bit rate for the video, in megabits per second. 3000000(3Mbps) is by default.
87+
#
88+
# @example
89+
#
90+
# @driver.start_recording_screen file_path: '/sdcard/default.mp4', video_size: '1280x720', time_limit: '180', bit_rate: '3000000'
91+
#
92+
93+
# @!method stop_recording_screen
94+
# Stop recording the screen.
95+
#
96+
# @example
97+
#
98+
# @driver.stop_recording_screen
99+
#
100+
80101
####
81102
## class << self
82103
####
@@ -138,6 +159,12 @@ def get_performance_data(package_name:, data_type:, data_read_timeout: 1000)
138159
dataReadTimeout: data_read_timeout
139160
end
140161
end
162+
163+
Appium::Core::Device.add_endpoint_method(:start_recording_screen) do
164+
def start_recording_screen(file_path: '/sdcard/default.mp4', video_size: '1280x720', time_limit: '180', bit_rate: '3000000')
165+
execute :start_recording_screen, {}, filePath: file_path, videoSize: video_size, timeLimit: time_limit, bitRate: bit_rate
166+
end
167+
end
141168
end
142169
end
143170
end # module Device

lib/appium_lib_core/common/command.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Commands
2525
is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'.freeze],
2626
get_network_connection: [:get, 'session/:session_id/network_connection'.freeze],
2727
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze],
28-
28+
stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'.freeze]
2929
# iOS
3030
}.freeze
3131

@@ -58,7 +58,8 @@ module Commands
5858
start_activity: [:post, 'session/:session_id/appium/device/start_activity'.freeze],
5959
end_coverage: [:post, 'session/:session_id/appium/app/end_test_coverage'.freeze],
6060
set_network_connection: [:post, 'session/:session_id/network_connection'.freeze],
61-
get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'.freeze]
61+
get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'.freeze],
62+
start_recording_screen: [:post, 'session/:session_id/appium/start_recording_screen'.freeze]
6263
}.freeze
6364

6465
COMMAND_IOS = {

test/functional/android/android/device_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,12 @@ def test_open_notifications
230230
@@driver.open_notifications
231231
# shouldn't see the elements behind shade
232232

233-
assert_raises Selenium::WebDriver::Error::NoSuchElementError do
234-
@@driver.find_element :accessibility_id, ':-|'
235-
end
233+
# Sometimes, we should wait animation
234+
@@core.wait {
235+
assert_raises Selenium::WebDriver::Error::NoSuchElementError do
236+
@@driver.find_element :accessibility_id, ':-|'
237+
end
238+
}
236239

237240
# should see the notification
238241
@@core.wait_true { text 'Mood ring' }

test/functional/android/webdriver/device_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_dismiss_alert
7676
# assert @@driver.switch_to.alert.text.start_with?('Lorem ipsum dolor sit aie consectetur')
7777
# assert @@driver.switch_to.alert.dismiss
7878

79-
assert_equal 'Cancel', @@driver.find_element(:id, 'android:id/button2').name
79+
assert_equal 'CANCEL', @@driver.find_element(:id, 'android:id/button2').name
8080
assert @@driver.find_element(:id, 'android:id/button2').click
8181
end
8282

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Caps
3232
platformName: :android,
3333
automationName: 'uiautomator2',
3434
app: 'test/functional/app/api.apk',
35-
platformVersion: '7.1.1',
35+
platformVersion: '6.0',
3636
deviceName: 'Android Emulator',
3737
appPackage: 'io.appium.android.apis',
3838
appActivity: 'io.appium.android.apis.ApiDemos',

test/unit/android/device_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ def test_get_performance_data_types
227227
assert_requested(:post, "#{SESSION}/appium/performanceData/types", times: 1)
228228
end
229229

230+
def test_stop_recording_screen
231+
stub_request(:post, "#{SESSION}/appium/stop_recording_screen")
232+
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
233+
234+
@driver.stop_recording_screen
235+
236+
assert_requested(:post, "#{SESSION}/appium/stop_recording_screen", times: 1)
237+
end
238+
230239
## with args
231240

232241
def test_available_contexts
@@ -444,6 +453,15 @@ def test_get_perfoemance_data
444453

445454
assert_requested(:post, "#{SESSION}/appium/getPerformanceData", times: 1)
446455
end
456+
457+
def test_start_recording_screen
458+
stub_request(:post, "#{SESSION}/appium/start_recording_screen")
459+
.to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json)
460+
461+
@driver.start_recording_screen
462+
463+
assert_requested(:post, "#{SESSION}/appium/start_recording_screen", times: 1)
464+
end
447465
end
448466
end
449467
end

0 commit comments

Comments
 (0)