繁体   English   中英

如何在Shell(终端)中执行Monkeyrunner命令

[英]how to execute monkeyrunner commands in shell (terminal)

当我从外壳开始笔录时,我会做类似的事情

monkeyrunner myScriptFile

接着

在myScriptFile中,我有这样的内容

    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
    device = MonkeyRunner.waitForConnection()
    device.installPackage('myproject/bin/MyApplication.apk')
.....

并且一切正常,但是我想做更多花哨的事情:),我想从terminal(shell)编写一切

那么有可能在shell中编写所有内容吗? 我的意思是说,写在myScriptFile中的命令是否可以在shell中直接执行而无需像myScriptFile这样的附加文件

或者换句话说,可以在shell中执行“从com.android.monkeyrunner导入MonkeyRunner,MonkeyDevice”命令吗?

  1. 要安装软件包,您可以使用adb代替monkeyrunner

    adb install -r 'myproject/bin/MyApplication.apk'

  2. 如果编写shell脚本,则可以在此处使用shell字符串语法,以避免使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM