当我从shell启动我的脚本时,我会做这样的事情
monkeyrunner myScriptFile
然后
在myScriptFile中我有这样的内容
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
device.installPackage('myproject/bin/MyApplication.apk')
.....
一切正常,但我想做更多花哨的事情:),我想从终端(shell)写一切
所以可以在shell中编写所有内容吗?我的意思是,在myScriptFile中编写的命令可以直接在shell中执行而不需要像myScriptFile这样的附加文件
或者换句话说可以在shell中执行'from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice'命令吗?
答案 0 :(得分:0)
要安装软件包,您可以使用adb
代替monkeyrunner
:
adb install -r 'myproject/bin/MyApplication.apk'
如果您编写shell脚本,则可以使用shell here字符串语法来避免使用monkeyrunner脚本单独的文件:
#!/bin/bash
./monkeyrunner <<EOL
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Takes a screenshot
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('1.png','png')
EOL