MonkeyRunner_用monkeyrunner点击view中的id/text

    以前代码是有问题的,我会不断完善,争取早日可以使用。

#! /usr/bin/env monkeyrunner

'''Copyright (C) 2012 Diego Torres MilanoCreated on Feb 3, 2012@author: diego'''
import re
import sys
import os
import failstry
 # this must be imported before MonkeyRunner and MonkeyDevice,
'''import failstry:
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')
'''
# 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
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Displayed com.android.development/.DevelopmentSettings: +379ms
package = 'com.android.development'
activity = '.DevelopmentSettings'
componentName = package + "/" + activity
device = MonkeyRunner.waitForConnection(60, "emulator-5554")
if not device:
    raise Exception('Cannot connect to device')
device.startActivity(component=componentName)
MonkeyRunner.sleep(5)
vc = ViewClient(device)
vc.dump()
showCpu = vc.findViewById("id/show_cpu")
showLoad = vc.findViewById("id/show_load")
alwaysFinish = vc.findViewById("id/always_finish")
if not showLoad.isChecked():
    showLoad.touch()
if not alwaysFinish.isChecked():
    alwaysFinish.touch()
if not showCpu.isChecked():
# WARNING: Show CPU usage is de-activated as soon as it's activated, that's why it seems it
# is never set showCpu.touch() Once we run this script against a running emulator or device we will be able to see how the settings are enabled.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值