我正在尝试实现Androidviewclient来运行基于视图的脚本,有什么办法可以像使用“ device.installPackage()”使用Monkeyrunner一样使用androidviewclient安装新程序包吗?
最佳答案
编辑
AndroidViewClient/culebra版本11.0.7实现了ViewClient.installPackage()
,并且还引入了新的命令行选项--install-apk
,该选项基于APK的安装结果生成测试先决条件。有关详细信息,请参见https://github.com/dtmilano/AndroidViewClient/wiki/Test-Cookbook#installing-apks-as-preconditions。installPackage
尚未在AdbClient
中实现,因为可以将其替换为subprocess
:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014 Diego Torres Milano
Created on 2015-11-14 by Culebra v10.8.2
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import subprocess
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
TAG = 'CULEBRA'
_s = 5
_v = '--verbose' in sys.argv
kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
vc = ViewClient(device, serialno, **kwargs2)
apk="/path/to/my/app-debug.apk"
subprocess.check_call([vc.adb, "install", "-r", apk], shell=False)