Android 以编程方式自动化触摸事件

Android programmatically automated touch events

我想知道是否有任何方法可以对自动触摸事件进行编程?例如,我有我的 android 应用程序,我想制作一个程序,自动进行 100 次测试,并且每次测试都会根据应用程序上显示的内容进行触摸事件。我想在模拟器上做这个,如果可能的话,同时进行所有 100 次测试。

要使用许多(超过 100 个事件)锻炼您的应用程序,请使用 monkey(全名:UI/Application Exerciser Monkey)or/and monkeyrunner.

The Monkey is a command-line tool that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.

The Monkey includes a number of options, but they break down into four primary categories:

Basic configuration options, such as setting the number of events to attempt.

  • Operational constraints, such as restricting the test to a single package.
  • Event types and frequencies.
  • Debugging options.

站点:http://developer.android.com/intl/es/tools/help/monkey.html

基本使用:

$ adb shell monkey [options] <event-count>

例子

adb shell monkey -p your.package.name -v 500

因此,如果您想控制 Android 系统事件并且熟悉 Python 和编写测试脚本,那么您可以使用 monkeyrunner.

The monkeyrunner tool provides an 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.

文档:http://developer.android.com/intl/es/tools/help/monkeyrunner_concepts.html

NOTE: The monkeyrunner tool is not related to the I/Application Exerciser Monkey, also known as the monkey tool. The monkey tool runs in an adb shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.