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

时间:2011-12-21 09:01:39

标签: android linux bash shell monkeyrunner

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

1 个答案:

答案 0 :(得分:0)

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

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

  2. 如果您编写shell脚本,则可以使用shell here字符串语法来避免使用monkeyrunner脚本单独的文件:

  3. #!/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