Connecting Emulators and Real Android Devices with Airtest for Seamless Mobile Automation
This guide walks you through using Airtest to connect Android emulators, Windows desktop apps, and real Android phones—both via USB and Wi‑Fi—covering required developer settings, driver installation, input method configuration, and sample connection scripts.
Introduction
Hello, I am the IT sharing host known as Pipi. In the previous articles we covered Airtest installation and IDE widget details; this article demonstrates how to use the Airtest emulator to connect a phone for mobile automation testing.
Preface
Some may think capturing mobile data packets or automating a phone is difficult, but the Airtest automation tool handles everything—just keep it running and it will perform all operations on your device automatically.
Connect Devices
1. Connect Emulator Phone with Airtest
Open the Airtest emulator, go to "About Tablet" and enable the developer options by tapping the version number repeatedly. Then enable USB debugging.
After enabling USB debugging, use Airtest to connect remotely to the emulator. The remote port number depends on the emulator model; the correspondence table is shown below.
Choose the appropriate host address and port, then click connect to establish the connection.
If the screen appears black, ensure the screen capture program yosemite.apk is installed in the emulator and drag it into the emulator before reconnecting.
use javacap: #解决IDE中手机画面黑屏的问题
use ADB orientation: #解决IDE中屏幕旋转的问题
use ADB touch: #解决IDE中屏幕无法点击的问题2. Connect Windows Desktop Application
Airtest can also attach to already opened or unopened desktop applications. Select the target window (e.g., 360 Browser) and load it into Airtest. The original desktop window will disappear while Airtest controls it; disconnecting the device restores the window.
3. Android Real Device Connection
1) Enable Developer Options
Connect the phone via USB, enable Developer Options and USB debugging, then set the default USB configuration to MIDI .
2) Install Phone Drivers
Download the appropriate driver package for your device brand. Example driver links:
三星: http://www.samsung.com/cn/support/downloads
华为: http://consumer.huawei.com/minisite/HiSuite_cn/
小米: http://bigota.d.miui.com/tools/xiaomi_usb_driver.rar
Vivo: http://zs.vivo.com.cn/download.php
魅族: http://care.meizu.com/
一加: http://service.oneplus.cn/
华硕: http://www.asus.com.cn/support/
联想: http://www.lenovocare.com.cn/default.aspx
LG: http://www.lg.com/us/support/software-firmware-drivers
索尼: https://developer.sony.com/develop/drivers/
摩托罗拉: http://mobilesupport.lenovo.com/us/en/solution/MS88481
HTC: http://www.htc.com/us/software/htc-sync-manager/
谷歌: https://developer.android.com/studio/run/win-usb.html
黑莓: https://swdownloads.blackberry.com/Downloads/entry.do?code=4EE0932F46276313B51570F46266A608
戴尔: http://www.dell.com/support/home/us/en/04/Products?app=drivers&lwp=rt
宏基: https://www.acer.com/ac/en/US/content/drivers3) Configure Input Method and Mock Location
Install the yosemite input method (automatically downloaded after driver installation) and set it as the default input method.
Enable mock location in Developer Options if mouse clicks are inaccurate.
4) Connect the Device
In Airtest, check Use Javacap and click Connect to establish the connection.
5) Wireless Connection to Android Device
Find the device's IP address (shown in the phone settings) and use it in Airtest. The default port is 5555; you can open other ports with the command below. adb tcpip 666 #开启666端口 Both the phone and the IDE must be on the same Wi‑Fi network.
6) Connect via Script
Create a script file in the editor and use the following code to connect:
connect_device('Android://127.0.0.1:5037/手机IP地址:5555') #前面是本机号和端口后面就是你手机的IP地址了Again, ensure the phone and IDE share the same Wi‑Fi network.
Conclusion
The Airtest automation tool is straightforward to use, though its installation can be cumbersome for beginners. This article covered device connection methods, driver setup, input configuration, and sample scripts to help you get started with mobile automation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
