Skip to content

Commit f98d161

Browse files
committed
Allow culebra to work without backend
- This is needed when UiAutomator gives "ERROR: Could not get idle state"
1 parent 7ac198c commit f98d161

2 files changed

Lines changed: 60 additions & 49 deletions

File tree

src/com/dtmilano/android/culebron.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
@author: Diego Torres Milano
1919
2020
'''
21+
import time
2122

22-
__version__ = '10.3.3'
23+
__version__ = '10.3.4'
2324

2425
import sys
2526
import threading
@@ -28,7 +29,6 @@
2829
import string
2930
import os
3031
import platform
31-
from __builtin__ import False
3232
from pkg_resources import Requirement, resource_filename
3333

3434
try:
@@ -165,12 +165,16 @@ def checkDependencies():
165165
This is usually installed by python package. Check your distribution details.
166166
''')
167167

168-
def __init__(self, vc, printOperation, scale=1):
168+
def __init__(self, vc, device, serialno, printOperation, scale=1):
169169
'''
170170
Culebron constructor.
171171
172172
@param vc: The ViewClient used by this Culebron instance
173173
@type vc: ViewClient
174+
@param device: The device
175+
@type device: L{AdbClient}
176+
@param serialno: The device's serial number
177+
@type serialno: str
174178
@param printOperation: the method invoked to print operations to the script
175179
@type printOperation: method
176180
@param scale: the scale of the device screen used to show it on the window
@@ -179,8 +183,8 @@ def __init__(self, vc, printOperation, scale=1):
179183

180184
self.vc = vc
181185
self.printOperation = printOperation
182-
self.device = vc.device
183-
self.serialno = vc.serialno
186+
self.device = device
187+
self.serialno = serialno
184188
self.scale = scale
185189
self.window = Tkinter.Tk()
186190
icon = resource_filename(Requirement.parse("androidviewclient"),
@@ -469,8 +473,11 @@ def findTargets(self):
469473
window = -1
470474
else:
471475
window = -1
472-
dump = self.vc.dump(window=window)
473-
self.printOperation(None, Operation.DUMP, window, dump)
476+
if self.vc:
477+
dump = self.vc.dump(window=window)
478+
self.printOperation(None, Operation.DUMP, window, dump)
479+
else:
480+
dump = []
474481
# the root element cannot be deleted from Treeview once added.
475482
# We have no option but to recreate it
476483
self.viewTree = ViewTree(self.sideFrame)
@@ -495,7 +502,8 @@ def findTargets(self):
495502
else:
496503
target = False
497504

498-
self.vc.traverse(transform=self.populateViewTree)
505+
if self.vc:
506+
self.vc.traverse(transform=self.populateViewTree)
499507

500508
def getViewContainingPointAndGenerateTestCondition(self, x, y):
501509
if DEBUG:
@@ -514,22 +522,23 @@ def getViewContainingPointAndGenerateTestCondition(self, x, y):
514522

515523

516524
def findViewContainingPointInTargets(self, x, y):
517-
vlist = self.vc.findViewsContainingPoint((x, y))
518-
if DEBUG_FIND_VIEW:
519-
print >> sys.stderr, "Views found:"
525+
if self.vc:
526+
vlist = self.vc.findViewsContainingPoint((x, y))
527+
if DEBUG_FIND_VIEW:
528+
print >> sys.stderr, "Views found:"
529+
for v in vlist:
530+
print >> sys.stderr, " ", v.__smallStr__()
531+
vlist.reverse()
520532
for v in vlist:
521-
print >> sys.stderr, " ", v.__smallStr__()
522-
vlist.reverse()
523-
for v in vlist:
524-
if DEBUG:
525-
print >> sys.stderr, "checking if", v, "is in", self.targetViews
526-
if v in self.targetViews:
527-
if DEBUG_TOUCH:
528-
print >> sys.stderr
529-
print >> sys.stderr, "I guess you are trying to touch:", v
530-
print >> sys.stderr
531-
return v
532-
533+
if DEBUG:
534+
print >> sys.stderr, "checking if", v, "is in", self.targetViews
535+
if v in self.targetViews:
536+
if DEBUG_TOUCH:
537+
print >> sys.stderr
538+
print >> sys.stderr, "I guess you are trying to touch:", v
539+
print >> sys.stderr
540+
return v
541+
533542
return None
534543

535544
def getViewContainingPointAndTouch(self, x, y):
@@ -615,11 +624,11 @@ def touchPoint(self, x, y):
615624
self.showVignette()
616625
self.device.touch(x, y)
617626
if self.coordinatesUnit == Unit.DIP:
618-
x = round(x / self.vc.display['density'], 2)
619-
y = round(y / self.vc.display['density'], 2)
620-
self.printOperation(None, Operation.TOUCH_POINT, x, y, self.coordinatesUnit, self.vc.display['orientation'])
627+
x = round(x / self.device.display['density'], 2)
628+
y = round(y / self.device.display['density'], 2)
629+
self.printOperation(None, Operation.TOUCH_POINT, x, y, self.coordinatesUnit, self.device.display['orientation'])
621630
self.printOperation(None, Operation.SLEEP, Operation.DEFAULT)
622-
self.vc.sleep(5)
631+
time.sleep(5)
623632
self.isTouchingPoint = False
624633
self.takeScreenshotAndShowItOnWindow()
625634
self.hideVignette()
@@ -781,7 +790,7 @@ def onKeyPressed(self, event):
781790
pass
782791
else:
783792
self.command(char.decode('ascii', errors='replace'))
784-
self.vc.sleep(1)
793+
time.sleep(1)
785794
self.takeScreenshotAndShowItOnWindow()
786795

787796

tools/culebra

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

23-
__version__ = '10.3.3'
23+
__version__ = '10.3.4'
2424

2525
import re
2626
import sys
@@ -775,7 +775,7 @@ def logAction(action):
775775
def runCulebron():
776776
Culebron.checkSupportedSdkVersion(device.getSdkVersion())
777777
Culebron.checkDependencies()
778-
culebron = Culebron(vc, printOperation, options[CulebraOptions.SCALE])
778+
culebron = Culebron(vc, device, serialno, printOperation, options[CulebraOptions.SCALE])
779779
if options[CulebraOptions.DEVICE_ART]:
780780
culebron.deviceArt = options[CulebraOptions.DEVICE_ART]
781781
culebron.dropShadow = options[CulebraOptions.DROP_SHADOW]
@@ -809,25 +809,27 @@ except getopt.GetoptError, e:
809809
kwargs1 = {CulebraOptions.VERBOSE: False, 'ignoresecuredevice': False, 'ignoreversioncheck': False}
810810
serialno = None
811811
kwargs2 = {ViewClientOptions.FORCE_VIEW_SERVER_USE: False, ViewClientOptions.START_VIEW_SERVER: True,
812-
ViewClientOptions.AUTO_DUMP: False, ViewClientOptions.IGNORE_UIAUTOMATOR_KILLED: True,
813-
ViewClientOptions.COMPRESSED_DUMP: True}
814-
options = {CulebraOptions.FIND_VIEWS_BY_ID: True, CulebraOptions.FIND_VIEWS_WITH_TEXT: True, CulebraOptions.FIND_VIEWS_WITH_CONTENT_DESCRIPTION: True,
815-
CulebraOptions.USE_REGEXPS: False, CulebraOptions.VERBOSE_COMMENTS: False,
816-
CulebraOptions.UNIT_TEST_CLASS: False, CulebraOptions.UNIT_TEST_METHOD: None, CulebraOptions.USE_JAR: False,
817-
CulebraOptions.USE_DICTIONARY: False, CulebraOptions.DICTIONARY_KEYS_FROM: 'id',
818-
CulebraOptions.AUTO_REGEXPS: None, CulebraOptions.START_ACTIVITY: None, CulebraOptions.OUTPUT: None, CulebraOptions.INTERACTIVE: False,
819-
CulebraOptions.WINDOW:-1, CulebraOptions.PREPEND_TO_SYS_PATH: False,
820-
CulebraOptions.SAVE_SCREENSHOT: None, CulebraOptions.SAVE_VIEW_SCREENSHOTS: None,
821-
CulebraOptions.GUI: False,
822-
CulebraOptions.DO_NOT_VERIFY_SCREEN_DUMP: False,
823-
CulebraOptions.SCALE: 1,
824-
CulebraOptions.ORIENTATION_LOCKED: None,
825-
CulebraOptions.MULTI_DEVICE: False,
826-
CulebraOptions.LOG_ACTIONS: False,
827-
CulebraOptions.DEVICE_ART: None,
828-
CulebraOptions.DROP_SHADOW: False,
829-
CulebraOptions.SCREEN_GLARE: False,
830-
}
812+
ViewClientOptions.AUTO_DUMP: False, ViewClientOptions.IGNORE_UIAUTOMATOR_KILLED: True,
813+
ViewClientOptions.COMPRESSED_DUMP: True}
814+
options = {CulebraOptions.FIND_VIEWS_BY_ID: True, CulebraOptions.FIND_VIEWS_WITH_TEXT: True,
815+
CulebraOptions.FIND_VIEWS_WITH_CONTENT_DESCRIPTION: True,
816+
CulebraOptions.USE_REGEXPS: False, CulebraOptions.VERBOSE_COMMENTS: False,
817+
CulebraOptions.UNIT_TEST_CLASS: False, CulebraOptions.UNIT_TEST_METHOD: None, CulebraOptions.USE_JAR: False,
818+
CulebraOptions.USE_DICTIONARY: False, CulebraOptions.DICTIONARY_KEYS_FROM: 'id',
819+
CulebraOptions.AUTO_REGEXPS: None, CulebraOptions.START_ACTIVITY: None, CulebraOptions.OUTPUT: None,
820+
CulebraOptions.INTERACTIVE: False,
821+
CulebraOptions.WINDOW: -1, CulebraOptions.PREPEND_TO_SYS_PATH: False,
822+
CulebraOptions.SAVE_SCREENSHOT: None, CulebraOptions.SAVE_VIEW_SCREENSHOTS: None,
823+
CulebraOptions.GUI: False,
824+
CulebraOptions.DO_NOT_VERIFY_SCREEN_DUMP: False,
825+
CulebraOptions.SCALE: 1,
826+
CulebraOptions.ORIENTATION_LOCKED: None,
827+
CulebraOptions.MULTI_DEVICE: False,
828+
CulebraOptions.LOG_ACTIONS: False,
829+
CulebraOptions.DEVICE_ART: None,
830+
CulebraOptions.DROP_SHADOW: False,
831+
CulebraOptions.SCREEN_GLARE: False,
832+
}
831833
transform = traverseAndPrint
832834
for o, a in optlist:
833835
o = o.strip('-')

0 commit comments

Comments
 (0)