当我写一个使用monkeyrunner的python脚本时,我发现脚本无法获得我想要的getProperty
的返回值。该脚本仅获取None
结果。
这是python代码,我想要getProperty
的返回值:
#-*-coding:utf-8-*-
# import module
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
# connect service
device = MonkeyRunner.waitForConnection()
print device.getProperty("build.ID")
print device.getProperty("activity")
print device.getSystemProperty('build.version.sdk')
结果是None
。
我不知道出了什么问题。请审核并提供反馈。
这是运行结果:
这是我编写的整个脚本:
#-*-coding:utf-8-*-
# import module
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice,
MonkeyImage
# connect service
device = MonkeyRunner.waitForConnection()
# screenshot
result = device.takeSnapshot()
result.writeToFile('E:\\Taskmanagetest_1\\testresult\\Test_001.jpg','jpg')
# install apk
device.installPackage('E:\\Taskmanagetest_1\\app\\build\\outputs\\apk\\debug\\app-debug.apk')
# sleep
MonkeyRunner.sleep(5)
# screenshot
result = device.takeSnapshot()
result.writeToFile('E:\\Taskmanagetest_1\\testresult\\Test_002.jpg','jpg')
# print device.getProperty("am.current.comp.package")
print('Install Success!')
# test
device.startActivity(component="com.example.samuel_soon.taskmanagetest_1/.Ma"
"inActivity")
MonkeyRunner.sleep(5)
result = device.takeSnapshot()
result.writeToFile('E:\\Taskmanagetest_1\\testresult\\Test_003.jpg','jpg')
device.touch(520,520,'DOWN_AND_UP')
MonkeyRunner.sleep(5)
result = device.takeSnapshot()
result.writeToFile('E:\\Taskmanagetest_1\\testresult\\Test_004.jpg','jpg')
print device.getProperty("build.ID")
print device.getProperty("activity")
print device.getSystemProperty('build.version.sdk')
device.removePackage("com.example.samuel_soon.taskmanagetest_1")
print('Remove Success!')
result = device.takeSnapshot()
result.writeToFile('E:\\Taskmanagetest_1\\testresult\\Test_005.jpg','jpg')
您可以使用AndroidViewClient/culebra生成可编辑的脚本并添加print
语句
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018 Diego Torres Milano
Created on 2019-03-26 by Culebra v15.5.1
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""
from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device, serialno)
print device.getProperty("ro.build.id")
print device.getTopActivityName()
print device.getSystemProperty("ro.build.version.sdk")
并在执行时打印预期值
OSM1.180201.007
com.google.android.apps.nexuslauncher/.NexusLauncherActivity
27