Use Monkeyrunner for continuous screenshot of Android screen

Source: Internet
Author: User

Monkeyrunner What is Monkeyrunner

The Monkeyrunner tool provides an API for programs written out using this API to control Android devices and emulators outside of Android code. With Monkeyrunner, you can write a Python program to install an Android application or test package, run it, send it an analog keystroke, intercept its user interface picture, and store it on your workstation. The main purpose of the Monkeyrunner tool is to test applications and devices at the functional/framework level, or to run unit test suites.

The difference between Monkeyrunner and Monkey Monkey tool runs directly in the ADB shell of the device or simulator, generating a pseudo-random stream of events for the user or system. The Monkeyrunner tool is a specific command and event control device or simulator that is defined on the workstation through the API, which supports, writes plugins, controls events, anytime, in short, anything you can do in a simulator/device, Monkeyrunner is capable, It can also be recorded and played back.

test type of Monkeyrunner

1. Multi-Device control: The Monkeyrunner API can implement test suites across multiple devices or emulators. You can pick up all the devices at the same time or start all the simulators at once (or all together), connect to each one by program, and then run one or more tests. You can also use a program to start a configured emulator, run one or more tests, and then close the emulator.

2. Functional test: Monkeyrunner can automatically implement a functional test for an application. You provide input values for keystrokes or touch events, and then observe the screenshots of the output results.

3. Regression test: Monkeyrunner can run an app and compare its result screenshot to a given known good result screenshot to test the application's stability.

4. Scalable Automation: Because Monkeyrunner is an API toolkit, you can develop a complete set of systems based on Python modules and programs to control your Android device. In addition to using the Monkeyrunner API, you can use the standard Python OS and subprocess modules to invoke Android tools such as Android Debug Bridge.

Run Monkeyrunner

You can run Monkeyrunner directly with a code file, or enter the Monkeyrunner statement in an interactive conversation. Either way, you need to invoke the Monkeyrunner command under the tools subdirectory of the SDK directory. If you provide a file name as a running parameter, Monkeyrunner will view the file content as a Python program and run it, otherwise it will provide an interactive dialog environment.

Monkeyrunner Basic Syntax
Monkeyrunner-plugin <plugin_jar> <program_filename> <program_options>

Specific introduction ... See Official documents (http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html)

Here is the implementation:

#!/home/arcticant/android-sdks/tools/monkeyrunnerfrom com.android.monkeyrunner Import Monkeyrunner, Monkeydevice "" "Enter CTRL + C to end" "Def Androidshot ():    #set The  interval between    and the screenshot Sleeptime = 3           #connect device     print "Start ..."    device = monkeyrunner.waitforconnection ()      # Begin to take snapshot    i = 0;    While I <: result = device.takesnapshot () filename = str (i) + ". png" Print filename result.writetofi Le (filename, ' png ') monkeyrunner.sleep (sleeptime) i = i + 1if __name__ = = ' __main__ ': Androidshot ()  

Requires Monkeyrunner to run this script

The General Android-sdks folder has Monkeyrunner

No write end code, ubuntu under direct CTRL + C End Program


Note: It's a good idea to save this one after running this script, and the second run overwrites the results of the first build.

Using Monkeyrunner to achieve Android screen continuous

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.