Skip to content

Commit

Permalink
Added forceviewserveruse parameter
Browse files Browse the repository at this point in the history
- forceviewserveruse parameter added to ViewClient and other classes to
allow the use of ViewServer even if the conditions were given to use
UiAutomator
  • Loading branch information
dtmilano committed Dec 22, 2012
1 parent 2759692 commit 941bcb7
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions AndroidViewClient/src/com/dtmilano/android/viewclient.py
Expand Up @@ -17,7 +17,7 @@
@author: diego
'''

__version__ = '2.3.1'
__version__ = '2.3.2'

import sys
import subprocess
Expand Down Expand Up @@ -164,23 +164,23 @@ class View:
'''

@staticmethod
def factory(attrs, device, version=-1):
def factory(attrs, device, version=-1, forceviewserveruse=False):
'''
View factory
'''

if attrs.has_key('class'):
clazz = attrs['class']
if clazz == 'android.widget.TextView':
return TextView(attrs, device, version)
return TextView(attrs, device, version, forceviewserveruse)
elif clazz == 'android.widget.EditText':
return EditText(attrs, device, version)
return EditText(attrs, device, version, forceviewserveruse)
else:
return View(attrs, device, version)
return View(attrs, device, version, forceviewserveruse)
else:
return View(attrs, device, version)
return View(attrs, device, version, forceviewserveruse)

def __init__(self, map, device, version=-1):
def __init__(self, map, device, version=-1, forceviewserveruse=False):
'''
Constructor
Expand All @@ -192,6 +192,9 @@ def __init__(self, map, device, version=-1):
@param version: the Android SDK version number of the platform where this View belongs. If
this is C{-1} then the Android SDK version will be obtained in this
constructor.
@type forceviewserveruse: boolean
@param forceviewserveruse: Force the use of C{ViewServer} even if the conditions were given
to use C{UiAutomator}.
'''

self.map = map
Expand All @@ -205,6 +208,7 @@ def __init__(self, map, device, version=-1):
self.windows = {}
self.currentFocus = None
self.build = {}
''' Build properties '''

if version != -1:
self.build[VERSION_SDK_PROPERTY] = version
Expand All @@ -218,16 +222,16 @@ def __init__(self, map, device, version=-1):
self.build[VERSION_SDK_PROPERTY] = -1

version = self.build[VERSION_SDK_PROPERTY]
self.useUiAutomator = (version >= 16)
self.useUiAutomator = (version >= 16) and not forceviewserveruse
''' Whether to use UIAutomator or ViewServer '''
self.idProperty = None
''' The id property depending on the View attribute format '''
self.textProperty = None
''' The text property depending on the View attribute format '''
if version >= 16:
if version >= 16 and self.useUiAutomator:
self.idProperty = ID_PROPERTY_UI_AUTOMATOR
self.textProperty = TEXT_PROPERTY_UI_AUTOMATOR
elif version > 10 and version < 16:
elif version > 10 and (version < 16 or self.useUiAutomator):
self.idProperty = ID_PROPERTY
self.textProperty = TEXT_PROPERTY
elif version > 0 and version <= 10:
Expand Down Expand Up @@ -835,7 +839,7 @@ class ViewClient:
mapping is created.
'''

def __init__(self, device, serialno, adb=None, autodump=True, localport=VIEW_SERVER_PORT, remoteport=VIEW_SERVER_PORT, startviewserver=True):
def __init__(self, device, serialno, adb=None, autodump=True, forceviewserveruse=False, localport=VIEW_SERVER_PORT, remoteport=VIEW_SERVER_PORT, startviewserver=True):
'''
Constructor
Expand All @@ -852,8 +856,8 @@ def __init__(self, device, serialno, adb=None, autodump=True, localport=VIEW_SER
@type remoteport: int
@param remoteport: the remote port used to start the C{ViewServer} in the device or
emulator
@type startviewserverparam: boolean
@param startviewserverparam: Whether to start the B{global} ViewServer
@type startviewserver: boolean
@param startviewserver: Whether to start the B{global} ViewServer
'''

if not device:
Expand Down Expand Up @@ -909,7 +913,9 @@ def __init__(self, device, serialno, adb=None, autodump=True, localport=VIEW_SER
# we expect it to be an int
self.build[prop] = int(self.build[prop] if self.build[prop] else -1)

self.useUiAutomator = (self.build[VERSION_SDK_PROPERTY] >= 16) # jelly bean 4.1 & 4.2
self.forceViewServerUse = forceviewserveruse
''' Force the use of ViewServer even if the conditions to use UiAutomator are satisfied '''
self.useUiAutomator = (self.build[VERSION_SDK_PROPERTY] >= 16) and not forceviewserveruse # jelly bean 4.1 & 4.2
''' If UIAutomator is supported by the device it will be used '''

if self.useUiAutomator:
Expand Down Expand Up @@ -1346,7 +1352,7 @@ def __parseTree(self, receivedLines):
if not self.root:
if v[0] == ' ':
raise Exception("Unexpected root element starting with ' '.")
self.root = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY])
self.root = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY], self.forceViewServerUse)
if DEBUG: self.root.raw = v
treeLevel = 0
newLevel = 0
Expand All @@ -1357,7 +1363,7 @@ def __parseTree(self, receivedLines):
newLevel = (len(v) - len(v.lstrip()))
if newLevel == 0:
raise Exception("newLevel==0 treeLevel=%d but tree can have only one root, v=%s" % (treeLevel, v))
child = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY])
child = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY], self.forceViewServerUse)
if DEBUG: child.raw = v
if newLevel == treeLevel:
parent.add(child)
Expand Down

0 comments on commit 941bcb7

Please sign in to comment.