Skip to content

Commit 039a95c

Browse files
AVC: Add pressKeyCode to uiAutomatorHelper and ViewClient
- Add test for uiAutomatorHelper:pressKeyCode
1 parent 005d8c5 commit 039a95c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/com/dtmilano/android/viewclient.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,15 @@ def swipe(self, (x0, y0), (x1, y1), steps=400):
36543654
else:
36553655
warnings.warn("swipe only implemented using UiAutomatorHelper. Use AdbClient.drag() instead.")
36563656

3657+
def pressKeyCode(self, keycode, metaState=-1):
3658+
'''By default no meta state'''
3659+
if self.uiAutomatorHelper:
3660+
if DEBUG_UI_AUTOMATOR_HELPER:
3661+
print >> sys.stderr, "pressKeyCode(%d, %d)" %(keycode, metaState)
3662+
self.uiAutomatorHelper.pressKeyCode(keycode, metaState)
3663+
else:
3664+
warnings.warn("pressKeyCode only implemented using UiAutomatorHelper. Use AdbClient.type() instead")
3665+
36573666
def setText(self, v, text):
36583667
if DEBUG:
36593668
print >> sys.stderr, "setText(%s, '%s')" % (v.__tinyStr__(), text)

tests/com/dtmilano/android/uiautomator/uiautomatorhelpertests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def testDumpWindowHierarchy_repeat(self):
4444
dump = self.uiAutomatorHelper.dumpWindowHierarchy()
4545
self.assertIsNotNone(dump)
4646

47+
def testPressKeyCode(self):
48+
response = self.uiAutomatorHelper.pressKeyCode(4)
49+
'''4 is KEYCODE_BACK'''
50+
if DEBUG:
51+
print >> sys.stderr, "response=", response
52+
4753
def testTakeScreenshot(self):
4854
buf = self.uiAutomatorHelper.takeScreenshot()
4955
self.assertIsNotNone(buf)

0 commit comments

Comments
 (0)