Permalink
Browse files

- Reassigned tools' command line options

- Version 6.0.0
- adbclient: added longPress() (experimental)
- adbclient: added sdk version
- vieclient: corrected getprop
-
  • Loading branch information...
1 parent 1b64647 commit 220a192807fad8a88801673418c7a5b69c3be401 @dtmilano committed May 21, 2014
@@ -3,7 +3,7 @@
from setuptools import setup, find_packages
setup(name='androidviewclient',
- version='5.6.2',
+ version='6.0.0',
description='''AndroidViewClient is a 100% pure python tool that
simplifies test script creation providing higher level operations and the ability of
obtaining the tree of Views present at any given moment on the device or emulator screen.
@@ -17,7 +17,7 @@
@author: Diego Torres Milano
'''
-__version__ = '5.5.0'
+__version__ = '5.7.0'
import sys
import warnings
@@ -54,6 +54,11 @@
TIMEOUT = 15
+# some device properties
+VERSION_SDK_PROPERTY = 'ro.build.version.sdk'
+VERSION_RELEASE_PROPERTY = 'ro.build.version.release'
+
+
class Device:
@staticmethod
def factory(_str):
@@ -84,9 +89,15 @@ def __init__(self, serialno=None, hostname=HOSTNAME, port=PORT, settransport=Tru
self.__connect()
self.checkVersion()
+
+ self.build = {}
+ ''' Build properties '''
+
self.isTransportSet = False
if settransport and serialno != None:
self.__setTransport()
+ self.build[VERSION_SDK_PROPERTY] = self.__getProp(VERSION_SDK_PROPERTY)
+
@staticmethod
def setAlarm(timeout):
@@ -102,6 +113,7 @@ def setSerialno(self, serialno):
raise ValueError("Transport is already set, serialno cannot be set once this is done.")
self.serialno = serialno
self.__setTransport()
+ self.build[VERSION_SDK_PROPERTY] = self.__getProp(VERSION_SDK_PROPERTY)
def setReconnect(self, val):
self.reconnect = val
@@ -311,12 +323,46 @@ def getProperty(self, key, strip=True):
return MAP_KEYS[kre](key=key, strip=strip)
raise ValueError("key='%s' does not match any map entry")
+ def getSdkVersion(self):
+ '''
+ Gets the SDK version.
+ '''
+
+ return self.build[VERSION_SDK_PROPERTY]
+
def press(self, name, eventType=DOWN_AND_UP):
cmd = 'input keyevent %s' % name
if DEBUG:
print >> sys.stderr, "press(%s)" % cmd
self.shell(cmd)
+ def longPress(self, name):
+ # WORKAROUND:
+ # Using 'input keyevent --longpress POWER' does not work correctly in
+ # KitKat (API 19), it sends a short instead of a long press.
+ # This uses the events instead, but it may vary from device to device.
+ # The events sent are device dependent and may not work on other devices.
+ # If this does not work on your device please do:
+ # $ adb shell getevent -l
+ # and post the output to https://github.com/dtmilano/AndroidViewClient/issues
+ # specifying the device and API level.
+ if name == 'POWER' or name == 'KEY_POWER':
+ self.shell('sendevent /dev/input/event0 1 116 1')
+ self.shell('sendevent /dev/input/event0 0 0 0')
+ time.sleep(0.5)
+ self.shell('sendevent /dev/input/event0 1 116 0')
+ self.shell('sendevent /dev/input/event0 0 0 0')
+ return
+
+ version = self.getSdkVersion()
+ if version >= 19:
+ cmd = 'input keyevent --longpress %s' % name
+ if DEBUG:
+ print >> sys.stderr, "longPress(%s)" % cmd
+ self.shell(cmd)
+ else:
+ raise RuntimeError("longpress: not supported for API < 19 (version=%d)" % version)
+
def startActivity(self, component=None, flags=None, uri=None):
cmd = 'am start'
if component:
@@ -388,7 +434,7 @@ def drag(self, (x0, y0), (x1, y1), duration, steps=1):
@param steps: number of steps (currently ignored by @{input swipe}
'''
- version = int(self.getProperty('ro.build.version.sdk'))
+ version = self.getSdkVersion()
if version <= 15:
raise RuntimeError('drag: API <= 15 not supported (version=%d)' % version)
elif version <= 17:
@@ -18,7 +18,7 @@
@author: Diego Torres Milano
'''
-__version__ = '5.6.2'
+__version__ = '5.6.3'
import sys
import warnings
@@ -293,7 +293,7 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False):
if USE_ADB_CLIENT_TO_GET_BUILD_PROPERTIES:
self.build[VERSION_SDK_PROPERTY] = int(device.getProperty(VERSION_SDK_PROPERTY))
else:
- self.build[VERSION_SDK_PROPERTY] = int(device.shell('getprop ro.build.' + VERSION_SDK_PROPERTY)[:-2])
+ self.build[VERSION_SDK_PROPERTY] = int(device.shell('getprop ' + VERSION_SDK_PROPERTY)[:-2])
except:
self.build[VERSION_SDK_PROPERTY] = -1
@@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
'''
-__version__ = '5.6.1'
+__version__ = '6.0.0'
import re
import sys
@@ -65,7 +65,7 @@ SAVE_SCREENSHOT = 'save-screenshot'
SAVE_VIEW_SCREENSHOTS = 'save-view-screenshots'
USAGE = 'usage: %s [OPTION]... [serialno]'
-SHORT_OPTS = 'HVIFSkw:i:t:d:rCUj:D:K:R:a:o:Aps:v:'
+SHORT_OPTS = 'HVvIFSkw:i:t:d:rCUj:D:K:R:a:o:Aps:W:'
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
DO_NOT_IGNORE_UIAUTOMATOR_KILLED,
WINDOW + '=',
@@ -83,6 +83,7 @@ LONG_OPTS_ARG = {WINDOW: 'WINDOW',
SAVE_SCREENSHOT: 'FILENAME', SAVE_VIEW_SCREENSHOTS: 'DIR'}
OPTS_HELP = {
'H': 'prints this help',
+ 'V': 'verbose comments',
'k': 'don\'t ignore UiAutomator killed',
'w': 'use WINDOW content (default: -1, all windows)',
'i': 'whether to use findViewById() in script',
@@ -99,7 +100,7 @@ OPTS_HELP = {
'A': 'interactive',
'p': 'append environment variables values to sys.path',
's': 'save screenshot to file',
- 'v': 'save View screenshots to files in directory'
+ 'W': 'save View screenshots to files in directory'
}
def fillAutoRegexpsRes():
@@ -6,7 +6,7 @@ Created on Feb 3, 2012
@author: diego
'''
-__version__ = '5.6.0'
+__version__ = '6.0.0'
import sys
import os
@@ -38,7 +38,7 @@ MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
}
USAGE = 'usage: %s [OPTION]... [serialno]'
-SHORT_OPTS = 'HVIFSkw:ixdc'
+SHORT_OPTS = 'HVvIFSkw:ixdc'
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE,
DO_NOT_START_VIEW_SERVER, DO_NOT_IGNORE_UIAUTOMATOR_KILLED, WINDOW + '=',
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]

0 comments on commit 220a192

Please sign in to comment.