-2

在下面的代码中,我如何使用我在 xml 布局文件中提到的按钮或任何视图的 ID。如果我运行 dump.py -i ,我会得到唯一的 id,但不是我在我的 xml 文件中提到的。

touchProject = vc.findViewByIdOrRaise('id/btnHome')
touchProject.touch()

如果我必须使用 Culebra,请告诉我设置环境和运行它的详细方法。我在环境变量中设置了 Android View Client Home。

谢谢

我当前的脚本如下所示

#! /usr/bin/env monkeyrunner
'''
Copyright (C) 2012  Diego Torres Milano
Created on Feb 3, 2012

@author: diego
'''


import re
import sys
import os
import java
# 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')
try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass
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 = 'org.droidtv.TvPlayerFunctionalTestApp'
# sets a variable with the name of an Activity in the package
activity = '.VideoViewActivity'
# 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(2);
vc = ViewClient(device, serialno)
vc.dump()
#root = vc.getRoot()
#touchProject = vc.findViewWithTextOrRaise('', root)
touchProject = vc.findViewByIdOrRaise('id/btnHome')
touchProject.touch()
# wait for screenshot to save
MonkeyRunner.sleep(2);
# Takes a screenshot
result1 = device.takeSnapshot()
result1.writeToFile('E:\NewApp\shot1.png','png')
# wait for 3 seconds
MonkeyRunner.sleep(2);
# Pressing Watch Tv Button
print "wait for NextButton to be pressed"
vc.dump()
touchProject = vc.findViewByIdOrRaise('id/no_id/6')
touchProject.touch()
MonkeyRunner.sleep(2);
result1 = device.takeSnapshot()
result1.writeToFile('E:\NewApp\WatchTv.png','png')
print "Wait for Home Button to be pressed"
vc.dump()
touchProject = vc.findViewByIdOrRaise('id/no_id/11')
touchProject.touch()
result1 = device.takeSnapshot()
result1.writeToFile('E:\NewApp\Home.png','png')
MonkeyRunner.sleep(2);
print "Pressing Channel Setting Button"
vc.dump()
touchProject = vc.findViewByIdOrRaise('id/no_id/11')
touchProject.touch
result1 = device.takeSnapshot()
result1.writeToFile('E:\NewApp\ChannelSetting.png','png')
MonkeyRunner.sleep(2)
4

1 回答 1

1

下载 AndroidViewClient 为我完成了这项工作。

于 2013-10-22T12:35:33.757 回答