Skip to content

Commit fc881af

Browse files
committed
Added screenshot options to dump
- Version 6.1.0 - Corrected short options
1 parent 3b4958b commit fc881af

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

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='6.0.0',
6+
version='6.1.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/tools/culebra

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
1919
2020
'''
2121

22-
__version__ = '6.0.1'
22+
__version__ = '6.1.0'
2323

2424
import re
2525
import sys

AndroidViewClient/tools/dump

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

9-
__version__ = '6.0.0'
9+
__version__ = '6.1.0'
1010

1111
import sys
1212
import os
@@ -31,18 +31,32 @@ UNIQUE_ID = 'uniqueId'
3131
POSITION = 'position'
3232
CONTENT_DESCRIPTION = 'content-description'
3333
CENTER = 'center'
34+
SAVE_SCREENSHOT = 'save-screenshot'
35+
SAVE_VIEW_SCREENSHOTS = 'save-view-screenshots'
36+
37+
def traverseSaveViewScreenshots(view):
38+
dir = options[SAVE_VIEW_SCREENSHOTS]
39+
var = view.variableNameFromId()
40+
filename = '%s/%s.png' % (dir, var)
41+
if kwargs1[VERBOSE]:
42+
print view.__tinyStr__(), ' => ', filename
43+
view.writeImageToFile(filename)
44+
3445
MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
3546
'x':ViewClient.TRAVERSE_CITPS, POSITION:ViewClient.TRAVERSE_CITPS,
3647
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
3748
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
49+
'W':traverseSaveViewScreenshots, SAVE_VIEW_SCREENSHOTS:traverseSaveViewScreenshots,
3850
}
3951

4052
USAGE = 'usage: %s [OPTION]... [serialno]'
41-
SHORT_OPTS = 'HVvIFSkw:ixdc'
53+
SHORT_OPTS = 'HVvIFSkw:ixdcs:W:'
4254
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE,
4355
DO_NOT_START_VIEW_SERVER, DO_NOT_IGNORE_UIAUTOMATOR_KILLED, WINDOW + '=',
44-
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]
45-
LONG_OPTS_ARG = {WINDOW: 'WINDOW'}
56+
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER,
57+
SAVE_SCREENSHOT + '=', SAVE_VIEW_SCREENSHOTS + '=',
58+
]
59+
LONG_OPTS_ARG = {WINDOW: 'WINDOW', SAVE_SCREENSHOT: 'FILE', SAVE_VIEW_SCREENSHOTS: 'DIR'}
4660
OPTS_HELP = {
4761
'H': 'prints this help',
4862
'V': 'verbose comments',
@@ -54,7 +68,9 @@ OPTS_HELP = {
5468
'i': 'dump View unique IDs',
5569
'x': 'dump View positions',
5670
'd': 'dump View content descriptions',
57-
'c': 'dump View centers'
71+
'c': 'dump View centers',
72+
's': 'save screenshot to file',
73+
'W': 'save View screenshots to files in directory',
5874
}
5975

6076
def shortAndLongOptions():
@@ -107,15 +123,15 @@ except getopt.GetoptError, e:
107123

108124
kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False}
109125
kwargs2 = {'forceviewserveruse': False, 'startviewserver': True, 'autodump': False, 'ignoreuiautomatorkilled': True}
110-
options = {WINDOW: -1}
126+
options = {WINDOW: -1, SAVE_SCREENSHOT: None, SAVE_VIEW_SCREENSHOTS: None}
111127
transform = ViewClient.TRAVERSE_CIT
112128
for o, a in opts:
113129
o = o.strip('-')
114130
if o in ['H', HELP]:
115131
help()
116132
elif o in ['V', VERBOSE]:
117133
kwargs1[VERBOSE] = True
118-
elif o in [VERSION]:
134+
elif o in ['v', VERSION]:
119135
version()
120136
elif o in ['I', IGNORE_SECURE_DEVICE]:
121137
kwargs1['ignoresecuredevice'] = True
@@ -127,9 +143,16 @@ for o, a in opts:
127143
kwargs2['ignoreuiautomatorkilled'] = False
128144
elif o in ['w', WINDOW]:
129145
options[WINDOW] = a
146+
elif o in ['s', SAVE_SCREENSHOT]:
147+
options[SAVE_SCREENSHOT] = a
148+
elif o in ['W', SAVE_VIEW_SCREENSHOTS]:
149+
options[SAVE_VIEW_SCREENSHOTS] = a
150+
transform = MAP[o]
130151
else:
131152
transform = MAP[o]
132153

133154
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
134155
vc.dump(window=options[WINDOW])
156+
if options[SAVE_SCREENSHOT]:
157+
vc.writeImageToFile(options[SAVE_SCREENSHOT])
135158
vc.traverse(transform=transform)

0 commit comments

Comments
 (0)