如何在shell(终端)中执行monkeyrunner命令

发布于 2024-12-22 00:42:48 字数 587 浏览 1 评论 0原文

当我从 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”命令?

When I start my scrip from the shell I do something like this

monkeyrunner myScriptFile

and then

in myScriptFile I have content like this

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

and everything works fine, but I want to do something more fancy :), I want to write everything from the terminal(shell)

so is it possible to write everything in shell ? I mean is it possible the commands that are written in myScriptFile to be executed directly in shell without additional file like myScriptFile

or with other words is it possible to execute the 'from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice' command in shell ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光①夏 2024-12-29 00:42:48
  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
  1. To install package you can use adb instead of monkeyrunner:

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

  2. if you write shell script, you can use shell here string syntax to avoid separate file with monkeyrunner script:

#!/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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文