I'm trying to write a python script and run it through monkeyrunner. The script should automatically hit buttons in an android application at certain times.
When running this script through CMD (I'm using Windows):
Run in CMD:
monkeyrunner C:\test\autoclick.py
Python Script:
from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner, MonkeyImage, MonkeyManager
device= MonkeyDevice
for i in range(5):
device = MonkeyRunner.waitForConnection(8)
if device != None:
print "Device found..."
break;
device.press("KEYCODE_NOTIFICATION", "DOWN_AND_UP")
time.sleep(1)
device.press("KEYCODE_BACK", "DOWN_AND_UP")
I get the following error:
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
pt terminated due to an exception
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Synta
xError: ("mismatched input '\\n' expecting COLON", ('C:\\test\\autoclick.py', 10
, 17, 'for i in range(5)\n'))
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.fixParseError(ParserFacade.java:92)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.parse(ParserFacade.java:184)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.compile_flags(Py.java:1731)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:514)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:18
9)
I'm writing the script in Eclipse using Jython 2.5.3 and PyDev installed through the Eclipse update manager. My version of Python is 3.3.2. Any help would be appreciated!
Note: I was trying to test my setup using this tutorial, but it looks like it's a little out of date.