简体   繁体   English

Monkeyrunner 脚本不运行,但命令有效

[英]Monkeyrunner script doesn't run, but commands work

If I run Monkeyrunner manually and execute the following 3 commands:如果我手动运行 Monkeyrunner 并执行以下 3 个命令:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

device = MonkeyRunner.waitForConnection()

device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)

Everything works, I see that the home key is pressed.一切正常,我看到按下了主页键。 However, if I save those 3 commands into a .py file, and then try to run the file, I get the following:但是,如果我将这 3 个命令保存到 .py 文件中,然后尝试运行该文件,则会得到以下信息:

....\MonkeyRunner Scripts>monkeyrunner BasicTest.py
Can't open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE

    -s      MonkeyServer IP Address.
    -p      MonkeyServer TCP Port.
    -v      MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO,
WARNING, SEVERE, OFF)

I decided to try the -v switch to see what it say's, and I got the following:我决定尝试使用 -v 开关看看它说的是什么,我得到了以下信息:

....\MonkeyRunner Scripts>monkeyrunner -v BasicTest.
py
Exception in thread "main" java.lang.IllegalArgumentException: Bad level "BasicT
est.py"
        at java.util.logging.Level.parse(Unknown Source)
        at com.android.monkeyrunner.MonkeyRunnerOptions.processOptions(MonkeyRun
nerOptions.java:130)
        at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter
.java:179)

Any ideas on what's going on here?关于这里发生了什么的任何想法?

I've figured it out.我已经想通了。 It doesn't make a whole lot of sense, but the only way I can get the scripts to work is run monkeyrunner from it's directory, rather than placing the path to monkeyrunner in my PATH.它没有多大意义,但我可以让脚本工作的唯一方法是从它的目录运行monkeyrunner,而不是将monkeyrunner的路径放在我的PATH中。 Also, the script itself also has to be in the same directly as the monkeyrunner.exe.此外,脚本本身也必须直接与monkeyrunner.exe 相同。

Does this make any sense to anyone out there?这对外面的人有意义吗?

it works on any folder sending the content of the file as input它适用于任何将文件内容作为输入发送的文件夹

monkeyrunner < ./my_script.py monkeyrunner < ./my_script.py

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

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