#!/usr/bin/env monkeyrunner
'''
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
#Actual device serialno=emulator-5554
try:
ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
except KeyError:
print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" % __file__
sys.exit(1)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')
from com.dtmilano.android.viewclient import ViewClient
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner as mr, MonkeyDevice as md
#starting script
print "start"
# Connects to the current device, returning a MonkeyDevice object
device, serialno = ViewClient.connectToDeviceOrExit(30,"emulator-5554")
#device connected
print "connection started"
# sets a variable with the package's internal name
package = 'com.tuangou.taobao
# sets a variable with the name of an Activity in the package
activity = '.activities.StartActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
#device set to sleep for 4 seconds
print "wait for 10 seconds"
# first screen shot event
mr.sleep(10);
vc = ViewClient(device, serialno)
vc.dump()
root = vc.getRoot()
#touchProject = vc.findViewWithTextOrRaise('', root)
touchProject = vc.findViewByIdOrRaise('id/title_right_tv')
touchProject.touch()
# wait for screenshot to save
mr.sleep(2);
# Takes a screenshot
result1 = device.takeSnapshot()
result1.writeToFile('shot11.png','png')
# wait for 3 seconds
mr.sleep(3);
'''
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
#Actual device serialno=emulator-5554
try:
ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
except KeyError:
print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" % __file__
sys.exit(1)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')
from com.dtmilano.android.viewclient import ViewClient
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner as mr, MonkeyDevice as md
#starting script
print "start"
# Connects to the current device, returning a MonkeyDevice object
device, serialno = ViewClient.connectToDeviceOrExit(30,"emulator-5554")
#device connected
print "connection started"
# sets a variable with the package's internal name
package = 'com.tuangou.taobao
# sets a variable with the name of an Activity in the package
activity = '.activities.StartActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
#device set to sleep for 4 seconds
print "wait for 10 seconds"
# first screen shot event
mr.sleep(10);
vc = ViewClient(device, serialno)
vc.dump()
root = vc.getRoot()
#touchProject = vc.findViewWithTextOrRaise('', root)
touchProject = vc.findViewByIdOrRaise('id/title_right_tv')
touchProject.touch()
# wait for screenshot to save
mr.sleep(2);
# Takes a screenshot
result1 = device.takeSnapshot()
result1.writeToFile('shot11.png','png')
# wait for 3 seconds
mr.sleep(3);
在 android platform 2.2上运行出现以下警告:
AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py:763: UserWarning: Unsupported Android version 8
warnings.warn("Unsupported Android version %d" % self.build[VERSION_SDK_PROPERTY])