Skip to content

Commit 235e1c0

Browse files
Replace keyevent with press_keycode. Add long_press_keycode
Fix #203
1 parent 64d9db1 commit 235e1c0

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

android_tests/appium.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[caps]
22
platformName = "android"
3+
deviceName = "Nexus 7"
34
app = "./api.apk"
45
appPackage = "io.appium.android.apis"
56
appActivity = ".ApiDemos"

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ def must_return_element element
8989
back
9090
end
9191

92-
t 'key_event' do
93-
key_event 176
92+
t 'press_keycode' do
93+
# http://developer.android.com/reference/android/view/KeyEvent.html
94+
press_keycode 176
95+
end
96+
97+
t 'long_press_keycode' do
98+
# http://developer.android.com/reference/android/view/KeyEvent.html
99+
long_press_keycode 176
94100
end
95101

96102
t 'action_chain' do

lib/appium_lib/device/device.rb

+22-7
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,17 @@ module Device
6565
# hide_keyboard('Finished') # Close a keyboard with the 'Finished' button
6666
# ```
6767

68-
# @!method key_event
69-
# Send a key event to the device.
70-
# @param key (integer) The key to send.
71-
# @param metastate (String) The state the metakeys should be in when sending the key.
68+
# @!method press_keycode
69+
# Press keycode on the device.
70+
# http://developer.android.com/reference/android/view/KeyEvent.html
71+
# @param key (integer) The key to press.
72+
# @param metastate (String) The state the metakeys should be in when pressing the key.
73+
74+
# @!method long_press_keycode
75+
# Long press keycode on the device.
76+
# http://developer.android.com/reference/android/view/KeyEvent.html
77+
# @param key (integer) The key to long press.
78+
# @param metastate (String) The state the metakeys should be in when long pressing the key.
7279

7380
# @!method push_file
7481
# Place a file in a specific location on the device.
@@ -146,11 +153,19 @@ def hide_keyboard(close_key='Done')
146153
end
147154
end
148155

149-
add_endpoint_method(:key_event, 'session/:session_id/appium/device/keyevent') do
150-
def key_event(key, metastate=nil)
156+
add_endpoint_method(:press_keycode, 'session/:session_id/appium/device/press_keycode') do
157+
def press_keycode(key, metastate=nil)
151158
args = { keycode: key }
152159
args[:metastate] = metastate if metastate
153-
execute :key_event, {}, args
160+
execute :press_keycode, {}, args
161+
end
162+
end
163+
164+
add_endpoint_method(:long_press_keycode, 'session/:session_id/appium/device/long_press_keycode') do
165+
def long_press_keycode(key, metastate=nil)
166+
args = { keycode: key }
167+
args[:metastate] = metastate if metastate
168+
execute :long_press_keycode, {}, args
154169
end
155170
end
156171

0 commit comments

Comments
 (0)