Skip to content

Commit 1aa6f8a

Browse files
committed
Added screnshot and View screenshot options to culebra
- Version 5.5.0 - Added more verbose message when adb is not running
1 parent 9b12f7f commit 1aa6f8a

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

AndroidViewClient/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
setup(name='androidviewclient',
6-
version='5.4.7',
6+
version='5.5.0',
77
description='''AndroidViewClient is a 100% pure python tool that
88
simplifies test script creation providing higher level operations and the ability of
99
obtaining the tree of Views present at any given moment on the device or emulator screen.

AndroidViewClient/src/com/dtmilano/android/adb/adbclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@author: Diego Torres Milano
1818
'''
1919

20-
__version__ = '5.1.1'
20+
__version__ = '5.5.0'
2121

2222
import sys
2323
import warnings
@@ -114,7 +114,7 @@ def __connect(self):
114114
try:
115115
self.socket.connect((self.hostname, self.port))
116116
except socket.error, ex:
117-
raise RuntimeError("ERROR: Connecting to %s:%d: %s" % (self.socket, self.port, ex))
117+
raise RuntimeError("ERROR: Connecting to %s:%d: %s.\nIs adb running on your computer?" % (self.socket, self.port, ex))
118118

119119
def close(self):
120120
if DEBUG:

AndroidViewClient/tools/culebra

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
1919
2020
'''
2121

22-
__version__ = '5.4.5'
22+
__version__ = '5.5.0'
2323

2424
import re
2525
import sys
@@ -60,22 +60,26 @@ OUTPUT = 'output'
6060
INTERACTIVE = 'interactive'
6161
WINDOW = 'window'
6262
APPEND_TO_SYS_PATH = 'append-to-sys-path'
63+
SAVE_SCREENSHOT = 'save-screenshot'
64+
SAVE_VIEW_SCREENSHOTS = 'save-view-screenshots'
6365

6466
USAGE = 'usage: %s [OPTION]... [serialno]'
65-
SHORT_OPTS = 'HVIFSkw:i:t:d:rCUj:D:K:R:a:o:Ap'
67+
SHORT_OPTS = 'HVIFSkw:i:t:d:rCUj:D:K:R:a:o:Aps:v:'
6668
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
6769
DO_NOT_IGNORE_UIAUTOMATOR_KILLED,
6870
WINDOW + '=',
6971
FIND_VIEWS_BY_ID + '=', FIND_VIEWS_WITH_TEXT + '=', FIND_VIEWS_WITH_CONTENT_DESCRIPTION + '=',
7072
USE_REGEXPS, VERBOSE_COMMENTS, UNIT_TEST,
7173
USE_JAR + '=', USE_DICTIONARY + '=', DICTIONARY_KEYS_FROM + '=', AUTO_REGEXPS + '=',
7274
START_ACTIVITY + '=',
73-
OUTPUT + '=', INTERACTIVE, APPEND_TO_SYS_PATH]
75+
OUTPUT + '=', INTERACTIVE, APPEND_TO_SYS_PATH,
76+
SAVE_SCREENSHOT + '=', SAVE_VIEW_SCREENSHOTS + '=']
7477
LONG_OPTS_ARG = {WINDOW: 'WINDOW',
7578
FIND_VIEWS_BY_ID: 'BOOL', FIND_VIEWS_WITH_TEXT: 'BOOL', FIND_VIEWS_WITH_CONTENT_DESCRIPTION: 'BOOL',
7679
USE_JAR: 'BOOL', USE_DICTIONARY: 'BOOL', DICTIONARY_KEYS_FROM: 'VALUE', AUTO_REGEXPS: 'LIST',
7780
START_ACTIVITY: 'COMPONENT',
78-
OUTPUT: 'FILENAME'}
81+
OUTPUT: 'FILENAME',
82+
SAVE_SCREENSHOT: 'FILENAME', SAVE_VIEW_SCREENSHOTS: 'DIR'}
7983
OPTS_HELP = {
8084
'H': 'prints this help',
8185
'k': 'don\'t ignore UiAutomator killed',
@@ -92,7 +96,9 @@ OPTS_HELP = {
9296
'a': 'starts Activity before dump',
9397
'o': 'output filename',
9498
'A': 'interactive',
95-
'p': 'append environment variables values to sys.path'
99+
'p': 'append environment variables values to sys.path',
100+
's': 'save screenshot to file',
101+
'v': 'save View screenshots to files in directory'
96102
}
97103

98104
def fillAutoRegexpsRes():
@@ -296,6 +302,12 @@ def printFindViewById(view):
296302
_id = view.getId() if view.getId() else view.getUniqueId()
297303
print '%s%s = %svc.findViewByIdOrRaise("%s")' % (indent, var, prefix, _id)
298304

305+
def printSaveViewScreenshot(view, dir):
306+
'''
307+
'''
308+
var = variableNameFromIdOrKey(view)
309+
print '%s%s%s.writeImageToFile(\'%s/%s.png\')' % (indent, prefix, var, dir, var)
310+
299311
def traverseAndPrint(view):
300312
'''
301313
Traverses the View tree and prints the corresponding statement.
@@ -312,6 +324,8 @@ def traverseAndPrint(view):
312324
printFindViewWithText(view, options[USE_REGEXPS])
313325
if options[FIND_VIEWS_WITH_CONTENT_DESCRIPTION]:
314326
printFindViewWithContentDescription(view, options[USE_REGEXPS])
327+
if options[SAVE_VIEW_SCREENSHOTS]:
328+
printSaveViewScreenshot(view, options[SAVE_VIEW_SCREENSHOTS])
315329

316330
def str2bool(v):
317331
return v.lower() in ("yes", "true", "t", "1", "on")
@@ -356,7 +370,8 @@ options = {FIND_VIEWS_BY_ID: True, FIND_VIEWS_WITH_TEXT: False, FIND_VIEWS_WITH_
356370
USE_REGEXPS: False, VERBOSE_COMMENTS: False,
357371
UNIT_TEST: False, USE_JAR: False, USE_DICTIONARY: False, DICTIONARY_KEYS_FROM: 'id',
358372
AUTO_REGEXPS: None, START_ACTIVITY: None, OUTPUT: None, INTERACTIVE: False,
359-
WINDOW:-1, APPEND_TO_SYS_PATH: False}
373+
WINDOW:-1, APPEND_TO_SYS_PATH: False,
374+
SAVE_SCREENSHOT: None, SAVE_VIEW_SCREENSHOTS: None}
360375
transform = traverseAndPrint
361376
for o, a in optlist:
362377
o = o.strip('-')
@@ -414,6 +429,10 @@ for o, a in optlist:
414429
options[INTERACTIVE] = True
415430
elif o in ['p', APPEND_TO_SYS_PATH]:
416431
options[APPEND_TO_SYS_PATH] = True
432+
elif o in ['s', SAVE_SCREENSHOT]:
433+
options[SAVE_SCREENSHOT] = a
434+
elif o in ['v', SAVE_VIEW_SCREENSHOTS]:
435+
options[SAVE_VIEW_SCREENSHOTS] = a
417436

418437
if not (options[FIND_VIEWS_BY_ID] or options[FIND_VIEWS_WITH_TEXT] or options[FIND_VIEWS_WITH_CONTENT_DESCRIPTION]):
419438
if not options[VERBOSE_COMMENTS]:
@@ -507,6 +526,11 @@ class CulebraTests(unittest.TestCase):
507526
self.vc.dump(%s)
508527
''' % (getWindowOption())
509528

529+
if options[SAVE_SCREENSHOT]:
530+
print '''\
531+
self.vc.writeImageToFile('%s')
532+
''' % options[SAVE_SCREENSHOT]
533+
510534
if options[USE_DICTIONARY]:
511535
print '''\
512536
self.views = dict()'''
@@ -544,6 +568,11 @@ vc.dump(window=%s)
544568
if options[USE_DICTIONARY]:
545569
print '''views = dict()'''
546570

571+
if options[SAVE_SCREENSHOT]:
572+
print '''\
573+
vc.writeImageToFile('%s')
574+
''' % options[SAVE_SCREENSHOT]
575+
547576
vc.dump(window=options[WINDOW])
548577
vc.traverse(transform=transform)
549578

AndroidViewClient/tools/dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Created on Feb 3, 2012
66
@author: diego
77
'''
88

9-
__version__ = '5.4.5'
9+
__version__ = '5.5.0'
1010

1111
import sys
1212
import os

0 commit comments

Comments
 (0)