Skip to content

v1.1.5-1.1.6 update

Compare
Choose a tag to compare
@yimelia yimelia released this 10 Oct 08:04
· 194 commits to master since this release

新功能与接口改动:

  1. 增加了对Android 11的支持

  2. 在脚本中用于记录log的log()接口进行了大幅度改动,支持4个参数:arg, timestamp=None, desc="", snapshot=False,(777b5ff
    77a4893ced1201 ),删掉了原先的trace参数

  • args 可以是字符串或是traceback对象,现在还支持传入非字符串,并且对py2做了一下兼容。假如传入的是traceback对象,将会自动在报告中标记为报错步骤,否则就是显示正常的log内容
  • timestamp参数可以自定义当前这条log的时间戳,默认为当前时间(在记录一些长时间的回调中获取到的log时,原本默认使用写入本条log的时间,但是可能需要修改为log产生的时间,比如几分钟前)
  • desc 自定义一个log标题,在报告中有更好的展示效果
  • snapshot 是否需要截取一张当前的屏幕图像并显示到报告中,方便查看。(同时,因为这个参数的加入,现在airtest脚本如果因为执行Poco语句失败报错而终止时,能够额外截取一张当前画面,方便大家排查问题。)
  • 调用示例:
data = {"test": 123, "time": 123456}
log(data, timestamp=time.time(), desc="title", snapshot=True)
try:
    1/0
except Exception as e:
    log(e, snapshot=True)
log("中文")

  1. 新增一个设置ST.IMAGE_MAXSIZE,用于指定截图的最大尺寸,假如设置为1200,则最后保存的截图长宽都都不会超过1200,有利于进一步缩小截图的图片尺寸。 ffe7ebc

同时,对于单张截图精度和全局截图精度也支持自定义 31e40122e723a36cc23e13716a48d336069a73ea:

  • snapshot接口支持传入quality参数,单独指定本次截图的图像精度
  • 目前可以使用ST.SNAPSHOT_QUALITY = xx 设置全局截图精度,在运行脚本时,报告的步骤截图也会采用这个数值进行压缩,默认为10

调用示例:

# 默认截图质量为10,这里设置截图质量为30
ST.SNAPSHOT_QUALITY = 30
# 设置截图尺寸不超过600*600,如果不设置,默认为原图尺寸
ST.IMAGE_MAXSIZE = 600

touch(xx)  # touch语句保存的截图质量为30, 尺寸不超过600*600
snapshot(filename="test.png", msg="test", quality=90)  # 本条语句截图质量为90
snapshot(filename="test2.png", msg="test", quality=90, max_size=1200)  # 截图质量为90,尺寸不超过1200*1200
snapshot(msg="test12")  # 不设置的情况下,默认采用ST中的全局变量的数值

  1. playground/android_motionevents.py里面提供了一些Android自定义手势的示例代码,现在直接调用dev.touch_proxy.perform接口就可以传入写好的MoveEvent列表来进行自定义的滑动了(以前是调用dev.minitouch.perform,如果是安卓10就会不兼容)。

调用示例:

from airtest.core.android.touch_methods.base_touch import *
# tap with two fingers
multitouch_event = [
    DownEvent((100, 100), 0),
    DownEvent((200, 200), 1),  # second finger
    SleepEvent(1),
    UpEvent(0), UpEvent(1)]

device().touch_proxy.perform(multitouch_event)

更多示例请参见:https://github.com/AirtestProject/Airtest/blob/master/playground/android_motionevents.py


  1. (仅限安卓手机)在运行脚本时如果需要录制屏幕,可以传入--recording 录屏文件名.mp4来指定录屏文件
  • 如果只传了--recording,默认将会使用recording_手机序列号.mp4来命名录屏文件
  • 如果指定了文件名--recording test.mp4,且超过一台手机,就命名为 手机序列号_test.mp4
  • 如果指定了文件名--recording test.mp4,且只有一台手机,就命名为 test.mp4
  • 注意传入的文件名必须以mp4作为结尾

BUG修复

  1. iOS修复了上个版本stopapp失效的问题 6bf146b

  2. 回退了屏幕录制代码到1.0.27之前的版本,取消使用yosemite.apk来录屏,避免每次重装过yosemite.apk后必须要手工赋予录屏权限才能录屏的问题

  3. 在一些无法使用minicap的手机上,虽然指定了Javacap模式也能截屏,但是在调用get_display_info的时候依然调用到minicap.get_display_info,如果没有指定ori_methodadbori,会导致脚本无法运行成功。 因此修改为假如获取屏幕信息失败,自动调整为使用adbori模式来获取当前屏幕信息。 9312f0d
    469fa82

  4. 在脚本中一旦对同一台手机运行了不止一次connect_device接口,并指定了不同的设备连接参数时,G.DEVICE不会更新到最新参数创建出来的设备对象,导致部分手机可能连接失败。现在改为每次更新设备对象时,也会自动更新一下G.DEVICE c163a4f

  5. 修复了在高版本Android手机上,get_ip_address()接口不能正确获取到手机IP的问题 e4d7625

  6. (暂未完全修复,请等待下个版本更新)修复了查找图片时,指定RGB属性没生效的问题: f2e84a0

  7. 去掉了assert_exists接口使用特殊的ST.THRESHOLD_STRICT值作为找图阈值的设定。假如之前设置了ST.THRESHOLD_STRICT将会继续沿用该数值,但是如果没有设置的话,默认与其他图片一样都使用指定的threshold参数,或是全局的ST.THRESHOLD,这样能够方便统一设置和管理,也不容易造成误解。0045c9b


New features and interface changes

  1. Added support for Android 11

  2. The log() interface used to log logs in the script has been greatly changed, supporting 4 parameters: arg, timestamp=None, desc="", snapshot=False, deleted the original parameters.
    777b5ff
    77a4893
    ced1201

  • Args can be a string or a traceback object, and now supports non-string input, and is compatible with py2. If the traceback object is passed in, it will be automatically marked as an error step in the report, otherwise the normal log content will be displayed
  • The timestamp parameter can customize the timestamp of the current log, and the default is the current time (when recording the log obtained in some long-term callbacks, the time written to this log was originally used by default, but it may need to be modified to The time when the log was generated, such as a few minutes ago)
  • desc customize a log title for better display in the report
  • snapshot Whether it is necessary to take a screenshot of the current screen image and display it in the report for easy viewing. (At the same time, because of the addition of this parameter, if the airtest script terminates due to a failure to execute the Poco statement and an error is reported, it can take an additional screenshot of the current screen to facilitate troubleshooting.)
  • Call example:
data = {"test": 123, "time": 123456}
log(data, timestamp=time.time(), desc="title", snapshot=True)
try:
    1/0
except Exception as e:
    log(e, snapshot=True)
log("中文")

  1. A new setting ST.IMAGE_MAXSIZE is added to specify the maximum size of the screenshot. If it is set to 1200, the height and width of the final saved screenshot will not exceed 1200, which is helpful to further reduce the screenshot image size. ffe7ebc

At the same time, it also supports customization for single screenshot accuracy and global screenshot accuracy 31e4012:

  • snapshot interface supports passing in quality parameter to individually specify the image accuracy of this screenshot
  • Currently you can use ST.SNAPSHOT_QUALITY = xx to set the global screenshot accuracy. When running the script, the step screenshots of the report will also be compressed using this value

Example:

# Set the screenshot quality to 30
ST.SNAPSHOT_QUALITY = 30
# Set the screenshot size not to exceed 600*600, if not set, the default size is the original image size
ST.IMAGE_MAXSIZE = 600

touch(xx) # The quality of the screenshot saved by the touch statement is 30, and the size does not exceed 600*600
snapshot(filename="test.png", msg="test", quality=90) # The quality of the screenshot of this sentence is 90
snapshot(filename="test2.png", msg="test", quality=90, max_size=1200) # The quality of the screenshot is 90, and the size does not exceed 1200*1200
snapshot(msg="test12") # If not set, the value of the global variable in ST is used by default

  1. playground/android_motionevents.py provides some sample codes for Android custom gestures, now you can directly call the dev.touch_proxy.perform interface to pass in the written MoveEvent list for customization Sliding (previously it was called dev.minitouch.perform, if it is Android 10, it will not be compatible).

Call example:

from airtest.core.android.touch_methods.base_touch import *
# tap with two fingers
multitouch_event = [
    DownEvent((100, 100), 0),
    DownEvent((200, 200), 1), # second finger
    SleepEvent(1),
    UpEvent(0), UpEvent(1)]

device().touch_proxy.perform(multitouch_event)

For more examples, please see: https://github.com/AirtestProject/Airtest/blob/master/playground/android_motionevents.py


  1. (Android phones only) If you need to record the screen when running the script, you can pass in --recording filename.mp4 to specify the screen file
  • If only --recording is passed, serial_number.mp4 will be used by default to name the screen recording file
  • If the file name --recording test.mp4 is specified, and there is more than one mobile phone, it will be named as the serialnumber_test.mp4
  • If the file name --recording test.mp4 is specified and there is only one mobile phone, it will be named test.mp4
  • Note that the incoming file name must end with mp4

BUG repair

  1. iOS fixes the issue of the failure of the previous version of stopapp 6bf146b

  2. The screen recording code was rolled back to the version before 1.0.27, and the use of yosemite.apk to record the screen was cancelled to avoid the problem that the screen recording permission must be manually granted every time yosemite.apk is reinstalled.

  3. On some mobile phones that cannot use minicap, although the Javacap mode can also be used to take screenshots, when calling get_display_info, minicap.get_display_info is still called. If ʻori_method is not specified as ʻadbori, it will cause The script could not run successfully. Therefore, it is modified to automatically adjust to use ʻadbori` mode to obtain current screen information if it fails to obtain screen information.
    9312f0d
    469fa82

  4. Once the connect_device interface is run on the same mobile phone more than once in the script, and different device connection parameters are specified, G.DEVICE will not be updated to the device object created with the latest parameters, which may cause some mobile phones Connection failed. Now it’s changed to automatically update G.DEVICE every time the device object is updated c163a4f

  5. Fixed the issue that the get_ip_address() interface could not obtain the phone IP correctly on high version Android phones e4d7625

  6. Fixed the problem that the specified RGB attribute did not take effect when searching for pictures: f2e84a0

  7. Removed the assert_exists interface and uses the special ST.THRESHOLD_STRICT value as the setting of the image finding threshold. If ST.THRESHOLD_STRICT is set before, this value will continue to be used, but if it is not set, the specified threshold parameter or the global ST.THRESHOLD will be used by default like other pictures, which is convenient for unification Setting and management are not easy to cause misunderstanding. 0045c9b