0

当我从外壳开始我的脚本时,我会做这样的事情

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' 命令?

4

1 回答 1

0
  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
于 2012-02-23T11:47:00.997 回答