新功能与接口改动:
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