121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "/home/aaa/workspace/AndroidViewClient/tao800/app_selectid.py", line 36, in <module>
vc = ViewClient(device)
TypeError: __init__() takes at least 3 arguments (2 given)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyException.fillInStackTrace(PyException.java:70)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at java.lang.Throwable.<init>(Throwable.java:198)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at java.lang.Exception.<init>(Exception.java:46)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at java.lang.RuntimeException.<init>(RuntimeException.java:49)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyException.<init>(PyException.java:46)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyException.<init>(PyException.java:43)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyException.<init>(PyException.java:61)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.Py.TypeError(Py.java:195)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyBaseCode.call(PyBaseCode.java:275)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyFunction.__call__(PyFunction.java:385)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyFunction.__call__(PyFunction.java:380)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyInstance.__init__(PyInstance.java:120)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyClass.__call__(PyClass.java:194)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyObject.__call__(PyObject.java:397)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyObject.__call__(PyObject.java:401)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.pycode._pyx0.f$0(/home/aaa/workspace/AndroidViewClient/tao800/app_selectid.py:40)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.pycode._pyx0.call_function(/home/aaa/workspace/AndroidViewClient/tao800/app_selectid.py)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyTableCode.call(PyTableCode.java:165)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.PyCode.call(PyCode.java:18)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.Py.runCode(Py.java:1197)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)
121213 13:37:13.553:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189)
源代码如下:
#! /usr/bin/env monkeyrunner
'''
Copyright (C) 2012 Diego Torres Milano
Created on May 5, 2012
@author: diego
'''
import sys
import os
import time
# this must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails
'''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)
'''
ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')
from com.dtmilano.android.viewclient import ViewClient
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device=MonkeyRunner.waitForConnection(20, 'emulator-5554')
if not device:
raise Exception('Cannot connect to device')
MonkeyRunner.sleep(5)
package="com.aaa.bbb"
activity="com.aaa.bbb.LaunchActivity"
runComponent=package+'/'+activity
device.startActivity(component=runComponent)
#device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device)
vc.dump()
print 'hello'
address= vc.findViewById('search')
address.type('india')