Monkeyrunner_importing from pythonpath

Source: Internet
Author: User

In previous post we analyzed what is needed to develop, run and debugmonkeyrunner scripts usingEclipseAndpydev.

#! /usr/bin/env monkeyrunner'''Created on Sep 10, 2012@author: diego'''import reimport sysimport osimport java# This must be imported before MonkeyRunner and MonkeyDevice,# otherwise the import fails.# PyDev sets PYTHONPATH, use ittry:    for p in os.environ['PYTHONPATH'].split(':'):       if not p in sys.path:          sys.path.append(p)except:    passtry:    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))except:    passfrom com.dtmilano.android.viewclient import ViewClient, Viewfrom com.android.monkeyrunner import MonkeyRunner, MonkeyDevice# usage: script [serialno]serialno = sys.argv[1] if len(sys.argv) > 1 else 'emulator-5554'device = MonkeyRunner.waitForConnection(30, serialno)try:    device.wake()except java.lang.NullPointerException, e:    print "ERROR: Couldn't connect to %s: %s" % (serialno, e)

These are the lines you shoshould add to every monkeyrunner script. Here you are a brief explanation of the snippet.

  1. The
    Shebang line to invoke
    Monkeyrunner interpreter if you are using Linux or Mac OS X. unfortunately this is not available on Windows. eclipse does not use this line but is needed if you want to simplify the way you are running the scripts from the command line.
  2. Some standard imports
  3. Pydev uses pythonpath whilemonkeyrunner ignores it. this snippet adds the components present inpythonpath
    To SYS. Path and makes them visible tomonkeyrunner.
  4. Following, We need to locateAndroidviewclientWhich you shoshould have added to the environment. This can be also added inEclipseInRun events-> Environment.
    Android_view_client_home shoshould point to yourAndroidviewclientInstallation to the parent folderSRC. That is, if you have downloadedAndroidviewclient
    In/opt/androidviewclient and kept the same structure as the distribution, you shoshould setAndroid_view_client_home =/opt/androidviewclient
  5. The imports, which will now succeed because SYS. path contains the right components
  6. Gets the device's serial number from the command line or default
    Emulator-5554.
  7. Connect to the device
  8. Check if the connection was successful. Because
    Monkeyrunner. waitforconnection () returns
    Monkeydevice even when the connection fails we need to go to this extra step to verify it.

Note: Enable pydev in eclipse, select interpreter monkeyrunner, configure the environment, and add variables.Android_view_client_home =/opt/androidviewclient, See

From: http://dtmilano.blogspot.ca/2012/09/monkeyrunner-importing-from-pythonpath.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.