Skip to content

Commit 8f2e41e

Browse files
committed
Fixed problem with fling*() command generation, now used cd, text or id as corresponds
1 parent ed1927b commit 8f2e41e

2 files changed

Lines changed: 49 additions & 19 deletions

File tree

src/com/dtmilano/android/culebron.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from com.dtmilano.android.common import profileEnd
2727
from com.dtmilano.android.concertina import Concertina
2828

29-
__version__ = '11.1.0'
29+
__version__ = '11.1.1'
3030

3131
import sys
3232
import threading
@@ -114,13 +114,17 @@ class Operation:
114114
VIEW_SNAPSHOT = 'view_snapshot'
115115
WAKE = 'wake'
116116

117+
COMMAND_NAME_OPERATION_MAP = {'flingBackward': FLING_BACKWARD, 'flingForward': FLING_FORWARD,
118+
'flingToBeginning': FLING_TO_BEGINNING, 'flingToEnd': FLING_TO_END,
119+
'openNotification': OPEN_NOTIFICATION, 'openQuickSettings': OPEN_QUICK_SETTINGS,
120+
}
117121
@staticmethod
118122
def fromCommandName(commandName):
119-
MAP = {'flingBackward': Operation.FLING_BACKWARD, 'flingForward': Operation.FLING_FORWARD,
120-
'flingToBeginning': Operation.FLING_TO_BEGINNING, 'flingToEnd': Operation.FLING_TO_END,
121-
'openNotification': Operation.OPEN_NOTIFICATION, 'openQuickSettings': Operation.OPEN_QUICK_SETTINGS,
122-
}
123-
return MAP[commandName]
123+
return Operation.COMMAND_NAME_OPERATION_MAP[commandName]
124+
125+
@staticmethod
126+
def toCommandName(operation):
127+
return next((cmd for cmd, op in Operation.COMMAND_NAME_OPERATION_MAP.items() if op == operation), None)
124128

125129

126130
class Culebron:
@@ -1206,6 +1210,9 @@ def executeCommandAndRefresh(self, command):
12061210
view = command.__self__.view
12071211
except AttributeError:
12081212
view = None
1213+
# FIXME: If we are not dumping the Views and assigning to variables (i.e -u was used on command line) then
1214+
# when we try to do an operation on the View via its variable name it's going to fail when the saved script
1215+
# is executed
12091216
self.printOperation(view, Operation.fromCommandName(command.__name__))
12101217
command()
12111218
self.printOperation(None, Operation.SLEEP, Operation.DEFAULT)

tools/culebra

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
2020
2121
'''
2222

23-
__version__ = '11.1.0'
23+
__version__ = '11.1.1'
2424

2525
import re
2626
import sys
@@ -280,6 +280,13 @@ You have to set PYTHONIOENCODING environment variable. For example:
280280
warnings.warn('Multi-device not implemented yet for this case')
281281
else:
282282
print '%s%svc.findViewWithTextOrRaise("%s").type(u"%s")' % (indent, prefix, text, arg)
283+
elif op in [Operation.FLING_BACKWARD, Operation.FLING_FORWARD, Operation.FLING_TO_BEGINNING, Operation.FLING_TO_END]:
284+
if options[CulebraOptions.MULTI_DEVICE]:
285+
warnings.warn('Multi-device not implemented yet for this case')
286+
else:
287+
commandName = Operation.toCommandName(op)
288+
logAction(u'flinging view with text=%s %s' % (text, commandName))
289+
print u'%s%svc.findViewWithTextOrRaise(%s).uiScrollable.%s()' % (indent, prefix, text, commandName)
283290
elif op == Operation.TEST:
284291
if options[CulebraOptions.MULTI_DEVICE]:
285292
warnings.warn('Multi-device not implemented yet for this case')
@@ -333,6 +340,13 @@ def printFindViewWithContentDescription(view, useregexp, op=Operation.ASSIGN, ar
333340
warnings.warn('Multi-device not implemented yet for this case')
334341
else:
335342
print '%s%sassertEquals(%svc.findViewWithContentDescriptionOrRaise(%s).getText(), u\'\'\'%s\'\'\')' % (indent, prefix, prefix, contentDescription, arg)
343+
elif op in [Operation.FLING_BACKWARD, Operation.FLING_FORWARD, Operation.FLING_TO_BEGINNING, Operation.FLING_TO_END]:
344+
if options[CulebraOptions.MULTI_DEVICE]:
345+
warnings.warn('Multi-device not implemented yet for this case')
346+
else:
347+
commandName = Operation.toCommandName(op)
348+
logAction(u'flinging view with content-description=%s %s' % (contentDescription, commandName))
349+
print u'%s%svc.findViewWithContentDescriptionOrRaise(%s).uiScrollable.%s()' % (indent, prefix, contentDescription, commandName)
336350
else:
337351
error("Invalid operation in %s: %s" % (sys._getframe().f_code.co_name), op)
338352

@@ -374,6 +388,13 @@ def printFindViewById(view, op=Operation.ASSIGN, arg=None):
374388
warnings.warn('Multi-device not implemented yet for this case')
375389
else:
376390
print '%s%sassertEquals(%svc.findViewByIdOrRaise("%s").getText(), u\'\'\'%s\'\'\')' % (indent, prefix, prefix, _id, arg)
391+
elif op in [Operation.FLING_BACKWARD, Operation.FLING_FORWARD, Operation.FLING_TO_BEGINNING, Operation.FLING_TO_END]:
392+
if options[CulebraOptions.MULTI_DEVICE]:
393+
warnings.warn('Multi-device not implemented yet for this case')
394+
else:
395+
commandName = Operation.toCommandName(op)
396+
logAction(u'flinging view with id=%s %s' % (_id, commandName))
397+
print u'%s%svc.findViewWithIdOrRaise(u"%s").uiScrollable.%s()' % (indent, prefix, _id, commandName)
377398
else:
378399
error("Invalid operation in %s: %s" % (sys._getframe().f_code.co_name, op))
379400

@@ -681,18 +702,20 @@ def printOperation(view, op, *args):
681702
elif op == Operation.VIEW_SNAPSHOT:
682703
printSaveViewScreenshot(view, filename=args[0], _format=args[1])
683704
return
684-
elif op == Operation.FLING_BACKWARD:
685-
printFlingBackward(view)
686-
return
687-
elif op == Operation.FLING_FORWARD:
688-
printFlingForward(view)
689-
return
690-
elif op == Operation.FLING_TO_BEGINNING:
691-
printFlingToBeginning(view)
692-
return
693-
elif op == Operation.FLING_TO_END:
694-
printFlingToEnd(view)
695-
return
705+
# FIXME: I moved this to printFindViewWithContentDescription(..,op.,,) to solve the problem of variable not defined when
706+
# the script is invoked with -u
707+
# elif op == Operation.FLING_BACKWARD:
708+
# printFlingBackward(view)
709+
# return
710+
# elif op == Operation.FLING_FORWARD:
711+
# printFlingForward(view)
712+
# return
713+
# elif op == Operation.FLING_TO_BEGINNING:
714+
# printFlingToBeginning(view)
715+
# return
716+
# elif op == Operation.FLING_TO_END:
717+
# printFlingToEnd(view)
718+
# return
696719
elif op == Operation.OPEN_NOTIFICATION:
697720
printOpenNotification()
698721
return

0 commit comments

Comments
 (0)