Skip to content
This repository was archived by the owner on Oct 11, 2019. It is now read-only.
Mingyuan Xia edited this page May 25, 2017 · 9 revisions

replaykit.py

Appetizer replaykit is a command-line tool for recording and replaying Android touchscreen events for test automation, debugging, etc. replaykit.py is its Python SDK. Both projects are cross-platform, available for Windows 7+, MacOS Mavericks+ and Linux x64. replaykit.py supports Python 2.7 and 3.3 to 3.6.

pre-requisite

  • Download replaykit.
  • Install adb from Android SDK; make sure adb is in your PATH.
  • Enable ADB debugging on the device and connect your android devices via USB with your PC. Type adb devices to make sure devices are ready. If you are using XiaoMi devices, please also enable ADB debugging (security) feature.

Installation

pip install appetizer

Usage

All SDK methods are documented with docstrings. Make sure to refer to docstring for detailed description of the functionality, parameter types, and return values. An Appetizer object is used to request all appetizer services. Initialize the Appetizer object to find replaykit like this:

from appetizer import Appetizer
appetizer = Appetizer(toolkit='path/to/the/replaykit/executable') # e.g., './replaykit/linux/appetizer' for linux, or './replaykit/win32/appetizer.exe' for windows

Device Control

Replaykit can perform a same command on multiple devices, like a parallel adb.

# list all devices connected to the development machine
print (appetizer.devices.list())
# take a screen shot from one device
appetizer.devices.take_screenshot("path/to/save/jpg/file", "serial_number")
# install an APK file to multiple devices
appetizer.devices.control(["serialno1", "serialno2"], 'install', ['path/to/APK/file'])
# launch an app
appetizer.devices.control(["serialno1", "serialno2"], 'launch_pkg', ['com.example.app'])
# execute a shell command and get the result
print(appetizer.devices.control(["serialno1", "serialno2"], 'shell', ['ls | grep system'])
# Device mirroring: synchronize the touchscreen input events from one device (master) to many (slaves), in real-time
task = appetizer.devices.mirror("master_serialno", ["slave_serialno1", "slave_serialno2"])
# the task object returned represents the running mirror task
time.sleep(5)
task.stop()

Trace Management

Trace management services allow users to record/replay touchscreen input events.

# record a trace from one device
record_task = appetizer.trace.record("path/to/trace/file", "device_serial_number")
time.sleep(10)
record_task.stop()
# replay a trace to multiple devices of the same aspect ratio as the original recording device
appetizer.trace.replay("path/to/trace/file", ['serialno1', 'serialno2'])
# get trace information (e.g., length, aspect ratio, etc)
print(appetizer.trace.get_info("path/to/trace/file"))

ADB server control

ADB is the unified channel that Appetizer communicates with devices. ADB binary is required and ADB server must be running properly on the development machine. The below APIs demonstrate how to control the local ADB server.

# start the local adb server
appetizer.adb.start_server()
# stop the local adb server
appetizer.adb.kill_server()
# check the details of the running adb server
print(appetizer.adb.check_server())
# detect the path to adb binary in the Android SDK
print(appetizer.adb.detect_adb())

Troubleshooting

Clone this wiki locally