Releases: AirtestProject/Airtest
v1.4.3
v1.4.2
v1.3.6
v1.3.5
v1.3.4
v1.3.3
ADD:
touch,swipe接口新增相对坐标的支持- 例如点击中心点 touch((0.5, 0.5))
- 从右往左滑动 swipe((0.7, 0.5), (0.2, 0.5))
- 目前android/ios/win都支持
- windows新增了剪贴板相关的接口
get_clipboard获取剪贴板内容,set_clipboard设置剪贴板内容,paste粘贴- 因此如果有大段文字需要输入,原本使用text接口将会一个一个输入,效率很低,现在可以使用
set_clipboard设置到剪贴板之后,再使用paste粘贴即可 - 剪贴板三个接口目前win/ios/android都支持了
- Android支持手动指定
touch_method,来强制指定ADBTOUCH, 或MINITOUCH,MAXTOUCHdev.touch_method = "ADBTOUCH"
FIX:
- Yosemite.apk更新,新增了判断输入法是否完全启动的接口,避免输入失败
- 修复了某些低版本iOS设备使用swipe接口会报错的问题(报错信息为:
Invalid parameter not satisfying: allAttributesForKey != nil) - 修复了1.3.2版本引入的adb路径为None的bug
- 修复了部分安卓设备屏幕只显示一半,并且无法恢复的问题
ADD:
touch,swipeinterfaces add support for relative coordinates- For example, click the center point touch((0.5, 0.5))
- Swipe from right to left swipe((0.7, 0.5), (0.2, 0.5))
- Currently supported by android/ios/win
- Windows has added some new clipboard-related interfaces
get_clipboardgets the clipboard content,set_clipboardsets the clipboard content,pastepastes- Therefore, if there is a large section of text that needs to be entered, the original text interface will be entered one by one, which is very inefficient. Now you can use
set_clipboardto set it to the clipboard, and then usepasteto paste it. - The three clipboard interfaces are currently supported by win/ios/android.
- Android supports manually specifying
touch_methodto force specifyingADBTOUCH, orMINITOUCH,MAXTOUCHdev.touch_method = "ADBTOUCH"
FIX:
- Yosemite.apk has been updated, adding an interface to determine whether the input method is fully started to avoid input failures.
- Fixed an issue where some lower version iOS devices would report an error when using the swipe interface (the error message is:
Invalid parameter not satisfying: allAttributesForKey != nil) - Fixed the bug that the adb path introduced in version 1.3.2 is None
- Fixed the issue where the screen of some Android devices is only half displayed and cannot be restored
v1.3.2
- 【重要】ADB升级至41版本,与之前的ADB版本不兼容,请注意保证系统环境中所有的ADB版本一致,否则可能会导致无法连接设备
- iOS模块新增一个Error类型,
LocalDeviceError,部分接口只有本地USB连接的iOS设备才可以用,远程设备将会抛出这个异常。因此若有需要,可以catch住这个异常,并对远程设备做一些额外的兼容和处理。 - 更新了yosemite.apk,对一些设备的兼容性更好
- 修复了一些其他问题
- [Important] ADB has been upgraded to version 41, which is incompatible with previous ADB versions. Please ensure that all ADB versions in the system environment are consistent, otherwise the device may not be connected.
- The iOS module adds a new Error type,
LocalDeviceError. Some interfaces can only be used by local USB-connected iOS devices, and the remote device will throw this exception. Therefore, if necessary, you can catch this exception and do some additional compatibility and processing for the remote device. - Updated yosemite.apk to have better compatibility with some devices
- Fixed some other issues
v1.3.1
- 报告中现在将会显示connect_device接口连接的设备
- ios和android设备在连接时,支持传入name参数,用于指定它的udid(ios)或serial number(android)
例如:ios:///http://10.240.145.171:20092?name=83282c400efc9122e3bcba60c803cf318a6b3822
安卓远程设备:android://127.0.0.1:5037/10.227.71.86:20029?name=serialno - adb现在将会优先使用当前的adb进程,或者是系统变量设置了ANDROID_HOME中的adb,如果都找不到,才会使用airtest里的adb。
同时也支持直接指定adb_path,例如:
from airtest.core.android.android import Android, ADB
adb = ADB(adb_path=r"D:\adb\adb.exe")
# 或者可以初始化一个指定了adb_path的Android设备对象
dev = Android(serialno="5TSSMVBYUSEQNRY5", adb_path=r"D:\test\adb41\adb.exe")
- 剪贴板的相关接口增加了安卓的支持,增加了粘贴接口(
paste,效果等同于执行text(get_clipboard()))
text = "test_clipboard"
set_clipboard(text)
get_text = get_clipboard()
print(get_text) # -> test_clipboard
paste() # => text(get_clipboard())
bug修复:
修复了一些小问题
如果遇到了手机画面只有一半的情况,重新连接画面即可恢复。
- The report will now display the devices connected to the connect_device interface.
- When connecting ios and android devices, the name parameter can be passed in to specify its udid (ios) or serial number (android)
For example:ios:///http://10.240.145.171:20092?name=83282c400efc9122e3bcba60c803cf318a6b3822
Android remote device:android://127.0.0.1:5037/10.227.71.86:20029?name=serialno - adb will now give priority to using the current adb process, or the system variable is set to adb in ANDROID_HOME. If neither is found, adb in airtest will be used.
It also supports directly specifyingadb_path, for example:
from airtest.core.android.android import Android, ADB
adb = ADB(adb_path=r"D:\adb\adb.exe")
# Or specify adb_path when initializing the Android object
dev = Android(serialno="5TSSMVBYUSEQNRY5", adb_path=r"D:\test\adb41\adb.exe")
- The relevant interfaces of the clipboard have been added with Android support and a paste interface (
paste, the effect is equivalent to executingtext(get_clipboard()))
text = "test_clipboard"
set_clipboard(text)
get_text = get_clipboard()
print(get_text) # -> test_clipboard
paste() # => text(get_clipboard())
bug fixes:
Fixed some minor issues
If you encounter a situation where the screen on your phone is only half full, you can restore the screen by reconnecting.
v1.3.0
重要改动
从airtest v1.3.0起,放弃对python2的支持
新增
ios设备接口新增
iOS设备对象IOS,新增以下接口的支持:
- (仅支持本地USB设备)安装
install
install(r"D:\demo\test.ipa") # install iOS ipa
install("http://www.example.com/test.ipa") # install iOS ipa from url
或
#获取当前设备
dev = device()
#通过本地.ipa文件安装APP
dev.install_app(r"D:\demo\test.ipa") # install iOS ipa
#通过下载链接安装APP
dev.install_app("http://www.example.com/test.ipa") # install iOS ipa from url
- (仅支持本地USB设备)卸载
uninstall
uninstall("com.netease.cloudmusic")
或
dev = device()
dev.uninstall_app("com.netease.godlike")
- (仅支持本地USB设备)列出所有的app,
list_app
list_app("user") 传入要列出的app类型,可以得到app列表
参数可选user/system/all 分别表示列出用户安装的app/系统app/全部app
返回值示例:[('com.apple.mobilesafari', 'Safari', '8.0'), ...]
dev = device()
#列出全部APP
all_app = dev.list_app("all")
print(all_app)
#打印系统APP
print(dev.list_app("system"))
#列出用户安装的APP
user_app = dev.list_app("user")
print(user_app)
- 获取剪贴板内容,
get_clipboard
text = get_clipboard()
print(text)
注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id才能使用:
text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
- 设置剪贴板内容,
set_clipboard
注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id才能使用
set_clipboard("content") # local iOS
# When the iOS device is a remote device, or more than one wda is installed on the device, you need to specify the wda_bundle_id
set_clipboard("content", wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
iOS新增tidevice相关接口
针对本地USB接入的设备,airtest结合tidevice的能力,封装了一个TIDevice对象,提供了几个常用接口如下:
devices:列出USB连接的所有设备的 UDID 列表list_app: 列出手机上安装的应用列表,支持对类型进行筛选,包括 user/system/alllist_wda: 列出手机上安装的所有WDA的bundleIDdevice_info:获取手机信息install_app:安装ipa包,支持本地路径或URLuninstall_app:卸载bundle_id对应的包体start_app:启动 bundle_id 对应的包体stop_app:停止 bundle_id 对应的包体ps: 获取当前的进程列表ps_wda: 获取当前启动中的WDA列表xctest:启动wda
可以参考:https://github.com/AirtestProject/Airtest/blob/master/tests/test_tidevice.py
代码执行效果示例:
>>> from airtest.core.ios.ios import TIDevice
>>> devices = TIDevice.devices()
>>> print(devices)
['10da21b9091f799891557004e4105ebab3416cb9']
>>> udid = devices[0]
>>> print(TIDevice.list_app(udid))
[ ('com.230316modified.WebDriverAgentRunner.xctrunner', 'wda-Runner', '1.0'),]
>>> print(TIDevice.list_app(udid, "system"))
[('com.apple.calculator', 'Calculator', '1.0.0'),]
>>> print(TIDevice.list_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
>>> print(TIDevice.device_info(udid))
{'productVersion': '12.4.8', 'productType': 'iPhone7,2', 'modelNumber': 'MG472', 'serialNumber': 'DNPNW6EJG5MN', 'timeZone': 'Asia/Shanghai', 'uniqueDeviceID': '10da21b9091f799891557004e4105ebab3416cb9', 'marketName': 'iPhone 6'}
>>>
>>> TIDevice.start_app(udid, "com.apple.mobilesafari")
>>> TIDevice.stop_app(udid, "com.apple.mobilesafari")
>>> print(TIDevice.ps(udid))
[ {'pid': 215, 'name': 'MobileMail', 'bundle_id': 'com.apple.mobilemail', 'display_name': 'MobileMail'}]
>>> print(TIDevice.ps_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
TIDevice.xctest接口的执行示例如下:
import threading
wda_bundle_id = TIDevice.list_wda(udid)[0]
# 创建一个线程,执行xctest
t = threading.Thread(target=TIDevice.xctest, args=(udid, wda_bundle_id), daemon=True)
t.start()
time.sleep(5)
ps_wda = TIDevice.ps_wda(udid)
print(ps_wda)
time.sleep(5)
# 终止线程
t.join(timeout=3)
using接口的改动
using接口的作用是,支持在脚本中引用另外一个脚本,同时还能够让airtest正确地读取到其他脚本中的图片路径。
假设目录结构如下:
demo/
foo/
bar.air
baz.air
main.py
如果我们希望在main.py中引用 foo/bar.air和baz.air,可以将项目根路径设置到ST.PROJECT_ROOT,或者确保项目根路径是当前工作目录:
# main.py
from airtest.core.api import *
ST.PROJECT_ROOT = r"D:\demo" # This line can be ignored if it is the current working directory
using("foo/bar.air")
using("baz.air")
如果我们希望在 foo/bar.air 中引用 baz.air,可以这样写:
# foo/bar.air
from airtest.core.api import *
using("../baz.air")
新增错误类型NoDeviceError
如果当前未连接任何设备,但又调用了某些需要连接设备才可以调用的接口时,抛出异常:NoDeviceError("No devices added.")
其他改动
- 当airtest脚本引发了assert异常时,退出码为20,以便和其他报错区分
- 更新了Yosemite.apk,修复了一些稳定性问题
- windows平台新增接口
set_focus,与原先的set_foreground功能相同
Important changes
From airtest v1.3.0, drop support for python2
add
ios function enhancement
iOS adds support for the following interfaces:
- (Only local USB devices are supported) Install
install
install(r"D:\demo\test.ipa") # install iOS ipa
install("http://www.example.com/test.ipa") # install iOS ipa from url
or
# Get the current device
dev = device()
#Install APP through local .ipa file
dev.install_app(r"D:\demo\test.ipa") # install iOS ipa
#Install the APP through the download link
dev.install_app("http://www.example.com/test.ipa") # install iOS ipa from url
- (Only local USB devices are supported) Uninstall
uninstall
uninstall("com.netease.cloudmusic")
or
dev = device()
dev.uninstall_app("com.netease.godlike")
- (Only support local USB devices) list all apps,
list_app
list_app("user") Pass in the app type to be listed, and you can get the app list
Optional parameter user/system/all means to list the app installed by the user/system app/all apps respectively
Return value example: [('com.apple.mobilesafari', 'Safari', '8.0'), ...]
dev = device()
#List all APPs
all_app = dev. list_app("all")
print(all_app)
#Print System APP
print(dev. list_app("system"))
#List the apps installed by the user
user_app = dev. list_app("user")
print(user_app)
- Get clipboard content,
get_clipboard
text = get_clipboard()
print(text)
Note: When the iOS device is a remote device, or more than one wda is installed, you need to specify a specific wda_bundle_id to use:
text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
- Set clipboard content,
set_clipboard
Note: When the iOS device is a remote device, or more than one wda is installed, you need to specify a specific wda_bundle_id to use
set_clipboard("content") # local iOS
# When the iOS device is a remote device, or more than one wda is installed on the device, you need to specify the wda_bundle_id
set_clipboard("content", wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
New tidevice related interface for iOS
For devices with local USB access, airtest combines the capabilities of tidevice to encapsulate a TIDevice object, providing several common interfaces as follows:
devices: list the UDIDs of all devices connected by USBlist_app: Lists the list of apps installed on the phone, supports filtering by type, including user/system/alllist_wda: list the bundleIDs of all WDAs installed on the phonedevice_info: get phone informationinstall_app: install ipa package, support local path or URLuninstall_app: Uninstall the package body corresponding to bundle_idstart_app: start the package body corresponding to bundle_idstop_app: Stop the package body corresponding to bundle_idps: get the current process listps_wda: Get a list of WDAs currently bootingxctest: start wda
You can refer to: https://github.com/AirtestProject/Airtest/blob/master/tests/test_tidevice.py
Example of code execution effect:
>>> from airtest.core.ios.ios import TIDevice
>>> devices = TIDevice.devices()
>>> print(devices)
['10da21b9091f799891557004e4105ebab3416cb9']
>>> udid = devices[0]
>>> print(TIDevice.list_app(udid))
[ ('com.230316modified.WebDriverAgentRunner.xctrunner', 'wda-Runner', '1.0'),]
>>> print(TIDevice.list_app(udid, "system"))
[('com.apple.calculator', 'Calculator', '1.0.0'),]
>>> print(TIDevice.list_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
>>> print(TIDevice.device_info(udid))
{'productVersion': '12.4.8', 'productType': 'iPhone7,2', 'modelNumber': 'MG472', 'serialNumber': 'DNPNW6EJG5MN', 'timeZone': 'Asia/Shanghai', 'uniqueDeviceID': '10da21b9091f799891557004e4105ebab3416cb9', 'marketName': 'iPhone 6'}
>>> TIDevice.start_app(udid, "com.apple.mobilesafari")
>>> TIDevice.stop_app(udid, "com.apple.mobilesafari")
>>> print(TIDevice.ps(udid))
[ {'pid': 215, 'name': 'MobileMail', 'bundle_id': 'com.apple.mobilemail', 'display_name': 'MobileMail'}]
>>> print(TIDevice.ps_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
The execution example of the TIDevice.xctest interface is as follows:
import threading
wda_bundle_id = TIDevice.list_wda(udid)[0]
# Create a thread to execute xctest
t = threading.Thread(target=TIDevice.xctest, args=(udid, wda_bundle_id), daemon=True)
t. start()
time. sleep(5)
ps_wda = TIDevice.ps_wda(udid)
print(ps_wda)
time. sleep(5)
# Terminate thread
t.join(timeout=3)
Changes to the using interface
The function of the using interface is to support another script to be referenced in the script, and at the same time, it can also allow airtest to correctly read the image path in other scripts.
Suppose the directory structure is as follows:
demo/
foo/
bar.air
baz.air
main.py
If we want to reference foo/bar.air and baz.air in main.py, we can set the project root path to ST.PROJECT_ROOT, or make sure the project root path is the current working directory:
# main.py
from airtest.core.api import *
ST.PROJECT_ROOT = r"D:\demo" # This line can b...
v1.2.10.2
录屏相关
Android录屏目前提供两种模式,yosemite和ffmpeg,区别如下:
yosemite:原有的默认模式,录屏清晰度和质量较高,但兼容性较差,部分机型可能有问题- 支持的参数:
orientation,max_time,bit_rate,bit_rate_level
- 支持的参数:
ffmpeg: 在1.2.9之后加入的新模式,录屏帧率和质量较低,但兼容性更好,能兼容绝大多数设备- 支持的参数:
orientation,max_size,max_time,fps,snapshot_sleep
- 支持的参数:
在1.2.10.2中的改动:
- 在1.2.9中提供的
cv2模式已经被舍弃,因为容易引发错误,效果也不如ffmpeg - win/ios的start_recording 就无需再有mode参数,只有android需要mode参数
- 录屏的ffmpeg模式增加了max_size参数,能够指定录屏结果的图像大小,因为屏幕图片越大,在录屏时造成的系统负载越大(CPU和内存占用)
代码示例:
dev = connect_device("android:///")
dev.start_recording(output="test.mp4", mode="ffmpeg", max_size=800) # Android 支持mode指定使用ffmpeg模式
其他改动
- 如果Android出现了屏幕有一半黑屏的情况,可以再次重连
- 去掉了numpy的版本号限制
Record screen
Android screen recording currently provides two modes, yosemite and ffmpeg, the differences are as follows:
yosemite: the original default mode, the recording resolution and quality are higher, but the compatibility is poor, and some models may have problems- Supported parameters:
max_time,orientation,bit_rate,bit_rate_level
- Supported parameters:
ffmpeg: a new mode added after 1.2.9, the screen recording frame rate and quality are lower, but the compatibility is better, compatible with most devices- Supported parameters:
max_time,fps,max_size,snapshot_sleep
- Supported parameters:
Changes in 1.2.10.2:
- The
cv2mode provided in 1.2.9 has been abandoned, because it is prone to errors and the effect is not as good as ffmpeg - The start_recording of win/ios does not need to have the mode parameter, only android needs the mode parameter
- The ffmpeg mode of screen recording adds the max_size parameter, which can specify the image size of the screen recording result, because the larger the screen image, the greater the system load caused by the screen recording (CPU and memory usage)
Code example:
dev = connect_device("android:///")
dev.start_recording(output="test.mp4", mode="ffmpeg", max_size=800) # Android supports mode to specify the use of ffmpeg mode
Other changes
- If the Android screen is half black, you can reconnect again
- Removed numpy version number restriction