MR_ Android view client source code(3)---获取当前view id的名称

本文详细介绍了如何使用MonkeyRunner进行Android应用的自动化启动测试,包括设备连接、组件运行及截图解析等关键步骤。
#!/usr/bin/env monkeyrunner
# -*- coding:utf-8 -*-
'''
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.tuangoui.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()

for i in range(1,50):
    id_list=vc.findViewByIdOrRaise('id/no_id/%d'%i)

    print id_list.getText().encode("utf-8")



creating directory /ops/portal/workspace/14/pid/ 2025-12-10 13:42:54.222 MainProcess WARNING pg_lib.py (776): <CODE:5320> Fail to query dolphin.sql_mode. 2025-12-10 13:42:54.230 MainProcess WARNING pg_lib.py (792): The B compatibility parameter enable_set_variable_b_format fail to be set. 2025-12-10 13:42:54.235 MainProcess WARNING pg_lib.py (792): The B compatibility parameter b_compatibility_user_host_auth fail to be set. 2025-12-10 13:42:54.291 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. 2025-12-10 13:42:54.300 MainProcess INFO global_lib.py (520): Dropping the replica schema 2025-12-10 13:42:54.300 MainProcess DEBUG pg_lib.py (2944): Trying to connect to the destination database. 2025-12-10 13:42:54.300 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. 2025-12-10 13:42:54.306 MainProcess INFO chameleon.py (94): drop_replica_schema finished. 2025-12-10 13:42:56.410 MainProcess WARNING pg_lib.py (776): <CODE:5320> Fail to query dolphin.sql_mode. 2025-12-10 13:42:56.417 MainProcess WARNING pg_lib.py (792): The B compatibility parameter enable_set_variable_b_format fail to be set. 2025-12-10 13:42:56.420 MainProcess WARNING pg_lib.py (792): The B compatibility parameter b_compatibility_user_host_auth fail to be set. 2025-12-10 13:42:56.466 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. 2025-12-10 13:42:56.474 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. Traceback (most recent call last): File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/bin/chameleon.py", line 67, in <module> replica = replica_engine(args) File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/pg_chameleon/lib/global_lib.py", line 143, in __init__ source_count = self.pg_engine.check_source() File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/pg_chameleon/lib/pg_lib.py", line 3081, in check_source stmt = self.pgsql_conn.prepare(sql_check % (self.source, )) File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/py_opengauss/driver/pq3.py", line 2343, in prepare ps._fini() File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/py_opengauss/driver/pq3.py", line 1520, in _fini self.database._pq_complete() File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/py_opengauss/driver/pq3.py", line 2623, in _pq_complete self.typio.raise_error(x.error_message, cause = getattr(x, &#39;exception&#39;, None)) File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/py_opengauss/driver/pq3.py", line 544, in raise_error self.raise_server_error(error_message, **kw) File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/lib/python3.6/site-packages/py_opengauss/driver/pq3.py", line 535, in raise_server_error raise server_error py_opengauss.exceptions.SchemaNameError: schema "sch_chameleon" does not exist CODE: 3F001 LOCATION: SERVER POSITION: 79 STATEMENT: [parsing] LINE: sch_chameleon.t_sources ^ [line 5, character 17] statement_id: py:0x7fa7b9663860 string: SELECT count(*) FROM sch_chameleon.t_sources WHERE t_source=&#39;mysql&#39;; CONNECTION: [idle] client_address: 192.168.10.18/32 client_port: 62923 version: gaussdb (GaussDB Kernel 505.1.0.SPC0100 build 4573308e) compiled at 2024-05-22 16:20:58 commit 8495 last mr 17944 release CONNECTOR: [IP4] pq://root:***@192.168.10.16:30100/postgres?[sslmode]=disable category: None DRIVER: py_opengauss.driver.pq3.Driver Traceback (most recent call last): File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/bin/chameleon", line 5, in <module> exec(compile(open(__file__).read(), __file__, &#39;exec&#39;)) File "/ops/portal/tools/chameleon/chameleon-7.0.0rc3/venv/bin/chameleon.py", line 72, in <module> if (replica.config[&#39;dump_json&#39;] and (args.command == &#39;init_replica&#39; or args.command == &#39;start_view_replica&#39; or args.command == &#39;start_trigger_replica&#39; or args.command == &#39;start_func_replica&#39; or args.command == &#39;start_proc_replica&#39;)): NameError: name &#39;replica&#39; is not defined 2025-12-10 13:43:00.689 MainProcess WARNING pg_lib.py (776): <CODE:5320> Fail to query dolphin.sql_mode. 2025-12-10 13:43:00.700 MainProcess WARNING pg_lib.py (792): The B compatibility parameter enable_set_variable_b_format fail to be set. 2025-12-10 13:43:00.703 MainProcess WARNING pg_lib.py (792): The B compatibility parameter b_compatibility_user_host_auth fail to be set. 2025-12-10 13:43:00.758 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. 2025-12-10 13:43:00.767 MainProcess INFO global_lib.py (520): Dropping the replica schema 2025-12-10 13:43:00.767 MainProcess DEBUG pg_lib.py (2944): Trying to connect to the destination database. 2025-12-10 13:43:00.767 MainProcess DEBUG pg_lib.py (769): There is already a database connection active. 2025-12-10 13:43:00.770 MainProcess INFO chameleon.py (94): drop_replica_schema finished.
最新发布
12-11
评论 11
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值