Airtest

Latest version: v1.3.4

Safety actively analyzes 629959 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 5

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

1. 兼容最新版本的[ios-tagent](https://github.com/AirtestProject/iOS-Tagent) master 的改动:
- 新增了一个点击接口、一个滑动接口,速度比appium/wda的接口更快
- 具体详细改动内容:[iOS-Tagent接口改动说明](https://github.com/AirtestProject/iOS-Tagent/wiki/iOS-Tagent%E6%8E%A5%E5%8F%A3%E6%94%B9%E5%8A%A8%E8%AF%B4%E6%98%8E)
- airtest将在检查到当前ios手机使用的是ios-tagent时,调用新增接口,否则调用wda原本的点击和滑动接口
2. 更新了yosemite.apk,修复了一个小米6手机横屏画面获取错误的问题
3. airtest的脚本内容支持 `if __name__ == "__main__"` 的写法了

* * *

1. Compatible with the latest version of [ios-tagent](https://github.com/AirtestProject/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](https://github.com/AirtestProject/iOS-Tagent/wiki/iOS-Tagent%E6%8E%A5%E5%8F%A3%E6%94%B9%E5%8A%A8%E8%AF%B4%E6%98%8E)
- 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__"`

1.2.9

功能新增

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

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](https://airtest.readthedocs.io/en/latest/all_module/airtest.core.assertions.html)

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

1.2.6

1.2.5

Add new

- iOS screen projection speed optimization, new MJPEG mode, viewing iOS screen images at a higher speed
- iOS click speed optimization, please update [iOS-Tagent](https://github.com/AirtestProject/iOS-Tagent) to the latest version (if you originally used the Appium/WebDriverAgent project, you can replace it with our version) , after the update can greatly reduce the click delay
- **Please use the latest version of AirtestIDE 1.2.14**, you can experience the best effect, otherwise it may cause the problem of wrong click position
- **If you use Poco, please update to version 1.0.87**, otherwise it may cause the problem of wrong click position

Related Notes:

1. On a very small number of devices, the click position may be offset. At present, the offset of the mouse click cannot be corrected on AirtestIDE, but it can be fixed in the code, for example:

We tested an iPhone 7Plus mobile phone, and there is a coordinate offset phenomenon when clicking, so it can be corrected when running the code in the following way:



>>> device = connect_device("iOS:///")
>>> device.touch((100, 100)) wrong position
>>> print(device.touch_factor)
0.333333
>>> device.touch_factor = 1 / 3.3 default is 1/3
>>> device.touch((100, 100))


Explanation about `touch_factor`:

> `touch_factor` This value is used to convert the touch coordinates of iOS devices:
>
> Phone real coordinates = touch_factor * screen coordinates
> The default calculation is: `self.display_info['window_height'] / self.display_info['height']`
> But it may be inaccurate on some special models of mobile phones, such as 7P of iOS14.4, the default value is 1/3, but the click position of some 7P is inaccurate, you can set it yourself: self.touch_factor = 1 / 3.3

Poco related notes:

1. Due to the high latency of Poco on iOS, it may also cause lag when it is turned on.
2. Some ipads may be in landscape + desktop, and the Poco obtained is in the wrong position. It is not recommended to click an icon on the desktop to open the app, try to use `start_app` to open it, but this interface must be transferred to the mobile phone. For some app package names, if the incoming package name does not exist, an error may be reported

BUG fixes

1. Fixed a bug that system resources were not completely released when Android screen recording, which may lead to memory overflow
2. Slightly optimized the recognition effect of `mstpl`
3. Fixed the possible click failure problem on mobile phones with Android 10 and above
4. Removed the restriction on numpy version number during installation
5. Compatible with jinja2>3.1 version
6. Fix the problem that the `adb.file_size` interface fails to obtain the file size under the Android 6.0.1 system

Page 2 of 5

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.