#! /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'
#! /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 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 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 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)