Skip to content

Commit 1993d98

Browse files
manoj9788SrinivasanTarget
authored andcommitted
Add unit tests for keyboard API (#452)
* Add Unit tests for Keyboard API * incorporating review comments * change per review comment
1 parent 9e18dfc commit 1993d98

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/unit/webdriver/device/keyboard_test.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,69 @@ def test_hide_keyboard(self):
3232
appium_command('/session/1234567890/appium/device/hide_keyboard')
3333
)
3434
assert isinstance(driver.hide_keyboard(), WebDriver)
35+
36+
@httpretty.activate
37+
def test_press_keycode(self):
38+
driver = android_w3c_driver()
39+
httpretty.register_uri(
40+
httpretty.POST,
41+
appium_command('/session/1234567890/appium/device/press_keycode'),
42+
body='{"value": "86"}'
43+
)
44+
driver.press_keycode(86)
45+
d = get_httpretty_request_body((httpretty.last_request()))
46+
assert d['keycode'] == 86
47+
48+
@httpretty.activate
49+
def test_long_press_keycode(self):
50+
driver = android_w3c_driver()
51+
httpretty.register_uri(
52+
httpretty.POST,
53+
appium_command('/session/1234567890/appium/device/long_press_keycode'),
54+
body='{"value": "86"}'
55+
)
56+
driver.long_press_keycode(86)
57+
d = get_httpretty_request_body((httpretty.last_request()))
58+
assert d['keycode'] == 86
59+
60+
@httpretty.activate
61+
def test_keyevent(self):
62+
driver = android_w3c_driver()
63+
httpretty.register_uri(
64+
httpretty.POST,
65+
appium_command('/session/1234567890/appium/device/keyevent'),
66+
body='{keycode: 86}'
67+
)
68+
assert isinstance(driver.keyevent(86), WebDriver)
69+
70+
@httpretty.activate
71+
def test_press_keycode_with_flags(self):
72+
driver = android_w3c_driver()
73+
httpretty.register_uri(
74+
httpretty.POST,
75+
appium_command('/session/1234567890/appium/device/press_keycode'),
76+
body='{keycode: 86, metastate: 2097153, flags: 44}'
77+
)
78+
# metastate is META_SHIFT_ON and META_NUM_LOCK_ON
79+
# flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM
80+
assert isinstance(
81+
driver.press_keycode(
82+
86, metastate=[
83+
0x00000001, 0x00200000], flags=[
84+
0x20, 0x00000004, 0x00000008]), WebDriver)
85+
86+
@httpretty.activate
87+
def test_long_press_keycode_with_flags(self):
88+
driver = android_w3c_driver()
89+
httpretty.register_uri(
90+
httpretty.POST,
91+
appium_command('/session/1234567890/appium/device/long_press_keycode'),
92+
body='{keycode: 86, metastate: 2097153, flags: 44}'
93+
)
94+
# metastate is META_SHIFT_ON and META_NUM_LOCK_ON
95+
# flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM
96+
assert isinstance(
97+
driver.long_press_keycode(
98+
86, metastate=[
99+
0x00000001, 0x00200000], flags=[
100+
0x20, 0x00000004, 0x00000008]), WebDriver)

0 commit comments

Comments
 (0)