Skip to content

Releases: AirtestProject/Airtest

v1.3.5

26 Sep 06:57
Compare
Choose a tag to compare
add tag for version 1.3.5

v1.3.4

30 Apr 07:18
Compare
Choose a tag to compare

ADD:

  • 增加了minicap对于Android 14版本的支持

ADD:

  • Added minicap support for Android 14 version.

v1.3.3

08 Jan 04:07
Compare
Choose a tag to compare

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, MAXTOUCH
    • dev.touch_method = "ADBTOUCH"

FIX:

  • Yosemite.apk更新,新增了判断输入法是否完全启动的接口,避免输入失败
  • 修复了某些低版本iOS设备使用swipe接口会报错的问题(报错信息为:Invalid parameter not satisfying: allAttributesForKey != nil
  • 修复了1.3.2版本引入的adb路径为None的bug
  • 修复了部分安卓设备屏幕只显示一半,并且无法恢复的问题

ADD:

  • touch, swipe interfaces 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_clipboard gets the clipboard content, set_clipboard sets the clipboard content, paste pastes
    • 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_clipboard to set it to the clipboard, and then use paste to paste it.
    • The three clipboard interfaces are currently supported by win/ios/android.
  • Android supports manually specifying touch_method to force specifying ADBTOUCH, or MINITOUCH, MAXTOUCH
    • dev.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

22 Nov 06:47
Compare
Choose a tag to compare
  1. 【重要】ADB升级至41版本,与之前的ADB版本不兼容,请注意保证系统环境中所有的ADB版本一致,否则可能会导致无法连接设备
  2. iOS模块新增一个Error类型,LocalDeviceError,部分接口只有本地USB连接的iOS设备才可以用,远程设备将会抛出这个异常。因此若有需要,可以catch住这个异常,并对远程设备做一些额外的兼容和处理。
  3. 更新了yosemite.apk,对一些设备的兼容性更好
  4. 修复了一些其他问题

  1. [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.
  2. 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.
  3. Updated yosemite.apk to have better compatibility with some devices
  4. Fixed some other issues

v1.3.1

28 Sep 03:54
Compare
Choose a tag to compare
  1. 报告中现在将会显示connect_device接口连接的设备
  2. 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
  3. 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")
  1. 剪贴板的相关接口增加了安卓的支持,增加了粘贴接口(paste,效果等同于执行 text(get_clipboard())
text = "test_clipboard"
set_clipboard(text)

get_text = get_clipboard()
print(get_text)  # -> test_clipboard

paste()  # => text(get_clipboard())

bug修复:
修复了一些小问题
如果遇到了手机画面只有一半的情况,重新连接画面即可恢复。


  1. The report will now display the devices connected to the connect_device interface.
  2. 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
  3. 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 specifying adb_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")
  1. The relevant interfaces of the clipboard have been added with Android support and a paste interface (paste, the effect is equivalent to executing text(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

18 Jul 11:13
Compare
Choose a tag to compare

重要改动

从airtest v1.3.0起,放弃对python2的支持

新增

ios设备接口新增

iOS设备对象IOS,新增以下接口的支持:

  1. (仅支持本地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
  1. (仅支持本地USB设备)卸载 uninstall
uninstall("com.netease.cloudmusic")

dev = device()

dev.uninstall_app("com.netease.godlike")
  1. (仅支持本地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)
  1. 获取剪贴板内容, get_clipboard
text = get_clipboard()
print(text)

注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id才能使用:

text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
  1. 设置剪贴板内容,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/all
  • list_wda: 列出手机上安装的所有WDA的bundleID
  • device_info:获取手机信息
  • install_app:安装ipa包,支持本地路径或URL
  • uninstall_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.airbaz.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.")

其他改动

  1. 当airtest脚本引发了assert异常时,退出码为20,以便和其他报错区分
  2. 更新了Yosemite.apk,修复了一些稳定性问题
  3. 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:

  1. (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
  1. (Only local USB devices are supported) Uninstall uninstall
uninstall("com.netease.cloudmusic")

or

dev = device()

dev.uninstall_app("com.netease.godlike")
  1. (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)
  1. 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")
  1. 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 USB
  • list_app: Lists the list of apps installed on the phone, supports filtering by type, including user/system/all
  • list_wda: list the bundleIDs of all WDAs installed on the phone
  • device_info: get phone information
  • install_app: install ipa package, support local path or URL
  • uninstall_app: Uninstall the package body corresponding to bundle_id
  • start_app: start the package body corresponding to bundle_id
  • stop_app: Stop the package body corresponding to bundle_id
  • ps: get the current process list
  • ps_wda: Get a list of WDAs currently booting
  • xctest: 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...
Read more

v1.2.10.2

12 May 06:29
Compare
Choose a tag to compare

录屏相关

Android录屏目前提供两种模式,yosemiteffmpeg,区别如下:

  • 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
  • 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

Changes in 1.2.10.2:

  • The cv2 mode 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

1.2.10 Compatible with the latest version of iOS-tagent. 兼容最新版本的iOS-Tagent

29 Mar 07:56
Compare
Choose a tag to compare
  1. 兼容最新版本的ios-tagent master 的改动:
    • 新增了一个点击接口、一个滑动接口,速度比appium/wda的接口更快
    • 具体详细改动内容:iOS-Tagent接口改动说明
    • airtest将在检查到当前ios手机使用的是ios-tagent时,调用新增接口,否则调用wda原本的点击和滑动接口
  2. 更新了yosemite.apk,修复了一个小米6手机横屏画面获取错误的问题
  3. airtest的脚本内容支持 if __name__ == "__main__" 的写法了

  1. Compatible with the latest version of ios-tagent master changes:
    • Added a click interface and a sliding interface, which are faster than the appium/wda interface
    • Specific detailed changes: iOS-Tagent interface change description
    • airtest will call the new interface when it checks that the current ios phone is using ios-tagent, otherwise it will call the original click and slide interface of wda
  2. Updated yosemite.apk, and fixed a problem that the horizontal screen image of Mi 6 mobile phone was incorrectly obtained
  3. The script content of airtest supports the writing method of if __name__ == "__main__"

v1.2.9 新版本录屏方法和windows截图优化

15 Feb 04:57
Compare
Choose a tag to compare

功能新增

新增windows窗口录屏功能、iOS录屏功能,同时也迭代了安卓录屏

目前录屏功能不仅支持Android设备,还支持了windows、iOS设备!

函数 start_recording() 参数修改如下:

  • max_time: 录屏最长时间限制,默认为1800,单位是秒
  • output: 录像保存文件地址, 默认为None,将会自动保存在log目录下,自动以当前时间命名——原先output参数在stop_recording中,现在改为在start_recording里
  • fps=10 # 输出视频的帧率,目前暂时限定不超过10fps,默认为10(仅对ffmpeg和cv2生效)
  • mode="yosemite" # 保存视频的方法,仅支持安卓,可选 'ffmpeg' 'yosemite',区别如下:
    • ffmpeg:对机型兼容较好,但cpu占用较高,第一次运行将会预先下载ffmpeg,有一定的额外空间占用(几十M)
    • yosemite:Android旧版本的录屏方案,假如当前设备是Android,默认会使用这个模式录屏,必须要事先安装yosemite.apk,并支持旧的参数,帧率比ffmpeg高,但兼容性差,有一些手机不支持
  • snapshot_sleep=0.001 # 截图间隔
  • orientation=0 # 视频朝向模式 1 竖屏 2 横屏 0 方形填充,默认是0

其中大部分参数使用默认值即可,最重要的参数有两个:

  • 新增参数orientation:
    • 当跑测过程中大部分时间是竖屏时,可以考虑将orientation=1,或 orientation="portrait"
    • 当跑测过程中大部分是横屏,可以orientation=2,或orientation="lanscape",适合游戏等横屏应用
    • 横竖屏都有可能的话,可以不指定参数,默认值为0,会用一个正方形来容纳视频内容,方便横竖屏转换
  • output=xxx.mp4,默认将录屏文件存放在log目录下,如果有重命名需求的话可以传这个参数,否则直接所有参数用默认值即可

代码示例:

            Record 30 seconds of video and export to the current directory test.mp4::

            >>> from airtest.core.api import connect_device, sleep
            >>> dev = connect_device("Android:///")
            >>> save_path = dev.start_recording(output="test.mp4")
            >>> sleep(30)
            >>> dev.stop_recording()
            >>> print(save_path)

            >>> # the screen is portrait
            >>> portrait_mp4 = dev.start_recording(output="portrait.mp4", orientation=1)  # or orientation="portrait"
            >>> sleep(30)
            >>> dev.stop_recording()

            >>> # the screen is landscape
            >>> landscape_mp4 = dev.start_recording(output="landscape.mp4", orientation=2)  # or orientation="landscape"

IOS支持传入udid参数

iOS的初始化字符串中,支持传入名为 serialno/udid/uuid的字段,用于设置这台iOS的设备udid,示例:

>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100")  # iOS with mjpeg port
>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100&&udid=00008020-001270842E88002E")  # iOS with mjpeg port and udid
>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100&&uuid=00008020-001270842E88002E")  # udid/uuid/serialno are all ok

该名称无论使用udid/uuid/serialno中任何一个名字传入都可以生效,可以在连接后,通过以下方式获取到这个值:

dev = connect_device("iOS:///http://localhost:8100/?uuid=00008020-001270842E88002E")
print(dev.uuid)

增加这个参数的主要原因是,在wda中获取不到ios手机的udid,但在某些情况下可能需要用到这个值,因此支持主动传入保存。

支持Android 13

目前支持了Android 13

问题修复

修复了部分windows下,游戏无法正确截屏的问题

迭代了windows的snapshot,修复了部分游戏截屏图像重复、黑屏等问题,同时修复了在双屏下的截图区域错误问题。

修改了报告中对于运行结果是否成功的判定

原先的逻辑是:只要整个运行过程中出现traceback,就认为此次任务运行失败
但通常会遇到一种情况是:在运行过程中会出现一些不太重要的脚本异常,我们希望脚本不卡在这里,而是catch住异常后继续往下跑,只要能跑到最后就算脚本成功。

因此将脚本的成功判断改为:当步骤列表的最后一个步骤有traceback,才认为本次脚本运行失败。

对报告中一些显示效果做了一点微调

  1. 做了一些样式调整,修复了一些显示问题

  2. 报告html支持上下左右按键切换预览图片。


New features

Added windows window screen recording function, iOS screen recording function, and iterative Android screen recording function

Currently, the screen recording function not only supports Android devices, but also supports Windows and iOS devices!

The parameters of the function start_recording() are modified as follows:

  • max_time: The maximum time limit for screen recording, the default is 1800, the unit is second
  • output: The address of the video save file, the default is None, it will be automatically saved in the log directory, automatically named after the current time - the original output parameter is in stop_recording, now it is changed to start_recording
  • fps=10 # The frame rate of the output video is currently limited to no more than 10fps, and the default is 10 (only valid for ffmpeg and cv2)
  • mode="ffmpeg" # (Android Only) The background to save the video, optional 'ffmpeg' 'yosemite', the differences between the three modes are as follows:
    • ffmpeg: Compatibility with models is better, but the cpu usage is high, the first run will pre-download ffmpeg, there is a certain amount of extra space occupied (tens of M)
    • cv2: (Android default) No need to occupy additional space, the generated video volume is larger than ffmpeg
    • yosemite: The screen recording solution of the old version of Android. If the current device is Android, this mode will be used to record the screen by default. You must install yosemite.apk in advance, and support the old parameters. The frame rate is higher than ffmpeg and cv2, but compatible Poor performance, some mobile phones do not support
  • snapshot_sleep=0.001 # screenshot interval
  • orientation=0 # Video orientation mode 1 portrait 2 landscape 0 square padding, the default is 0

Most of the parameters can use the default values, and there are two most important parameters:

  • New parameter orientation:
    • When most of the time during the running test is a vertical screen, you can consider setting orientation=1, or orientation="portrait"
    • When most of the running tests are horizontal screens, you can use orientation=2, or orientation="lanscape", which is suitable for horizontal screen applications such as games
    • If both horizontal and vertical screens are possible, no parameter can be specified, the default value is 0, and a square will be used to accommodate the video content, which is convenient for horizontal and vertical screen conversion
  • output=xxx.mp4, by default, the screen recording file will be stored in the log directory. If there is a need to rename it, you can pass this parameter, otherwise you can use the default value for all parameters

Code example:

            Record 30 seconds of video and export to the current directory test.mp4::

            >>> from airtest.core.api import connect_device, sleep
            >>> dev = connect_device("Android:///")
            >>> save_path = dev.start_recording(output="test.mp4")
            >>> sleep(30)
            >>> dev.stop_recording()
            >>> print(save_path)

            >>> # the screen is portrait
            >>> portrait_mp4 = dev.start_recording(output="portrait.mp4", orientation=1)  # or orientation="portrait"
            >>> sleep(30)
            >>> dev.stop_recording()

            >>> # the screen is landscape
            >>> landscape_mp4 = dev.start_recording(output="landscape.mp4", orientation=2)  # or orientation="landscape"

IOS supports passing in udid parameters

In the initialization string of iOS, it is supported to pass in a field named serialno/udid/uuid, which is used to set the udid of this iOS device, for example:

>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100") # iOS with mjpeg port
>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100&&udid=00008020-001270842E88002E") # iOS with mjpeg port and udid
>>> connect_device("iOS:///http://localhost:8100/?mjpeg_port=9100&&uuid=00008020-001270842E88002E") # udid/uuid/serialno are all ok

The name can take effect no matter which name is used in udid/uuid/serialno, and this value can be obtained in the following way after connection:

dev = connect_device("iOS:///http://localhost:8100/?uuid=00008020-001270842E88002E")
print(dev.uuid)

The main reason for adding this parameter is that the udid of the ios phone cannot be obtained in wda, but this value may be needed in some cases, so it is supported to actively pass in and save.

Support Android 13

Currently supports Android 13

bug fixes

Fixed the problem that the game could not take screenshots correctly under some windows

Iterated the snapshot of windows, fixed some game screenshot image duplication, black screen and other problems, and also fixed the wrong area of ​​the screenshot under dual screen.

Modified the judgment on whether the running result is successful or not in the report

The original logic is: as long as a traceback occurs during the entire running process, it is considered that the task failed.
But there is usually a situation where some unimportant script exceptions will appear during the running process. We hope that the script will not get stuck here, but continue to run after catching the exception. As long as it can run to the end, it will be considered as a script. success.

Therefore, the success judgment of the script is changed to: When the last step in the step list has a traceback, the script is considered to have failed.

Fine-tuned some display effects in the report

  1. Made some style adjustments and fixed some display issues

  2. The report html supports up, down, left, and right buttons to switch the preview image.

v1.2.7

29 Sep 08:18
Compare
Choose a tag to compare

1. 更新内容

1.2.7版本主要是新增了设备释放接口、大量断言的语句,新增了对Android 12L的支持,对安装接口的增强,和若干bug的修复。

2. Airtest版本提升至1.2.7

1)新增了device.disconnect()接口

原先的Airtest,在脚本长时间运行、或是使用了AirtestIDE反复连接多个不同手机时,可能会 建立大量adb连接未释放 ,一直占用资源。

这也会导致在部分手机上,反复切换横屏和竖屏应用时,会有概率出现 屏幕一半内容变成黑屏 的问题。

因此,1.2.7版本的Airtest新增了device.disconnect()接口,用于:

  • 在脚本中允许手动调用,让设备创建出的所有adb连接都强制释放掉,dev.disconnect(),如果还要继续使用这个设备对象,最好重新再创建一次 dev = connect_device("android:///")
  • 同时对连接的创建进行了更进一步的清理操作,避免黑屏问题的发生
2)新增了大量的断言语句

在脚本编写中,断言语句是非常重要的组成部分,但airtest旧版只支持 assert_existsassert_equal 两种类型的断言语句。

现在Airtest1.2.7版本,将所有断言语句单独放在 airtest/core/assertions.py 中,增加了更多类型,方便脚本编写工作。

目前Airtest1.2.7支持的断言列表: assertions

  • assert_exists
  • assert_not_exists
  • assert_equal
  • assert_not_equal
  • assert_true
  • assert_false
  • assert_is
  • assert_is_not
  • assert_is_none
  • assert_is_not_none
  • assert_in
  • assert_not_in
  • assert_is_instance
  • assert_not_is_instance
  • assert_greater
  • assert_greater_equal
  • assert_less
  • assert_less_equal
3)支持设置断言时附带当前截图

Airtest1.2.7除了让断言语句更加丰富以外,还支持设置断言时截取当前画面的图片,然后显示在Airtest报告中,这样报告的断言内容会更加清晰,也更具有airtest的截图特色:

# 默认情况下,断言截图会开启
assert_exists()

# 如不需要断言时截取当前画面,则可以设置关闭断言的截图
assert_exists(截图, snapshot=False)
4)新增对Android12L的支持

已增加 minicap 对android 12L的支持,Poco的支持可以等待poco后续的更新。

5)安装接口pm_install的增强

pm_install 接口进行了较大的增强:

  • 支持了安装参数的传入(与 adb.install 保持一致),
  • 支持了中文路径、一些包含特殊符号路径
  • 对路径的改动同时影响到了 adb.pull()adb.push() 接口,支持了中文路径、包含斜杠的路径(比如 \g 这样的字符也会有问题)、包含特殊符号(空格、括号等)的路径
  • pm_install 安装完毕后,会进行 adb shell rm apk 的操作,超时时间30秒
6)logwrap增加截图参数

如果希望把自定义的函数显示到airtest的报告中,可以使用@logwrap,例如:

@logwrap
def func1():
    pass

如果希望在报告显示func1内容的同时,还附带一张当前设备的截图的话,可以增加snapshot=True参数在func1()的定义中:

@logwrap
def func1(snapshot=True):
    pass
7)bug修复
  • 尝试修复偶现的一个报告读取不到图片导致生成报告失败的问题
  • 兼容了adb 获取屏幕信息超时的情况
  • 修复了一个 adb.text() 在输入字母+数字时可能会导致乱序的问题,同时支持空格
8)新增了3个PR的支持
  • 在Windows环境下,初始化 airtest.core.win.Windows 对象时,允许开发者选择性跳过 connect() 方法中的 set_foreground() 功能 #1068
  • Android.get_render_resolution 中增加应用包名参数,
    使得 get_render_resolution 能够获取到除top activity以外的应用的渲染区域 #1070
  • 修复win和linux的start_app缺少的传参 #1056

3. 如何更新

pip install -U airtest

1. Update content

Version 1.2.7 mainly added device release interface, a large number of assertion statements, added support for Android 12L, enhanced installation interface, and fixed several bugs.

2. Airtest version upgraded to 1.2.7

1) Added device.disconnect() interface

The original Airtest, when the script runs for a long time, or uses AirtestIDE to repeatedly connect to multiple different mobile phones, may establish a large number of adb connections but not release, which will always occupy resources.

This will also lead to the problem of half of the screen becoming a black screen when switching between landscape and portrait applications repeatedly on some mobile phones.

Therefore, version 1.2.7 of Airtest has added the device.disconnect() interface for:

  • Allow manual calls in the script, so that all adb connections created by the device are forcibly released, dev.disconnect(), if you want to continue to use this device object, it is best to recreate it again dev = connect_device(" android:///")
  • At the same time, the creation of the connection has been further cleaned up to avoid the black screen problem
2) Added a large number of assertion statements

In scripting, assertion statement is a very important part, but the old version of airtest only supports assert_exists and assert_equal two types of assertion statement.

Now Airtest 1.2.7 version, put all assertion statements in airtest/core/assertions.py separately, adding more types to facilitate scripting work.

List of assertions currently supported by Airtest1.2.7: assertions

  • assert_exists
  • assert_not_exists
  • assert_equal
  • assert_not_equal
  • assert_true
  • assert_false
  • assert_is
  • assert_is_not
  • assert_is_none
  • assert_is_not_none
  • assert_in
  • assert_not_in
  • assert_is_instance
  • assert_not_is_instance
  • assert_greater
  • assert_greater_equal
  • assert_less
  • assert_less_equal
3) Support setting assertion with current screenshot

In addition to enriching the assertion statement, Airtest 1.2.7 also supports capturing a picture of the current screen when setting an assertion, and then displaying it in the Airtest report, so that the assertion content of the report will be clearer and more characteristic of airtest screenshots:

# By default, assertion screenshots are enabled
assert_exists()

# If you do not need to take a screenshot of the current screen when asserting, you can set a screenshot of closing the assertion
assert_exists(screenshot, snapshot=False)
4) Added support for Android12L

Added minicap support for android 12L, Poco support can wait for poco's subsequent updates.

5) Enhancement of installation interface pm_install

Major enhancements to the pm_install interface:

  • Supports the passing of installation parameters (consistent with adb.install),
  • Support Chinese paths, some paths containing special symbols
  • Changes to paths affect both adb.pull() and adb.push() interfaces, supports Chinese paths, paths containing slashes (such as \g and other characters will also problem), paths that contain special symbols (spaces, brackets, etc.)
  • After pm_install is installed, the adb shell rm apk operation will be performed with a timeout of 30 seconds
6) Logwrap adds screenshot parameters

If you want to display a custom function in the airtest report, you can use @logwrap, for example:

@logwrap
def func1():
    pass

If you want the report to display the contents of func1 and also attach a screenshot of the current device, you can add the snapshot=True parameter to the definition of func1():

@logwrap
def func1(snapshot=True):
    pass
7) Bug fix
  • Attempt to fix an occasional issue where the report could not be read, causing the report to fail to be generated
  • Compatible with the timeout of adb getting screen information
  • Fixed an issue where adb.text() could cause out-of-order when entering letters + numbers, while supporting spaces
8) Added support for 3 PRs
  • In Windows environment, when initializing airtest.core.win.Windows object, allow developers to selectively skip set_foreground() function in connect() method #1068
  • Add the application package name parameter in Android.get_render_resolution,
    Enable get_render_resolution to get the rendering area of ​​applications other than top activity #1070
  • Fix the missing parameter of start_app of win and linux #1056

3. How to update

pip install -U airtest