Airtest

Latest version: v1.3.4

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

Scan your dependencies

Page 4 of 5

1.1.8

iOS模块全面迭代

重做了airtest/core/ios模块,主要改动如下:

- 支持Appium的[WebDriverAgent](https://github.com/appium/WebDriverAgent)工具,因此能够支持更新版本的iOS(>=14)以及新版本的xcode

- Appium的[WebDriverAgent](https://github.com/appium/WebDriverAgent)与我们的[iOS-Tagent](https://github.com/AirtestProject/iOS-Tagent),只需要选择其中一个部署即可,若原先已经部署了iOS-Tagent,请更新至最新版本

- **重要:** 由于`facebook-wda`只支持python3,因此假如想升级到这个版本,更好地使用ios模块以及下方提及的接口的话,必须使用python3

- 新增了弹窗相关接口:

- `alert_accept` :适用于拥有2个按钮的iOS弹窗,会点击弹窗右边的按钮,通常是“同意”或者“好”

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

点击弹窗右边的按钮
ios.alert_accept()


- `alert_dismiss`:适用于拥有2个按钮的iOS弹窗,会点击弹窗左边的按钮,例如“不同意”

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

点击弹窗左边的按钮
ios.alert_dismiss()


- `alert_buttons`:以列表形式返回弹窗的按钮文字

-
返回设备弹窗的按钮的文字
ios.alert_buttons()


- `alert_click`:点击弹窗上的指定按钮

-
点击弹窗上面的指定按钮,可传入列表按顺序查找
ios.alert_click(['设置', '允许', '好'])


- `alert_exists`:判断弹窗是否存在

-
ios.alert_exists()


- `alert_watch_and_click`:监控弹窗出现并点击指定按钮

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

默认情况下监控此类弹窗:["使用App时允许", "好", "稍后", "稍后提醒", "确定", "允许", "以后"]
with ios.alert_watch_and_click():
sleep(5)

监控指定弹窗出现并点击
with ios.alert_watch_and_click(["Cancel"]):
sleep(5)

设置监控的时间间隔为2.0s
with ios.alert_watch_and_click(interval=2.0):
sleep(5)


- `alert.text`: 返回弹窗上面的描述文字

-
返回弹窗上面的描述文字
print(ios.driver.alert.text)


- `keyevent`接口增加音量控制事件

- 支持使用 `keyevent` 接口对iOS设备的音量进行加减控制:

-
音量增加
keyevent("volumeUp")

音量减少
keyevent("volumeDown")


- `app_state`接口返回包体状态

-
dev = device()
start_app('com.apple.mobilesafari')
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 4
home()
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 3
stop_app('com.apple.mobilesafari')
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 1


- `app_current`返回当前运行应用

-
print(ios.app_current())
output is {"pid": 1281,
"name": "",
"bundleId": "com.netease.cloudmusic"}


- 加锁相关接口

- `is_locked` 当前是否锁屏

- `unlock` 解锁设备

- `lock` 为设备锁屏

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

判断当前iOS设备是否上锁
print(ios.is_locked())
ios.unlock()
ios.lock()


- `device_info` 返回设备信息

-
print(ios.device_info())
>>> AttrDict({
'timeZone': 'GMT+0800',
'currentLocale': 'zh_CN',
'model': 'iPhone',
'uuid': '90CD6AB7-11C7-4E52-B2D3-61FA31D791EC',
'userInterfaceIdiom': 0,
'userInterfaceStyle': 'light',
'name': 'iPhone',
'isSimulator': False})


- `home_interface` 判断是否在home桌面

-
print(ios.home_interface())


- 其他ios相关的bug修复和优化:

- 修复了部分设备在屏幕旋转时,屏幕画面显示异常、点击位置错误的问题,以及在poco框选节点时,框选位置错误的问题
- 优化了同时有多个进程连接单个ios时的表现和连接稳定性,略微加快了点击和滑动操作的速度。另外部分设备(例如ipad, 6P/7P/8P)的操作速度会比别的型号手机更慢,这些型号的设备在竖屏情况下使用体验会更好

BUG FIX

1. 如果minicap没有成功启动、或是RotationWatcher.apk没安装成功,就换用adb获取ori信息,新增了使用ADB线程不断获取ori信息的逻辑 [`1b85fc7`](https://github.com/AirtestProject/Airtest/commit/1b85fc7c26813e0b6c429cadb48adef5362943ed)
2. 如果ori_method运行失败、Yosemite.apk安装失败(如果已经安装过旧版,允许跳过安装),也能保证基础功能的运行 [`b1c8568`](https://github.com/AirtestProject/Airtest/commit/b1c8568792bd710674a64c6a45b0566dafde1a60) [`f1f095c`](https://github.com/AirtestProject/Airtest/commit/f1f095c10fbe2c2f03872a730cbae36c5b8dc986)
3. 修复上个版本引入的问题,py2下不能正常截图 [`a6e8f68`](https://github.com/AirtestProject/Airtest/commit/a6e8f68fdd14e318f0908c3c995b5d3c384167ac)



--------------------------



iOS module full iteration

Reworked the airtest/core/ios module, the main changes are as follows:

- Support Appium's [WebDriverAgent](https://github.com/appium/WebDriverAgent) tool, so it can support updated versions of iOS (>=14) and new versions of xcode

- Appium’s [WebDriverAgent](https://github.com/appium/WebDriverAgent) and our [iOS-Tagent](https://github.com/AirtestProject/iOS-Tagent), you only need to choose one of them to deploy. Yes, if iOS-Tagent is already deployed, please update to the latest version

- **Important:** Since `facebook-wda` only supports python3, if you want to upgrade to this version and better use the ios module and the interfaces mentioned below, you must use python3

- Added pop-up related interfaces:

- `alert_accept`: Applicable to iOS pop-up windows with 2 buttons, you will click the button on the right side of the pop-up window, usually "Agree" or "OK"

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

ios.alert_accept()


- `alert_dismiss`: Applicable to iOS pop-up windows with 2 buttons, you will click the button on the left side of the pop-up window, such as "disagree"

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

ios.alert_dismiss()


- `alert_buttons`: return the button text of the pop-up window as a list

-
ios.alert_buttons()


- `alert_click`: Click the specified button on the pop-up window

-
Click the specified button on the pop-up window, you can enter the list and search in order
ios.alert_click(['Settings','Allow','OK'])


- `alert_exists`: Determine whether the pop-up window exists

- `alert_watch_and_click`: The monitoring pop-up window appears and click the specified button

-
from airtest.core.ios.ios import IOS, wda
ios = IOS("http://localhost:8100/")

This type of pop-up window is monitored by default: ["Allow when using App", "OK", "Later", "Remind later", "OK", "Allow", "Later"]
with ios.alert_watch_and_click():
sleep(5)

Monitor the specified pop-up window appears and click
with ios.alert_watch_and_click(["Cancel"]):
sleep(5)

Set the monitoring interval to 2.0s
with ios.alert_watch_and_click(interval=2.0):
sleep(5)


- `alert.text`: Return the description text on the pop-up window

-
print(ios.driver.alert.text)


- `keyevent` interface adds volume control events

- Support using the `keyevent` interface to control the volume of iOS devices:

-
音量增加
keyevent("volumeUp")

音量减少
keyevent("volumeDown")


- The `app_state` interface returns the package state

-
dev = device()
start_app('com.apple.mobilesafari')
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 4
home()
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 3
stop_app('com.apple.mobilesafari')
print(dev.app_state('com.apple.mobilesafari')["value"]) --> output is 1


- Lock related interface

- `is_locked` whether the screen is currently locked

- `unlock` to unlock the device

- `lock` to lock the device screen

-
from airtest.core.ios.ios import IOS
ios = IOS("http://localhost:8100/")

Determine whether the current iOS device is locked
print(ios.is_locked())
ios.unlock()
ios.lock()


- `device_info` returns device information

-
print(ios.device_info())
>>> AttrDict({
'timeZone': 'GMT+0800',
'currentLocale': 'zh_CN',
'model': 'iPhone',
'uuid': '90CD6AB7-11C7-4E52-B2D3-61FA31D791EC',
'userInterfaceIdiom': 0,
'userInterfaceStyle': 'light',
'name': 'iPhone',
'isSimulator': False})


- `home_interface` determines whether it is on the home desktop

-
print(ios.home_interface())


- Other iOS related bug fixes and optimizations:

- Fixed the problem of abnormal screen display and wrong click position when the screen is rotated on some devices, and the wrong position of the box selection when selecting nodes in poco
- Optimized the performance and connection stability when there are multiple processes connected to a single ios at the same time, and slightly accelerated the speed of clicking and sliding operations. In addition, the operating speed of some devices (such as ipad, 6P/7P/8P) will be slower than other models of mobile phones, and these models will have a better experience in portrait mode.

BUG FIX

1. If minicap is not successfully started or `RotationWatcher.apk` is not installed successfully, use adb to obtain ori information, and add the logic of using ADB thread to continuously obtain ori information [`1b85fc7`](https://github.com /AirtestProject/Airtest/commit/1b85fc7c26813e0b6c429cadb48adef5362943ed)
2. If ori_method fails to run and `Yosemite.apk` fails to install (if you have already installed the old version, you can skip the installation), it can also ensure the operation of basic functions [`b1c8568`](https://github.com/AirtestProject/Airtest/ commit/b1c8568792bd710674a64c6a45b0566dafde1a60) [`f1f095c`](https://github.com/AirtestProject/Airtest/commit/f1f095c10fbe2c2f03872a730cbae36c5b8dc986)
3. Fix the problem introduced in the previous version, the screenshot cannot be taken normally under py2 [`a6e8f68`](https://github.com/AirtestProject/Airtest/commit/a6e8f68fdd14e318f0908c3c995b5d3c384167ac)

1.1.7

新增功能与重要API调整:

1. 目前可以自由选择**是否保存脚本运行过程中的截图**了,方式如下:

- 在命令行`airtest run xx.air`的时候,新增一个参数 `--no-image` ,只要在运行时传入这个参数,就能够在任务运行过程中不再保存截图 https://github.com/AirtestProject/Airtest/commit/2ed128c201be94d1fda0f364641296bec7e68a52 , 示例:


airtest run test.air --device Android:/// --log logs/ --no-image


- 目前settings新增了一个配置`ST.SAVE_IMAGE` ,默认为`True`, 如果改为`False`,就不保存截图,直到这个值再次设为`True`,示例:


from airtest.core.api import *
暂时关闭截图
ST.SAVE_IMAGE = False
touch((100, 100)) 这条语句将不会保存当前画面图片

继续截图
ST.SAVE_IMAGE = True
touch((100, 100))


- 命令行传入`--no-image`参数时,实际上也是将`ST.SAVE_IMAGE`设为`False`,因此第二种方式会更加灵活,大家可以在脚本运行过程中自由决定当前是否要保存图片

2. 当调用`log()`接口来保存对应log到报告中时,也同时将它print到当前终端,方便查看。 https://github.com/AirtestProject/Airtest/commit/b7d98f640fb3ddad339efe2617270488e8ec83c6

3. 去掉了`requirements.txt`里`opencv-contrib-python`的版本依赖,**目前python3.8和python3.9都能安装了**。

**注意:python3.9如果安装完毕还不能使用airtest,报错`ImportError: numpy.core.multiarray failed to import`,可以手工将`numpy`版本号降级至`1.19.3`就能使用了。**

4. Android的**录屏接口**,`start_recording`修改了参数,增加了一个更简单的`bit_rate_level`,可以设置1-5的清晰度级别,默认为1,数字越大会越清晰 https://github.com/AirtestProject/Airtest/pull/834/commits/2220863d9f82e066c9543b3a1f34d7242fdd75c4 , 示例:

python
from airtest.core.api import connect_device, sleep
dev = connect_device("Android:///")
Record the screen with the lowest quality
dev.start_recording(bit_rate_level=1)
sleep(30)
dev.stop_recording(output="test.mp4")


更多示例,请参考[文档](https://airtest.readthedocs.io/zh_CN/latest/wiki/device/android_zh.html#id13)

5. 重新整理了`LogToHtml`里面路径相关的参数`logfile`和`logdir`,现在支持通过修改`ST.LOG_DIR`和`ST.LOG_FILE`,来自主设置log文件夹和log.txt的文件名。修改完毕后,还可以直接用`LogToHtml`生成报告,同时简化了参数的传递 https://github.com/AirtestProject/Airtest/pull/834/commits/a4b43cb824d9d99855d80a0055ba09694889744c , 示例:

python
from airtest.report.report import LogToHtml
假设脚本为当前目录下的run.air, log目录为当前目录下的./log
默认将认为log存放在ST.LOG_DIR中,如果ST.LOG_DIR为空,则尝试寻找当前目录下的log文件夹
rpt = LogToHtml("test.air")
rpt.report()


自定义`ST.LOG_DIR`和`ST.LOG_FILE`的示例:

python
from airtest.core.helper import set_logdir
new_logfile = "log123.txt"
new_logdir = "./logs_new"
set logfile = ./logs_new/log123.txt
ST.LOG_FILE = new_logfile
set_logdir(new_logdir)

...

rpt = LogToHtml("test.air")
LogToHtml将会默认选择ST.LOG_FILE作为logfile,ST.LOG_DIR作为log_root,生成对应的log.html内容
rpt.report()


修复以下bug:

1. 修复在log()接口中,如果desc包含关键词assert,可能会导致步骤被错误认定为assert步骤的问题 https://github.com/AirtestProject/Airtest/commit/bfa4617058afa97feeac44ac3ada5054fab295c0
2. 修复了一个报告中缩略图没有被正确缩小的BUG(之前报告缩略图一般都只有3-5K大小,上个版本有问题,缩略图还是正常图片的大小) https://github.com/AirtestProject/Airtest/commit/39dc8346baa262050f12ae5596be34112079f030
3. 修复了在高版本android手机中,`adb.start_app_timing`获取不到app启动时间的问题 https://github.com/AirtestProject/Airtest/commit/002a17077a846010eec69093bfe42abdb094035f
4. 修复了`get_top_activity`在获取含有`$`符号的包名时会报错的问题(java允许命名时出现$符号) https://github.com/AirtestProject/Airtest/commit/c9e00e878c7aef6f0cc4f5ff2faa9caf82ae5c4f
5. `adb.file_size`更换了获取文件大小的命令,兼容更低版本的android手机,顺便修改了minitouch和maxtouch的安装过程,更简洁一点 https://github.com/AirtestProject/Airtest/commit/75e4665d2dcfc14993a1a8935fba6112dfa2fbb6
6. 修复了多线程同时截图时的`generator already executing`报错 https://github.com/AirtestProject/Airtest/commit/3a69dc89ac6f4b797e5175a057121f05b94892f8
7. 在获取sdk版本时偶尔会失败,尝试增加重试次数,但是是否修复此问题还有待观察 https://github.com/AirtestProject/Airtest/commit/ac08555a75eccb392fc0a6e9bf2642717dc12124
8. 修复部分手机初始化minitouch失败的问题,因为会有额外的log,导致正则匹配失败 https://github.com/AirtestProject/Airtest/commit/ece127b09ca3ea5b55a7b4ee9bfd8d604b834b47
9. 初始化`RotationWatcher`的时机改为在`get_display_info`的时候,避免在特殊情况下,因为它没有及时初始化,导致横竖屏转换时不能正确获取屏幕信息的问题。(假设连手机时是竖屏,开始运行后切换成了横屏,接下来运行纯poco脚本的click语句,就会导致点击位置横竖屏错误。因为poco语句在点击时不涉及截图,导致没有走到`rotationwatcher`的初始化逻辑里。) https://github.com/AirtestProject/Airtest/pull/834/commits/1ec622364e3a1ac780629245d4a1b7c8c3314ee9
10. `Android.get_top_activity_name_and_pid`的功能与`get_top_activity`重复,因此删除一个。 https://github.com/AirtestProject/Airtest/pull/834/commits/1df9afc0bde7720d408435e99e90f5506aecd6a3

* * *

New features and important API adjustments:

1. At present, you can freely choose whether to save the screenshot during the script running process or not. The method is as follows:

- In the command line `airtest run xx.air`, a new parameter `--no-image` is added. As long as this parameter is passed in at runtime, the screenshot can no longer be saved during the task run https:// github.com/AirtestProject/Airtest/commit/2ed128c201be94d1fda0f364641296bec7e68a52, example:


airtest run test.air --device Android:/// --log logs/ --no-image


- Currently there is a new configuration `ST.SAVE_IMAGE` in settings, the default is `True`, if it is changed to `False`, the screenshot will not be saved until the value is set to `True` again, example:


from airtest.core.api import *
Temporarily close the screenshot
ST.SAVE_IMAGE = False
touch((100, 100)) This statement will not save the current screen picture

Continue to take screenshot
ST.SAVE_IMAGE = True
touch((100, 100))


- When passing the `--no-image` parameter from the command line, it actually sets `ST.SAVE_IMAGE` to `False`, so the second method will be more flexible. You can freely decide whether the current script is currently running or not. To save the picture

2. When calling the `log()` interface to save the corresponding log to the report, it will also be printed to the current terminal for easy viewing. https://github.com/AirtestProject/Airtest/commit/b7d98f640fb3ddad339efe2617270488e8ec83c6

3. Removed the version dependency of `opencv-contrib-python` in `requirements.txt`, **currently both python3.8 and python3.9 can be installed**.

**Note: If you cannot use airtest after installing python3.9, you will get an error of `ImportError: numpy.core.multiarray failed to import`, you can manually downgrade the `numpy` version number to `1.19.3` to use it.**

4. Android’s **Screen Recording Interface**, `start_recording` has modified the parameters and added a simpler `bit_rate_level`, which can set the clarity level from 1-5, the default is 1, the larger the number, the clearer it will be (https://github.com/AirtestProject/Airtest/pull/834/commits/2220863d9f82e066c9543b3a1f34d7242fdd75c4), example:

python
from airtest.core.api import connect_device, sleep
dev = connect_device("Android:///")
Record the screen with the lowest quality
dev.start_recording(bit_rate_level=1)
sleep(30)
dev.stop_recording(output="test.mp4")


For more examples, please refer to [document](https://airtest.readthedocs.io/zh_CN/latest/wiki/device/android.html#record-the-screen-while-running-the-script)

5. Reorganized the path-related parameters `logfile` and `logdir` in `LogToHtml`, and now supports modifying `ST.LOG_DIR` and `ST.LOG_FILE`, from the main settings log folder and the file name of log.txt. After modification, you can also directly use `LogToHtml` to generate a report, and at the same time simplify the transfer of parameters (https://github.com/AirtestProject/Airtest/pull/834/commits/a4b43cb824d9d99855d80a0055ba09694889744c), example:
python
from airtest.report.report import LogToHtml
Assuming that the script is run.air in the current directory, and the log directory is ./log in the current directory
By default, log will be considered to be stored in ST.LOG_DIR, if ST.LOG_DIR is empty, try to find the log folder in the current directory
rpt = LogToHtml("test.air")
rpt.report()


Examples of customizing `ST.LOG_DIR` and `ST.LOG_FILE`:

python
from airtest.core.helper import set_logdir
new_logfile = "log123.txt"
new_logdir = "./logs_new"
set logfile = ./logs_new/log123.txt
ST.LOG_FILE = new_logfile
set_logdir(new_logdir)

...

rpt = LogToHtml(OWL)
LogToHtml will select ST.LOG_FILE as logfile and ST.LOG_DIR as log_root by default, and generate the corresponding log.html content
rpt.report()


Fix the following bugs:

1. Fix the problem that if desc contains the keyword assert in the log() interface, the step may be incorrectly identified as an assert step https://github.com/AirtestProject/Airtest/commit/bfa4617058afa97feeac44ac3ada5054fab295c0
2. Fixed a bug where the thumbnails in a report were not correctly reduced (the thumbnails of the previous reports were generally only 3-5K in size, there was a problem with the previous version, the thumbnails were still the size of normal pictures) https://github.com/ AirtestProject/Airtest/commit/39dc8346baa262050f12ae5596be34112079f030
3. Fixed the issue that `adb.start_app_timing` could not get app start time in high version android phones https://github.com/AirtestProject/Airtest/commit/002a17077a846010eec69093bfe42abdb094035f
4. Fixed the problem that `get_top_activity` would report an error when obtaining the package name containing the `$` symbol (java allows the $ symbol to appear when naming it) https://github.com/AirtestProject/Airtest/commit/c9e00e878c7aef6f0cc4f5ff2faa9caf82ae5c4f
5. `adb.file_size` has replaced the command to obtain the file size, compatible with lower versions of android phones, and modified the installation process of minitouch and maxtouch by the way to be more concise https://github.com/AirtestProject/Airtest/commit/75e4665d2dcfc14993a1a8935fba6112dfa2fbb6
6. Fixed the error of `generator already executing` when taking screenshots from multiple threads at the same time https://github.com/AirtestProject/Airtest/commit/3a69dc89ac6f4b797e5175a057121f05b94892f8
7. It occasionally fails when getting the SDK version, try to increase the number of retries, but it remains to be seen whether this problem is fixed https://github.com/AirtestProject/Airtest/commit/ac08555a75eccb392fc0a6e9bf2642717dc12124
8. Fix the problem that some mobile phones failed to initialize minitouch, because there will be extra logs, causing regular matching to fail https://github.com/AirtestProject/Airtest/commit/ece127b09ca3ea5b55a7b4ee9bfd8d604b834b47
9. The timing of initializing `RotationWatcher` is changed to when `get_display_info`, to avoid the problem that the screen information cannot be correctly obtained during the horizontal and vertical screen conversion because it is not initialized in time under special circumstances. (Assuming that the phone is connected to the vertical screen and switched to the horizontal screen after starting to run, then running the click statement of the pure poco script will cause the click position to be wrong. Because the poco statement does not involve screenshots when clicking, it does not go Into the initialization logic of `rotationwatcher`.) https://github.com/AirtestProject/Airtest/pull/834/commits/1ec622364e3a1ac780629245d4a1b7c8c3314ee9
10. The function of `Android.get_top_activity_name_and_pid` is duplicated with `get_top_activity`, so delete one. https://github.com/AirtestProject/Airtest/pull/834/commits/1df9afc0bde7720d408435e99e90f5506aecd6a3

1.1.5

新功能与接口改动:

1. 增加了对`Android 11`的支持

2. **在脚本中用于记录log的`log()`接口进行了大幅度改动**,支持4个参数:`arg, timestamp=None, desc="", snapshot=False`,(https://github.com/AirtestProject/Airtest/commit/777b5ffe51cfc41c7c05b3bcf289edc38f861774 ,
https://github.com/AirtestProject/Airtest/commit/77a4893be37bb7a3094171af27993fb6b593a0c1 , https://github.com/AirtestProject/Airtest/pull/802/commits/ced1201bbf1a3c244e7a5f5131b684b19b37b18a ),删掉了原先的`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("中文")

* * *
3. 新增一个设置`ST.IMAGE_MAXSIZE`,用于**指定截图的最大尺寸**,假如设置为1200,则最后保存的截图长宽都都不会超过1200,有利于进一步缩小截图的图片尺寸。 https://github.com/AirtestProject/Airtest/pull/802/commits/ffe7ebc5ad92dcb7139d0f91437658c8518da886

同时,对于**单张截图精度和全局截图精度也支持自定义** https://github.com/AirtestProject/Airtest/commit/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中的全局变量的数值


* * *

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

* * *

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

BUG修复

1. iOS修复了上个版本`stopapp`失效的问题 https://github.com/AirtestProject/Airtest/commit/6bf146becc56b2737288941d0771b013d183bc96

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

1. 在一些无法使用minicap的手机上,虽然指定了Javacap模式也能截屏,但是在调用`get_display_info`的时候依然调用到`minicap.get_display_info`,如果没有指定`ori_method`为`adbori`,会导致脚本无法运行成功。 因此修改为假如获取屏幕信息失败,自动调整为使用`adbori`模式来获取当前屏幕信息。 https://github.com/AirtestProject/Airtest/commit/9312f0d52a6dbf28a9b84ed51e338686d68ed875
https://github.com/AirtestProject/Airtest/pull/802/commits/469fa829ca1c593b16e87ba60c8982c4c868cc14

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

1. 修复了在高版本Android手机上,`get_ip_address()`接口不能正确获取到手机IP的问题 https://github.com/AirtestProject/Airtest/pull/802/commits/e4d76254f17850b927288fe09a6d0356951a4f2a

1. (暂未完全修复,请等待下个版本更新)修复了查找图片时,指定**RGB属性没生效**的问题: https://github.com/AirtestProject/Airtest/pull/802/commits/f2e84a06e90d1e97fc15cec0f2507198c79faf25

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

* * *

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.
https://github.com/AirtestProject/Airtest/commit/777b5ffe51cfc41c7c05b3bcf289edc38f861774
https://github.com/AirtestProject/Airtest/commit/77a4893be37bb7a3094171af27993fb6b593a0c1
https://github.com/AirtestProject/Airtest/pull/802/commits/ced1201bbf1a3c244e7a5f5131b684b19b37b18a

- `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("中文")


* * *

3. 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. https://github.com/AirtestProject/Airtest/pull/802/commits/ffe7ebc5ad92dcb7139d0f91437658c8518da886

At the same time, it also supports customization for **single screenshot accuracy and global screenshot accuracy** https://github.com/AirtestProject/Airtest/commit/31e40122e723a36cc23e13716a48d336069a73ea:
- `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


* * *

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

* * *
5. (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` https://github.com/AirtestProject/Airtest/commit/6bf146becc56b2737288941d0771b013d183bc96

1. 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.

1. 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.
https://github.com/AirtestProject/Airtest/commit/9312f0d52a6dbf28a9b84ed51e338686d68ed875
https://github.com/AirtestProject/Airtest/pull/802/commits/469fa829ca1c593b16e87ba60c8982c4c868cc14

1. 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 https://github.com/AirtestProject/Airtest/commit/c163a4f46b95c9ad758fa666cf113696bbe7ce6d

1. Fixed the issue that the `get_ip_address()` interface could not obtain the phone IP correctly on high version Android phones https://github.com/AirtestProject/Airtest/pull/802/commits/e4d76254f17850b927288fe09a6d0356951a4f2a

1. Fixed the problem that the specified **RGB attribute did not take effect** when searching for pictures: https://github.com/AirtestProject/Airtest/pull/802/commits/f2e84a06e90d1e97fc15cec0f2507198c79faf25

1. **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. https://github.com/AirtestProject/Airtest/pull/802/commits/0045c9bcd074f19e2084f864428eb165d5e10c59

1.1.4

Android API修改:

- Android部分点击接口修改:
将Android的点击代码进行了一些维护,对于以前一部分需要调用到`Android.minitouch`才能运行的接口(主要是`pinch`, `swipe_along`, `two_finger_swipe`),现在统一直接在Android层面进行调用:

old:
dev = device()
dev.minitouch.pinch()
dev.minitouch.swipe_along([(100, 300), (300, 300), (100, 500), (300, 600)])
dev.minitouch.two_finger_swipe( (100, 100), (200, 200) )
->
new:
dev = device()
dev.pinch() 双指捏合或分开
dev.swipe_along([(100, 300), (300, 300), (100, 500), (300, 600)]) 连续滑过一系列坐标
dev.two_finger_swipe( (100, 100), (200, 200) ) 两个手指一起滑动

更多调用代码示例与参数示例,可以参考:[tests/test_android.py](https://github.com/AirtestProject/Airtest/blob/master/tests/test_android.py#L168-L196)

- 如果使用了自定义点击`DownEvent/UpEvent/SleepEvent`,请将import语句修改成如下内容:

old:
from airtest.core.android.minitouch import *
->
new:
from airtest.core.android.touch_methods.base_touch import *


- 修复了部分型号的小米手机(主要是MIUI11版本)在横屏时使用javacap截图,会导致图像被不正确压缩的情况。
- 请卸载手机上已有的`Yosemite.apk`,重新连接手机即可重装新版本的`Yosemite.apk`修复此问题。
**注: 若手机更新到MIUI12版本,无需使用javacap模式就能直接获取到手机屏幕了,建议大家直接更新系统**

- 修复了MIUI11+android10下,`is_screenon`(手机是否亮屏)和`is_locked`(手机是否锁屏)接口无法使用的bug

iOS部分修改:

- 修复iOS部分机型横屏异常及提高启动应用的速度
- `iOS-Tagent`对xcode的支持更新到11.5版本,iOS版本支持到13.5(最新版本的xcode目前暂时还有一些问题需要兼容)

---------------

Android API modification:

- Modification of some click interfaces of Android:
Performed some maintenance on the Android click code. For the previous part of the interface that needs to be called to `Android.minitouch` to run (mainly `pinch`, `swipe_along`, `two_finger_swipe`), it is now called directly at the Android level. like this:

old:
dev.minitouch.pinch()
dev.minitouch.swipe_along([(100, 300), (300, 300), (100, 500), (300, 600)])
dev.minitouch.two_finger_swipe( (100, 100), (200, 200) )
->
new:
dev.pinch() pinch or separate with two fingers
dev.swipe_along([(100, 300), (300, 300), (100, 500), (300, 600)]) continuously slide through a series of coordinates
dev.two_finger_swipe( (100, 100), (200, 200) ) Two fingers slide together

For more call code examples, you can refer to [tests/test_android.py](https://github.com/AirtestProject/Airtest/blob/master/tests/test_android.py#L168-L196)

- If you used `DownEvent/UpEvent/SleepEvent`, please modify the import statement to the following:

old:
from airtest.core.android.minitouch import *
->
new:
from airtest.core.android.touch_methods.base_touch import *

- Fixed an issue where some models of Xiaomi phones (mainly the MIUI11 version) used javacap to take incorrect screenshots in landscape mode.
- Please uninstall the existing `Yosemite.apk` on your phone and reconnect the phone to reinstall the new version of `Yosemite.apk` to fix this problem.
**Note: If the mobile phone is updated to the MIUI12 version, you can directly get the mobile phone screen without using javacap mode. It is recommended that you update the system directly**
- Fixed the bug that the interfaces of `is_screenon` (whether the phone is bright) and `is_locked` (whether the phone is locked) under MIUI11+android10 cannot be used


iOS modification:

- Fixed the horizontal screen abnormality of some iOS models and increase the speed of starting the application
- `iOS-Tagent` support for xcode is updated to version 11.5, iOS version is supported to 13.5 (the latest version of xcode currently has some problems that need to be compatible)

1.1.3

1. 增强了对Android10的支持
2. 更新了yosemite.apk
3. 重构了底层的touch操作,更合理一些

1.1.2

接口:

- 新增了接口`airtest.__version__`用来查看airtest当前版本号,也可以运行命令行`airtest version`查看
- log()接口目前可以更好地将报错或信息显示到报告中了
- 在报告中显示信息,`log(string_msg)`
- 在报告中显示报错,`log(Exception)`, `log(title, string_error)`

报告:

- 修复了一些新版本报告的BUG
- 显示log.txt、步骤绝对时间,截图点击后可放大显示
- 可自定义截图压缩精度,有以下使用方式:
- 使用命令行启动,`airtest run ... --compress quality`
- 在脚本中自定义,优先级高于命令行,取值范围是1-99的正整数,airtest默认取10,如果希望获得更高精度的图片可以改为75

import airtest.core.api import *
ST.SNAPSHOT_QUALITY = xxx [1, 99]

- 设置某张图片的压缩精度,`snapshot(quality=my_quality)`
- 简化了生成报告的代码,去掉了一些无需额外传入的参数,现在只需要这样写就可以了:

rpt = LogToHtml("test_bj.air", "log", export_dir="export", plugins=["poco.utils.airtest.report"])
rpt.report()


windows:

- 修正了touch直接设置光标位置导致的部分ui未识别到光标位移的问题
- 修正了swipe在双屏模式下会多位移一倍距离的问题
- 修正了在某些版本的Python和pywin32下会报dll缺失的问题


Android:

- 更新了minicap.so,对部分Android10手机进行了兼容,但是并不完全,Android10的更好兼容请参考下一个版本1.1.3
- 更新了Yosemite.apk,修复了横屏截屏的bug,更新了录屏接口和录屏的方式,对部分手机有更好的兼容
- 修复了部分模拟器初始化时的失败问题,现在无需勾选`use ADB orientation`也能连接模拟器了
- adb的cmd操作增加了timeout参数,可以指定指令运行的超时时间了
- 去掉了在windows下运行cmd时如果出现异常,将导致弹出"adb.exe停止响应"的弹窗,避免脚本被卡住

-----------

Interface:

- Added interface `airtest .__ version__` to view the current version of airtest. You can also run the command line` airtest version` to view it.
- The `log()` interface can now better display errors or information in reports
- Display information in the report, `log (string_msg)`
- Show errors in the report, `log (Exception)`, `log (title, string_error)`

Report:

- Fixed some bugs reported by the new version
- Display log.txt, step absolute time, click the screenshot to zoom in
- You can customize the compression precision of screenshots, which can be used in the following ways:
- Start from the command line, `airtest run ... --compress quality`
- Customize in the script, the priority is higher than the command line, the value range is a positive integer from 1 to 99, the default value of airtest is 10, if you want to obtain a more accurate picture, you can change it to 75

import airtest.core.api import *
ST.SNAPSHOT_QUALITY = xxx [1, 99]

- Set the compression precision of a picture, `snapshot (quality = my_quality)`
- Simplified the code for generating reports, removing some parameters that do not need to be passed in, now it is only necessary to write like this:

rpt = LogToHtml("test_bj.air", "log", export_dir="export", plugins=["poco.utils.airtest.report"])
rpt.report()


Windows:

- Fixed the problem that some UIs did not recognize the cursor displacement caused by touch directly setting the cursor position
- Fixed an issue where swipe would double the distance in dual screen mode
- Fixed the problem of missing dlls under certain versions of Python and pywin32


Android:

- Updated minicap.so, compatible with some Android10 phones, but not completely. For better compatibility of Android10, please refer to the next version 1.1.3
- Updated Yosemite.apk, fixed the bug of horizontal screen capture, updated the screen recording interface and the screen recording method, better compatibility with some mobile phones
- Fixed the failure of some simulators during initialization, now you can connect to the simulator without checking the `use ADB orientation`
- Added a timeout parameter to the cmd operation of adb, which can specify the timeout period for the instruction to run
- Removed the "adb.exe stopped responding" pop-up window if an exception occurs when running cmd under windows, avoiding the script being stuck

Page 4 of 5

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.