#! /usr/bin/env python # -*- coding: utf-8 -*- ''' Copyright (C) 2013-2018 Diego Torres Milano Created on 2018-03-29 by Culebra v15.0.1 __ __ __ __ / \ / \ / \ / \ ____________________/ __\/ __\/ __\/ __\_____________________________ ___________________/ /__/ /__/ /__/ /________________________________ | / \ / \ / \ / \ \___ |/ \_/ \_/ \_/ \ o \ \_____/--< @author: Diego Torres Milano @author: Jennifer E. Swofford (ascii art snake) ''' import sys from androidviewclient3.viewclient import ViewClient TAG = 'CULEBRA' _s = 5 _v = '--verbose' in sys.argv kwargs1 = { 'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False } device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { 'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True,
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Apr 23, 2013 @author: diego ''' import sys import os import getopt # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient HELP = 'help' VERBOSE = 'verbose' IGNORE_SECURE_DEVICE = 'ignore-secure-device' FORCE_VIEW_SERVER_USE = 'force-view-server-use' DO_NOT_START_VIEW_SERVER = 'do-not-start-view-server' # -u,-s,-p,-v eaten by monkeyrunner
#! /usr/bin/env python
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Sep 8, 2012 @author: diego @see: http://code.google.com/p/android/issues/detail?id=36544 ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient, View device, serialno = ViewClient.connectToDeviceOrExit() DEBUG = True FLAG_ACTIVITY_NEW_TASK = 0x10000000 # We are not using Settings as the bug describes because there's no WiFi dialog in emulator componentName = 'com.android.settings/.Settings'
@author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient, TextView, EditText device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) #send = vc.findViewWithTextOrRaise('Send') send = vc.findViewByIdOrRaise('id/send') #to = EditText(vc.findViewByIdOrRaise('id/to')) to = vc.findViewByIdOrRaise('id/to') subject = vc.findViewByIdOrRaise('id/subject') subject.touch() subject.type('AVCSample') ViewClient.sleep(10) to.touch() #to.type('*****@*****.**') device.type('*****@*****.**') ViewClient.sleep(10) send.touch()
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Aug 31, 2012 @author: diego ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient vc = ViewClient(*ViewClient.connectToDeviceOrExit()) button = vc.findViewWithTextOrRaise('Show Dialog') print("button: ", button.getClass(), button.getId(), button.getCoords())
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Sep 8, 2012 @author: diego @see: http://code.google.com/p/android/issues/detail?id=36544 ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient device, serialno = ViewClient.connectToDeviceOrExit() FLAG_ACTIVITY_NEW_TASK = 0x10000000 # We are not using Settings as the bug describes because there's no WiFi dialog in emulator #componentName = 'com.android.settings/.Settings' componentName = 'com.dtmilano.android.sampleui/.MainActivity'
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Oct 15, 2012 @author: diego ''' import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient ViewClient.connectToDeviceOrExit(verbose=True)
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Aug 7, 2012 @author: diego ''' import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient vc = ViewClient(*ViewClient.connectToDeviceOrExit()) for i in range(1, 9): view = vc.findViewById("id/no_id/%d" % i) if view: print(view.__tinyStr__()) view.touch()
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Sep 5, 2012 @author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient, View device, serialno = ViewClient.connectToDeviceOrExit() FLAG_ACTIVITY_NEW_TASK = 0x10000000 #09-06 01:01:34.964: I/ActivityManager(873): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.android.apis/.ApiDemos bnds=[784,346][880,442]} from pid 991 componentName = 'com.example.android.apis/.ApiDemos' device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(3) vc = ViewClient(device=device, serialno=serialno) app = vc.findViewWithText('App') if app: app.touch() ViewClient.sleep(3) # windows changed, request a new dump vc.dump() ad = vc.findViewWithText('Alert Dialogs') if ad:
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Mar 13, 2012 @author: diego ''' import re import sys import os import string try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient USE_BROWSER = True # Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity } if USE_BROWSER: package = 'com.android.browser' activity = '.BrowserActivity' else: package = 'com.android.chrome' activity = 'com.google.android.apps.chrome.Main' component = package + "/" + activity uri = 'http://dtmilano.blogspot.com' device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) ViewClient.sleep(5) vc = ViewClient(device, serialno)
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on May 5, 2012 @author: diego ''' import sys import os import time try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient vc = ViewClient(*ViewClient.connectToDeviceOrExit()) for bt in ['One', 'Two', 'Three', 'Four', 'Five']: b = vc.findViewWithText(bt) if b: (x, y) = b.getXY() print("clicking b%s @ (%d,%d) ..." % (bt, x, y), file=sys.stderr) b.touch() else: print("b%s not found" % bt, file=sys.stderr) time.sleep(7) print("bye", file=sys.stderr)
#! /usr/bin/env python ''' Copyright (C) 2014 Diego Torres Milano Created on Apr 24, 2014 @author: diego ''' import sys import os try: sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient kwargs1 = {'verbose': True, 'ignoresecuredevice': True} kwargs2 = {'startviewserver': True, 'forceviewserveruse': True, 'autodump': False, 'ignoreuiautomatorkilled': True} vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2) windows = vc.list() for wId in windows.keys(): print(">>> window=", wId, windows[wId]) vc.dump(window=wId) vc.traverse(transform=ViewClient.TRAVERSE_CITCD, indent=" ")
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Feb 1, 2012 @author: diego ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient package = 'com.android.settings' activity = '.Settings' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() if True: device.startActivity(component=component)
| / \ / \ / \ / \ \___ |/ \_/ \_/ \_/ \ o \ \_____/--< @author: Diego Torres Milano @author: Jennifer E. Swofford (ascii art snake) ''' import re import sys import os from androidviewclient3.viewclient import ViewClient if len(sys.argv) < 2: sys.exit("usage: %s /path/to/filename.png [serialno]" % sys.argv[0]) filename = sys.argv.pop(1) kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { 'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True } vc = ViewClient(device, serialno, **kwargs2) vc.dump(window='-1') vc.findViewWithContentDescriptionOrRaise('''Home screen 3''').writeImageToFile( filename, 'PNG')
#! /usr/bin/env python # -*- coding: utf-8 -*- """ Copyright (C) 2013-2018 Diego Torres Milano Created on 2018-03-29 by Culebra v15.1.0 __ __ __ __ / \ / \ / \ / \ ____________________/ __\/ __\/ __\/ __\_____________________________ ___________________/ /__/ /__/ /__/ /________________________________ | / \ / \ / \ / \ \___ |/ \_/ \_/ \_/ \ o \ \_____/--< @author: Diego Torres Milano @author: Jennifer E. Swofford (ascii art snake) """ import re import sys import os try: sys.path.insert( 0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient TAG = 'CULEBRA' _s = 5 _v = '--verbose' in sys.argv kwargs1 = { 'ignoreversioncheck': False, 'verbose': False,
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Feb 3, 2012 This example starts the TemperatureConverter activity then type '123' into the 'Celsius' field. Then a ViewClient is created to obtain the view dump and the current values of the views with id/celsius and id/fahrenheit are obtained and the conversion printed to stdout. Finally, the fields are obtained by using their tags and again, conversion printed to stdout. If --localViewServer is passed in the command line then LocalViewServer provided by TemperatureConverter is used. This is very useful when the device is secure and ViewServer cannot be started. @author: diego ''' import re import sys import os import time # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Aug 31, 2012 @author: diego ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient, ViewNotFoundException vc = ViewClient(*ViewClient.connectToDeviceOrExit()) if vc.useUiAutomator: print("ViewClient: using UiAutomator backend") # Find the 3 toggle buttons, because the first 2 change their text if they are selected # we use a regex to find them. # Once found, we touch them changing their state
# otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient package = 'com.example.trashcan' activity = '.FullScreenActivity' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() #device.startActivity(component=component) #ViewClient.sleep(3) vc = ViewClient(device, serialno) button = vc.findViewWithTextOrRaise('Button') button.touch() toggle = vc.findViewWithTextOrRaise(re.compile('(ON)|(OFF)')) toggle.touch()
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Aug 15, 2012 @author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient, View START_ACTIVITY = True FLAG_ACTIVITY_NEW_TASK = 0x10000000 package = 'com.android.settings' activity = '.Settings' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() if START_ACTIVITY: device.startActivity(component=component, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(3) vc = ViewClient(device, serialno) # this may help you find the attributes for specific Views #vc.traverse(vc.getRoot()) text = 'Display' view = vc.findViewWithText(text) if view:
#! /usr/bin/env python2.7
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Apr 30, 2013 @author: diego ''' import sys import os # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient ViewClient(*ViewClient.connectToDeviceOrExit(verbose=True)).traverse( transform=ViewClient.TRAVERSE_CIT)
#!/usr/bin/env python #! /usr/bin/env shebang monkeyrunner -plugin $ANDROID_VIEW_CLIENT_HOME/bin/androidviewclient-$ANDROID_VIEW_CLIENT_VERSION.jar @! # # Linux: #! /usr/local/bin/shebang monkeyrunner -plugin $AVC_HOME/bin/androidviewclient-$AVC_VERSION.jar @! # # Other: #! /path/to/monkeyrunner -plugin /path/to/androidviewclient/bin/androidviewclient-2.3.14.jar # # No shebang: # c:>path\to\monkeyrunner -plugin \path\to\androidviewclient-2.3.13.jar dump-all-windows-lib.py ''' Copyright (C) 2012 Diego Torres Milano Created on Apr 30, 2013 @author: diego ''' from androidviewclient3.viewclient import ViewClient kwargs2 = {'autodump': False, 'forceviewserveruse': True} vc = ViewClient(*ViewClient.connectToDeviceOrExit(), **kwargs2) windows = vc.list() for wId in windows.keys(): print(">>> window=", wId, windows[wId]) vc.dump(window=wId) vc.traverse(transform=ViewClient.TRAVERSE_CIT, indent=" ")
Copyright (C) 2012 Diego Torres Milano Created on Feb 3, 2012 @author: diego ''' import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=True) vc = ViewClient(device=device, serialno=serialno, startviewserver=False) vc.findViewWithTextOrRaise("New activity").touch()
#! /usr/bin/env python2.7 ''' Copyright (C) 2012 Diego Torres Milano Created on Feb 5, 2012 @author: diego ''' import sys import os import unittest # PyDev sets PYTHONPATH, use it if 'PYTHONPATH' in os.environ: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) try: sys.path.insert( 0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import View, TextView, EditText, ViewClient # Script gets stuck on ViewClient(device, serial) #243 d, s = ViewClient.connectToDeviceOrExit() input('\n** Disconnect the device now and press <ENTER>') device = ViewClient(d, s)
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Oct 12, 2012 @author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient VPS = "javascript:alert(document.getElementsByTagName('html')[0].innerHTML);" USE_BROWSER = True if USE_BROWSER: package = 'com.android.browser' activity = '.BrowserActivity' _id = 'id/no_id/12' else: package = 'com.android.chrome' activity = 'com.google.android.apps.chrome.Main' _id = 'id/no_id/28' component = package + "/" + activity uri = 'http://dtmilano.blogspot.com' device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) ViewClient.sleep(5)
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Aug 31, 2013 @author: diego ''' import sys import os from androidviewclient3.viewclient import ViewClient if len(sys.argv) < 2: sys.exit("usage: %s filename.png [serialno]" % sys.argv[0]) filename = sys.argv.pop(1) device, serialno = ViewClient.connectToDeviceOrExit(verbose=False) device.takeSnapshot().save(filename, 'PNG')
#! /usr/bin/env python ''' Copyright (C) 2012 Diego Torres Milano Created on Feb 3, 2012 @author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from androidviewclient3.viewclient import ViewClient # 01-04 18:23:42.000: I/ActivityManager(4288): Displayed com.android.development/.DevelopmentSettings: +379ms package = 'com.android.development' activity = '.DevelopmentSettings' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component) ViewClient.sleep(5) vc = ViewClient(device, serialno) showCpu = vc.findViewWithTextOrRaise("Show CPU usage") showLoad = vc.findViewWithTextOrRaise("Show running processes") alwaysFinish = vc.findViewWithTextOrRaise("Immediately destroy activities") if not showLoad.isChecked(): print("touching @", showLoad.getCenter()) showLoad.touch() if not alwaysFinish.isChecked():