Skip to content

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

Compare
Choose a tag to compare
@yimelia yimelia released this 15 Feb 04:57
· 136 commits to master since this release

功能新增

新增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.