我有一个应用程序,我想为它运行 Monkeyrunner(使用 Android ViewClient)
我试图将我的观点定义为
Vc = ViewClient(device, serialno)
vc.dump
touchProject = vc.findViewByIdorRaise('id/projectNewGallery')
touchProject.touch()
但我收到错误:->"com.dtmilano.android.viewclient.ViewNotFoundException: Couldn't find View with ID='id/projectNewGallery' in tree with root=ROOT"
我怎样才能设置根?像这样 ?
touchProject = vc.findViewByIdorRaise('id/projectNewGallery','id/projectMain')
? ///////////////////////////////////////// ////////////////////////////
我正在尝试使用 culebra 工具,但出现以下错误。
$ java -jar androidviewclient-2.3.16.jar culebra
ERROR: monkeyrunner was not found and Windows 7 does not support shebang in scripts. Aborting.
我也尝试过这种方式(Non-Shebang OS -> Windows 7)
$ /cygdrive/c/android-sdk/tools/monkeyrunner.bat -plugin /cygdrive/c/Android_Resources_Hassan/MonkeyRunner_KIneMaster/AndroidViewClient-master/AndroidViewClient/bin/androidviewclient-2.3.22.jar culebra myscript.py
Plugin file doesn't exist
Usage: monkeyrunner [options] SCRIPT_FILE
-s MonkeyServer IP Address.
-p MonkeyServer TCP Port.
-v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)
好的,我能够运行它 Windows CMD :
C:\android-sdk\tools>monkeyrunner -plugin C:\Android_Resources_Hassan\MonkeyRunner_KIneMaster\androidviewclient-2.3.24.jar test3_py.py
但我再次收到以下错误:
130619 14:41:15.725:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130619 14:41:15.725:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "C:\android-sdk\tools\test3_py.py", line 71, in <module>
touchProject = vc.findViewByIdOrRaise('id/projectNewGallery')
File "C:\Android_Resources_Hassan\MonkeyRunner_KIneMaster\AndroidViewClient- master\AndroidViewClient\src\com\dtmilano\android\viewclient.py", line 1919, in findViewById
OrRaise raise ViewNotFoundException("ID", viewId, root)
com.dtmilano.android.viewclient.ViewNotFoundException: Couldn't find View with ID='id/projectNewGallery' in tree with root=ROOT
我的脚本文件--------
#! /usr/bin/env monkeyrunner
'''
Copyright (C) 2012 Diego Torres Milano
Created on Feb 3, 2012
@author: diego
'''
import re
import sys
import os
# 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)
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, MonkeyDevice
#starting script
print "start"
# Connects to the current device, returning a MonkeyDevice object
device, serialno = ViewClient.connectToDeviceOrExit()
#device connected
print "connection started"
# sets a variable with the package's internal name
package = 'com.example.app.myApp'
# sets a variable with the name of an Activity in the package
activity = 'com.example.mainapp.MainActivity'
# 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 4 seconds"
# first screen shot event
MonkeyRunner.sleep(4);
vc = ViewClient(device, serialno)
vc.dump()
root = vc.getRoot()
#touchProject = vc.findViewWithTextOrRaise('', root)
touchProject = vc.findViewByIdOrRaise('projectNewGallery')
touchProject.touch()
# wait for screenshot to save
MonkeyRunner.sleep(2);
# Takes a screenshot
result1 = device.takeSnapshot()
result1.writeToFile('/myPath/shot1.png','png')
# wait for 3 seconds
MonkeyRunner.sleep(3);
is ID same as defined in XML android:id="+id/newProjectGallery" ?
////////////////////// AFTER adding vc.traverse() in code///////////////////
I am getting following error
130620 10:07:43.775:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130620 10:07:43.775:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "C:\android-sdk\tools\test.py", line 71, in <module>
ViewClient(*ViewClient.connectToDeviceOrExit()).traverse(transform=ViewClient.TRAVERSE_CIT)
File "C:\Android_Resources_Hassan\MonkeyRunner\AndroidViewClient- master\AndroidViewClient\src\com\dtmilano\android\viewclient.py", line 1687, in traverse
print >>stream, "%s%s" % (indent, s)
LookupError: unknown encoding 'ms949'
Moreover I ran dump-simple.py code also. But I am getting again the same error :
130620 10:07:43.775:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130620 10:07:43.775:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "C:\android-sdk\tools\dump-simple.py", line 30, in <module>
ViewClient(*ViewClient.connectToDeviceOrExit()).traverse(transform=ViewClient.TRAVERSE_CIT)
File "C:\Android_Resources_Hassan\MonkeyRunner\AndroidViewClient- master\AndroidViewClient\src\com\dtmilano\android\viewclient.py", line 1687, in traverse
print >>stream, "%s%s" % (indent, s)
LookupError: unknown encoding 'ms949'
what is causing it ? Please help me ~
Thanks