5,598,086 Members 42,920 Now Online
XDA Developers Android and Mobile Development Forum

[Test Automation Tool] [Android] MonkeyRunner on Eclipse [RHBROMS]

Tip us?
 
Ravi H Basawa
Old
(Last edited by Ravi H Basawa; 14th December 2013 at 05:18 AM.)
#1  
Ravi H Basawa's Avatar
Senior Member - OP
Thanks Meter 890
Posts: 394
Join Date: Jun 2012
Location: gadag

 
DONATE TO ME
Thumbs up [Test Automation Tool] [Android] MonkeyRunner on Eclipse [RHBROMS]





Quote:
This will be a Full Tutorial on MonkeyRunner Android Automation Tool
I will be updating this thread as I get time. SO NO ETA's.
Quote:
If anybody wants to use / copy this tutorial to their Website or Blog please feel free to contact me at my personal email id: edy.434@gmail.com
or at our official Website: www.rhbroms.com
Quote:
Please Click on Thanks button if this tutorial by me had helped you for some extent !!!

Table of Contents:

1. Monkeyrunner

2. What all we need before we get it started?

3. How to setup monkeyrunner in Eclipse?

4. How to write and execute monkeyrunner Script?

5. Limitations of monkeyrunner
 
Ravi H Basawa
Old
(Last edited by Ravi H Basawa; 12th December 2013 at 11:42 AM.)
#2  
Ravi H Basawa's Avatar
Senior Member - OP
Thanks Meter 890
Posts: 394
Join Date: Jun 2012
Location: gadag

 
DONATE TO ME
Smile monkeyrunner

1.monkeyrunner

monkeyrunner is a automation tool which provides us to conduct BlackBox testing on android applications.

The monkeyrunner tool provides a Python API for writing programs that control an Android device or emulator from outside of Android code.
With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation.

The monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for running unit test suites, but you are free to use it for other purposes.

2.What all we need before we get it started?

We need the below:

1. Windows 7/8 OS
2. Java 6
3. Eclipse
4. Android device running min android version 2.3.4*
5. Python
6. Jython
7. Application to be tested

*Are not mandatory.

DOWNLOADS:

SimpleCalc app sourcecode: SimpleCalc
 
Ravi H Basawa
Old
(Last edited by Ravi H Basawa; 14th December 2013 at 05:16 AM.)
#3  
Ravi H Basawa's Avatar
Senior Member - OP
Thanks Meter 890
Posts: 394
Join Date: Jun 2012
Location: gadag

 
DONATE TO ME
3.How to setup monkeyrunner in Eclipse?

1. First download Python from this site: http://www.python.org/getit/

2. Second download Jython.jar file from this site: http://www.jython.org/downloads.html

3. Download the Jython Installer from this site: https://wiki.python.org/jython/DownloadInstructions

3. After downloading the above files install Python.

4. Basic Install for Jython:
After downloading Jython installer, either double click the jython_installer-2.5.2.jar or run java with the -jar option

Quote:
java -jar jython_installer-2.5.2.jar
5. Now after completion of this we will move to Eclipse and download PyDev from Eclipse market place as shown below:



6. When finished install, Go to Window->Preferences->PyDev->Interpreters
- Jython interpreters : Click [new...] and got o the path where you have installed Jython. For me it is at C:/jython/jython.jar
- Libraries : Click [New Jar/Zip(s)] and enter your ANDROID_SDK_PATH/tools/lib/monkeyrunner.jar

as shown below:



7. After this Go to Window->Preferences->PyDev->Interpreters->
- Python interpreters : Click [new...] and got o the path where you have installed Python. For me it is at C:/Python33/python.jar

as shown below:

 
Ravi H Basawa
Old
(Last edited by Ravi H Basawa; 14th December 2013 at 05:53 AM.)
#4  
Ravi H Basawa's Avatar
Senior Member - OP
Thanks Meter 890
Posts: 394
Join Date: Jun 2012
Location: gadag

 
DONATE TO ME
4. How to write and execute monkeyrunner Script?

1. Go to File-> New -> PyDev Project -> Give any project Name and select Jython as shown below:



2. Now right click on the newly created project -> New -> PyDev Module



3. Give any Name to the project but leave the package field empty as shown below:



4. After this Just copy paste the below code:

Quote:
'''
Created on Dec 11, 2013

@author: RHB
'''


from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice


# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
device.installPackage('C:/Users/rhb/workspace/SimpleCalc/bin/SimpleCalc.apk')

# sets a variable with the package's internal name
package = 'com.rhb.simplecalc'

# sets a variable with the name of an Activity in the package
activity = 'com.rhb.simplecalc.MainActivity'

# sets the name of the component to start
runComponent = package + '/' + activity

# Runs the component
device.startActivity(component=runComponent)


# Presses the Menu button
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)

# Enters the value 12 into the first edit text box
device.type('12')

# clicks on the second edit test box of SimpleCalc application that i have provided at the beginning of the post.
device.touch(87,448,'DOWN_AND_UP')

# Enters the value 3 into the second edit text box
device.type('3')


#Clicks on the multiplication button
device.touch(386,650,'DOWN_AND_UP')

# Takes a screenshot
result = device.takeSnapshot()

# Writes the screenshot to a file
result.writeToFile('C:/Users/rhb/workspace/SimpleCalc/shot1.png','png')
5. Before executing the above code make sure that you have installed the SimpleCalc app to your device. To do this you can use the below adb command:

Quote:
adb install SimpleCalc.apk
7. To execute this we need to do some customization as explained below:

7a. Go to Run-> External Tools -> External Tools Configurations... . as shown below:



7b. Now select Location as monkeyrunner.bat. Select your working Directory and also write arguments as shown below:



8. Click on Run button and you are good to go
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes