0

I am really new to python, Cmonkeyrunner and android. I am trying to automate android application and using dtmilano AndroidViewClient

I have installed python 2.7.9 on Windows 8, extracted AndroidViewClient-master.zip to C drive, after that I installed android viewclient using easy_install When I am running a simple py script with monkeyrunner I am getting the error mismatched input 'as' expecting CLONE in dtmilano viewclient.py

My code look like this:

    ! /usr/bin/env monkeyrunner
    import re
    import sys
    import os
    import java
    import glob
    import os


    sys.path.append('C:\AndroidViewClient-master\src')
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
    from com.dtmilano.android.viewclient import ViewClient

    try:
        ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
    except KeyError:
        print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" % __file__
        sys.exit(1)

    device= MonkeyRunner.waitForConnection(15)
mydir=r'C:\Android SDK\adt-bundle-windows\sdk\tools'

apk_path = device.shell('pm path com.sample.test')
if apk_path.startswith('package:'):
    print "Test app is already installed."
else:
    print "Test app is not installed, installing..."
    os.chdir(mydir)
    MonkeyRunner.sleep(1)
    app = "Test.apk"
    device.installPackage(mydir+"/"+app)
    MonkeyRunner.sleep(5)

print "Launching Resource Test app"
device.startActivity(component='com.sample.test/com.sample.test.MainActivity')
MonkeyRunner.sleep(5)

My path variable is:

C:\Android SDK\adt-bundle-windows\sdk\tools;C:\Python27;C:\Python27\Scripts

Please tell me whats wrong here? Do I need to install a different version of python.

This the error I am getting:

C:\Users\Desktop>monkeyrunner test1.py
150520 11:10:35.203:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
150520 11:10:35.203:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
  File "C:\Android SDK\adt-bundle-windows\sdk\tools\test1.py", line 12, in <module>
    from com.dtmilano.android.viewclient import ViewClient
SyntaxError: ("mismatched input 'as' expecting COLON", ('C:\\AndroidViewClient-master\\src\\com\\dtmilano\\android\\viewclient.py', 3708, 35, ''))

C:\Users\Desktop>

And the line 12 in test1.py is:

from com.dtmilano.android.viewclient import ViewClient

Line 3708 is viewclient.py is:

except ImportError as ex:

Please help.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
James Bond
  • 45
  • 1
  • 5

1 Answers1

0

From my personal experience, you should install AndroiviewClient with easy_install and pypi, that is the official site for python packages, AndroidViewClient is very often updated there too, you should only use the package from github for development only, for any further AndroidViewClient updates, just type easy_install --upgrade AndroidViewClient:
1) Go to your Python folder and type: easy_install AndroiViewClient, it will automatically load AndroidViewClient from http://pypi..., the package will be setup in the folder C:\Python27\Lib\site-packages\androidviewclient-10.4.0-py2.7.egg (that is my current version)
2) Download the package from github, and set it anywhere you want, no easy_install or whatever, just unzip it. I just use this package to test python check-import.py as suggested in the wiki, the program check-import.py only exists in this package.
3) If I remember well, I don't even need to setup any environment variables for AndroidViewClient, just add the Python folder into the environment variable path.
4) Start Culebra to see how the generated script looks like, it will simplify your life in the beginning to understand the structure, if you use Culebra in the beginning you will not see errors like monkeyrunner, that is just an example.

AbrtFus
  • 29
  • 7