0

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.

ad01
  • 43
  • 1
  • 10
  • First of all, you need to indent the block after `for i in range(5):`. Secondly, according to your traceback that's not what the line says: It looks like it's missing a colon (`('C:\\test\\autoclick.py', 10 , 17, 'for i in range(5)\n'))`. Are you sure you are showing exactly the code you are trying to compile? – David Robinson Oct 02 '13 at 03:10
  • Sorry about that, I do have an indent after `for i in range(5):`. Other then that, I am sure that this is exactly the code I am trying to compile. – ad01 Oct 02 '13 at 03:15
  • Can you edit the question (click the edit link below) and make the code exactly the same, including the indentation? Indentation matters in Python – David Robinson Oct 02 '13 at 03:16
  • The code is identical now. – ad01 Oct 02 '13 at 03:23
  • Aha! It was a missing colon. I was running a different, out of date version of my code, saved in a different place. – ad01 Oct 02 '13 at 04:23

0 Answers0