Skip to content

v1.2.7

Compare
Choose a tag to compare
@yimelia yimelia released this 29 Sep 08:18
· 210 commits to master since this release

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