A Python-based Android app automation testing tool that can automatically perform app operations and capture corresponding network traffic.
This project aims to automate testing of Android applications while simultaneously capturing their network traffic data. By combining uiautomator2, adb, and mitmdump tools, the project can automatically perform app operations (such as opening apps, searching content, etc.) and record the app's network communication data for subsequent analysis.
- Android app automation operations (based on uiautomator2)
- Network traffic capture (using adb tcpdump)
- HTTPS traffic decryption (using mitmdump and SSLKEYLOGFILE)
- Multi-process management and control
- Supports automation testing for apps like YouTube and Reddit
main.py- Main entry file for starting tests for different appsbeans/- App-specific automation operation implementationsyoutube.py- Automation operations for YouTube appreddit.py- Automation operations for Reddit app
utils/- Utility classesprocess.py- Process management and traffic capture functionalityrandom_string.py- Random string generation utility
- Start mitmdump proxy server and set up SSL key log file
- Start tcpdump on Android device for traffic capture
- Connect to device via uiautomator2 and perform app operations
- Terminate all related processes after operations are completed
- Generate paired data containing app operations and corresponding network traffic
- Ensure Developer Options and USB Debugging are enabled on the Android device
- Create pcap directory on Android device:
adb shell mkdir -p /data/local/tmp/pcap/ - Ensure tcpdump tool is installed on the device and has execution permissions
- mitmdump in
process.pyuses upstream proxy mode (--mode upstream:http://127.0.0.1:7897), ensure a proxy service is available on local port 7897 - SSL key log files will be saved in
C:/Users/nstl/Downloads/extract/key/directory, ensure this path exists and is writable - Traffic capture files (.pcap) will be saved in
/data/local/tmp/pcap/directory on the Android device
- Install mitmproxy man-in-the-middle environment and install the man-in-the-middle certificate on the test device. For details, refer to: https://docs.mitmproxy.org/stable/
- Install uiautomator2. For details, refer to: https://github.com/openatx/uiautomator2
- Write scripts for the apps you need to collect data from, you can refer to beans/youtube.py
- Run main.py.