What is monkeyrunner
The monkeyrunner tool provides an API that can be used to control Android devices and emulators outside of Android code. With monkeyrunner, you can write a Python program to install an Android app or test package, run it, send it a simulated keystroke, intercept its user interface image, and store the screenshot on your workstation. The main purpose of the monkeyrunner tool is to test applications and devices at the functional/framework level, or to run a unit test suite, but you can of course use it for other purposes as well.
The difference between the monkeyrunner tool and the Monkey tool
Monkey:
The Monkey tool runs directly in the adb shell of the device or emulator, generating a pseudo-random event stream for the user or system.
Monkeyrunner:
The monkeyrunner tool is a specific command and event control device or simulator defined on the workstation via the API.
Monkeyrunner test type1. Multi-device control: The monkeyrunner API can implement test suites across multiple devices or simulators. You can connect all the devices at the same time or start all the simulators at once (or unify them), connect to each one according to the program, and then run one or more tests. You can also use the program to launch a configured emulator, run one or more tests, and then close the emulator.
2. Functional Testing: monkeyrunner can automatically perform a functional test for an application. You provide an input value for a button or touch event, and then observe a screenshot of the output.
3. Regression testing: monkeyrunner can test the stability of an application by running an application and comparing the resulting screen capture to a screen shot of a known known correct result.
4. Extensible Automation: Since monkeyrunner is an API toolkit, you can develop a complete system based on Python modules and programs to control Android devices. In addition to using the monkeyrunner API, you can use standard Python os and subprocess modules to call Android tools like adb.
5. The monkeyrunner tool uses Jython (a Python implementation of the Java programming language). Jython allows the monkeyrunner API to easily interact with the Android framework. With Jython, you can use Python syntax to get constants, classes, and methods in the API.
Running monkeyrunner
You can run monkeyrunner directly from a code file, or enter a monkeyrunner statement in an interactive dialog. Either way, you need to call the monkeyrunner command in the tools subdirectory of the SDK directory. If you provide a filename as a run parameter, then monkeyrunner will treat the contents of the file as a Python program and run it; otherwise, it will provide an interactive dialog environment.
The command syntax of monkeyrunner is:
Monkeyrunner -plugin "plugin_jar" "program_filename" "program_opTIons"
Monkeyrunner test tutorial
If you need to implement automated testing, Android's monkeyrunner tool can help you automate testing. It provides a set of APIs that can be used to control Android devices or emulators. With monkeyrunner, you can write Python programs to install Android apps or test packages. Run the app or test, send a button message, and take a screenshot and save it on your computer. The main purpose of monkeyrunner is to test the application or run the unit test package at the application or framework level, but you can also use it for other purposes.
The monkeyrunner toolkit is different from the UI/ApplicaTIon Exerciser Monkey (also known as Money). Money runs through the adb shell and can simulate "Monkey" random buttons or send system messages to a specified application for Stress testing.
The monkeyrunner API mainly uses the following three packages:
MonkeyRunner: It mainly provides helper methods for monkeyrunner applications, methods for linking devices or emulators, and UI support.
MonkeyDevice: Represents a device or emulator that provides methods for installing, uninstalling an application, launching an AcTIvity, sending a button or a Touch event.
MonkeyImage: Represents a screenshot image that can capture images in different formats, compare two MonkeyImage images, save images, and more.
The following is a monkeyrunner application written in Python. Because it involves the Python language, it is not explained in detail here.
[python] view plain copy# Imports the monkeyrunner modules used by this program
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('myproject/bin/MyApplication.apk')
# sets a variable with the package's internal name
Package = 'com.example.android.myapplication'
# sets a variable with the name of an Activity in the package
Activity = 'com.example.android.myapplication.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', 'DOWN_AND_UP')
# Takes a screenshot
Result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('myproject/shot1.png','png')
For detailed API descriptions, please refer to the Android documentation. If you need to implement automatic testing, write test code, you can use Python to implement through the monkeyrunner API.
AC DC power adapter 48v,48v power supply adapter,universal power adapter 48v,48v dc adapter
ShenZhen Yinghuiyuan Electronics Co.,Ltd , https://www.yhypoweradapter.com