Skip to content

Commit 3a9bebd

Browse files
committed
Add keyevent method
1 parent 758afbf commit 3a9bebd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

android_tests/lib/android/specs/common/device.rb

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
act.class.must_equal Selenium::WebDriver::Element
6565
end
6666

67+
t 'keyevent' do
68+
keyevent key: 176
69+
end
70+
6771
t 'action_chain' do
6872
e = find_element(:name, "Accessibility")
6973
Appium::TouchAction.new.press(:element => e, x: 0.5, y: 0.5).release(:element => e).perform

lib/appium_lib/device/device.rb

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ module Device
6262
# hide_keyboard('Finished') # Close a keyboard with the 'Finished' button
6363
# ```
6464

65+
# @!method key_event
66+
# Send a key event to the device.
67+
# @param key (integer) The key to send.
68+
# @param metastate (String) The state the metakeys should be in when sending the key.
69+
6570
# @!method push_file
6671
# Place a file in a specific location on the device.
6772
# @param path (String) The absolute path on the device to store data at.
@@ -126,6 +131,14 @@ def hide_keyboard(close_key='Done')
126131
end
127132
end
128133

134+
add_endpoint_method(:key_event, 'session/:session_id/appium/device/keyevent') do
135+
def key_event(key, metastate=nil)
136+
args = {keycode: key}
137+
args[:metastate] = metastate if metastate
138+
execute :key_event, {}, args
139+
end
140+
end
141+
129142
add_endpoint_method(:complex_find, 'session/:session_id/appium/app/complex_find') do
130143
def complex_find(all, selectors=nil)
131144
if selectors.nil?

0 commit comments

Comments
 (0)