Monkeyrunner is an automated test tool provided by Android, and it also provides a Python interface that allows us to control the behavior of the app, such as installing apps, launching apps based on package name, clicking, sliding Events, and more. Using Monkeyrunner in eclipse requires some configuration:
1. Download and install Python;
2.eclipse install the Python plugin;
3. Download and install Jython.jar;
4. Configure Eclipse;
Since the first 3 steps are relatively simple, here is not too much to describe, the 4th step directly.
A. Configure the Python interpreter and click Window->preferences->pydev->interpreters, as shown in:
B. Configure Jython, click Window->preferences->pydev->interpreters, and add Monkeyrunner.jar to libraries, as shown in:
C. Next you can create a Jython project,
d. Finally, the creation of Python code, a simple code, copied from the Android website, this code includes the behavior: Install MYAPPLICATION.APK, Open mainactivity, click menu
from com.android.monkeyrunner import Monkeyrunner, monkeydevice# connects to the Current device, returning a monkeydevice Objectdevice = Monkeyrunner.waitforconnection () # Installs the Android package. Notice that this method returns a Boolean, so can test# to see if the installation Worked.device.installPackage (' Mypro ject/bin/myapplication.apk ') # sets a variable with the package ' s internal namepackage = ' Com.example.android.myapplication ' # Sets a variable with the name of an Activity in the packageactivity = ' Com.example.and Roid.myapplication.MainActivity ' # Sets the name of the component to Startruncomponent = package + '/' + activity# Runs the Componentdevice.startactivity (component=runcomponent) # presses the Menu buttondevice.press (' KEYCODE_MENU ', MONKEYDEVICE.DOWN_AND_UP) # Takes a screenshotresult = Device.takesnapshot () # writes the screenshot to a Fileresult.writeT Ofile (' myproject/shot1.png ', ' png ')
E. Run the code, actually I execute this code, rely on Android to provide Monkeyrunner.bat, so do not run the program as usual, right->run-> choose to execute the program, this time to use the Eclipse external Tools, click Run->external tools->external Tools configurations, and then add the relevant configuration information, such as:
Later, every time you execute it, you don't have to add it again.
Reference: http://forum.xda-developers.com/showthread.php?t=2566234
Monkeyrunner on Eclipse