UI Automation Framework for Games and Apps
ADD:
minicap
对于Android 14
版本的支持ADD:
minicap
support for Android 14
version.ADD:
touch
, swipe
接口新增相对坐标的支持
get_clipboard
获取剪贴板内容,set_clipboard
设置剪贴板内容, paste
粘贴set_clipboard
设置到剪贴板之后,再使用paste
粘贴即可touch_method
,来强制指定ADBTOUCH
, 或 MINITOUCH
, MAXTOUCH
dev.touch_method = "ADBTOUCH"
FIX:
Invalid parameter not satisfying: allAttributesForKey != nil
)ADD:
touch
, swipe
interfaces add support for relative coordinates
get_clipboard
gets the clipboard content, set_clipboard
sets the clipboard content, paste
pastesset_clipboard
to set it to the clipboard, and then use paste
to paste it.touch_method
to force specifying ADBTOUCH
, or MINITOUCH
, MAXTOUCH
dev.touch_method = "ADBTOUCH"
FIX:
Invalid parameter not satisfying: allAttributesForKey != nil
)LocalDeviceError
,部分接口只有本地USB连接的iOS设备才可以用,远程设备将会抛出这个异常。因此若有需要,可以catch住这个异常,并对远程设备做一些额外的兼容和处理。LocalDeviceError
. Some interfaces can only be used by local USB-connected iOS devices, and the remote device will throw this exception. Therefore, if necessary, you can catch this exception and do some additional compatibility and processing for the remote device.ios:///http://10.240.145.171:20092?name=83282c400efc9122e3bcba60c803cf318a6b3822
安卓远程设备: android://127.0.0.1:5037/10.227.71.86:20029?name=serialno
adb_path
,例如:from airtest.core.android.android import Android, ADB
adb = ADB(adb_path=r"D:\adb\adb.exe")
# 或者可以初始化一个指定了adb_path的Android设备对象
dev = Android(serialno="5TSSMVBYUSEQNRY5", adb_path=r"D:\test\adb41\adb.exe")
paste
,效果等同于执行 text(get_clipboard())
)text = "test_clipboard"
set_clipboard(text)
get_text = get_clipboard()
print(get_text) # -> test_clipboard
paste() # => text(get_clipboard())
bug修复: 修复了一些小问题 如果遇到了手机画面只有一半的情况,重新连接画面即可恢复。
ios:///http://10.240.145.171:20092?name=83282c400efc9122e3bcba60c803cf318a6b3822
Android remote device: android://127.0.0.1:5037/10.227.71.86:20029?name=serialno
adb_path
, for example:from airtest.core.android.android import Android, ADB
adb = ADB(adb_path=r"D:\adb\adb.exe")
# Or specify adb_path when initializing the Android object
dev = Android(serialno="5TSSMVBYUSEQNRY5", adb_path=r"D:\test\adb41\adb.exe")
paste
, the effect is equivalent to executing text(get_clipboard())
)text = "test_clipboard"
set_clipboard(text)
get_text = get_clipboard()
print(get_text) # -> test_clipboard
paste() # => text(get_clipboard())
bug fixes: Fixed some minor issues If you encounter a situation where the screen on your phone is only half full, you can restore the screen by reconnecting.
从airtest v1.3.0起,放弃对python2的支持
iOS设备对象IOS
,新增以下接口的支持:
install
install(r"D:\demo\test.ipa") # install iOS ipa
install("http://www.example.com/test.ipa") # install iOS ipa from url
或
#获取当前设备
dev = device()
#通过本地.ipa文件安装APP
dev.install_app(r"D:\demo\test.ipa") # install iOS ipa
#通过下载链接安装APP
dev.install_app("http://www.example.com/test.ipa") # install iOS ipa from url
uninstall
uninstall("com.netease.cloudmusic")
或
dev = device()
dev.uninstall_app("com.netease.godlike")
list_app
list_app("user") 传入要列出的app类型,可以得到app列表
参数可选user/system/all
分别表示列出用户安装的app/系统app/全部app
返回值示例:[('com.apple.mobilesafari', 'Safari', '8.0'), ...]
dev = device()
#列出全部APP
all_app = dev.list_app("all")
print(all_app)
#打印系统APP
print(dev.list_app("system"))
#列出用户安装的APP
user_app = dev.list_app("user")
print(user_app)
get_clipboard
text = get_clipboard()
print(text)
注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id
才能使用:
text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
set_clipboard
注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id
才能使用
set_clipboard("content") # local iOS
# When the iOS device is a remote device, or more than one wda is installed on the device, you need to specify the wda_bundle_id
set_clipboard("content", wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
针对本地USB接入的设备,airtest结合tidevice
的能力,封装了一个TIDevice
对象,提供了几个常用接口如下:
devices
:列出USB连接的所有设备的 UDID 列表list_app
: 列出手机上安装的应用列表,支持对类型进行筛选,包括 user/system/alllist_wda
: 列出手机上安装的所有WDA的bundleIDdevice_info
:获取手机信息install_app
:安装ipa包,支持本地路径或URLuninstall_app
:卸载bundle_id对应的包体start_app
:启动 bundle_id 对应的包体stop_app
:停止 bundle_id 对应的包体ps
: 获取当前的进程列表ps_wda
: 获取当前启动中的WDA列表xctest
:启动wda可以参考:https://github.com/AirtestProject/Airtest/blob/master/tests/test_tidevice.py
代码执行效果示例:
>>> from airtest.core.ios.ios import TIDevice
>>> devices = TIDevice.devices()
>>> print(devices)
['10da21b9091f799891557004e4105ebab3416cb9']
>>> udid = devices[0]
>>> print(TIDevice.list_app(udid))
[ ('com.230316modified.WebDriverAgentRunner.xctrunner', 'wda-Runner', '1.0'),]
>>> print(TIDevice.list_app(udid, "system"))
[('com.apple.calculator', 'Calculator', '1.0.0'),]
>>> print(TIDevice.list_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
>>> print(TIDevice.device_info(udid))
{'productVersion': '12.4.8', 'productType': 'iPhone7,2', 'modelNumber': 'MG472', 'serialNumber': 'DNPNW6EJG5MN', 'timeZone': 'Asia/Shanghai', 'uniqueDeviceID': '10da21b9091f799891557004e4105ebab3416cb9', 'marketName': 'iPhone 6'}
>>>
>>> TIDevice.start_app(udid, "com.apple.mobilesafari")
>>> TIDevice.stop_app(udid, "com.apple.mobilesafari")
>>> print(TIDevice.ps(udid))
[ {'pid': 215, 'name': 'MobileMail', 'bundle_id': 'com.apple.mobilemail', 'display_name': 'MobileMail'}]
>>> print(TIDevice.ps_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
TIDevice.xctest
接口的执行示例如下:
import threading
wda_bundle_id = TIDevice.list_wda(udid)[0]
# 创建一个线程,执行xctest
t = threading.Thread(target=TIDevice.xctest, args=(udid, wda_bundle_id), daemon=True)
t.start()
time.sleep(5)
ps_wda = TIDevice.ps_wda(udid)
print(ps_wda)
time.sleep(5)
# 终止线程
t.join(timeout=3)
using
接口的作用是,支持在脚本中引用另外一个脚本,同时还能够让airtest正确地读取到其他脚本中的图片路径。
假设目录结构如下:
demo/
foo/
bar.air
baz.air
main.py
如果我们希望在main.py中引用 foo/bar.air
和baz.air
,可以将项目根路径设置到ST.PROJECT_ROOT
,或者确保项目根路径是当前工作目录:
# main.py
from airtest.core.api import *
ST.PROJECT_ROOT = r"D:\demo" # This line can be ignored if it is the current working directory
using("foo/bar.air")
using("baz.air")
如果我们希望在 foo/bar.air
中引用 baz.air
,可以这样写:
# foo/bar.air
from airtest.core.api import *
using("../baz.air")
如果当前未连接任何设备,但又调用了某些需要连接设备才可以调用的接口时,抛出异常:NoDeviceError("No devices added.")
set_focus
,与原先的set_foreground
功能相同From airtest v1.3.0, drop support for python2
iOS adds support for the following interfaces:
install
install(r"D:\demo\test.ipa") # install iOS ipa
install("http://www.example.com/test.ipa") # install iOS ipa from url
or
# Get the current device
dev = device()
#Install APP through local .ipa file
dev.install_app(r"D:\demo\test.ipa") # install iOS ipa
#Install the APP through the download link
dev.install_app("http://www.example.com/test.ipa") # install iOS ipa from url
uninstall
uninstall("com.netease.cloudmusic")
or
dev = device()
dev.uninstall_app("com.netease.godlike")
list_app
list_app("user") Pass in the app type to be listed, and you can get the app list
Optional parameter user/system/all
means to list the app installed by the user/system app/all apps respectively
Return value example: [('com.apple.mobilesafari', 'Safari', '8.0'), ...]
dev = device()
#List all APPs
all_app = dev. list_app("all")
print(all_app)
#Print System APP
print(dev. list_app("system"))
#List the apps installed by the user
user_app = dev. list_app("user")
print(user_app)
get_clipboard
text = get_clipboard()
print(text)
Note: When the iOS device is a remote device, or more than one wda is installed, you need to specify a specific wda_bundle_id
to use:
text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
set_clipboard
Note: When the iOS device is a remote device, or more than one wda is installed, you need to specify a specific wda_bundle_id
to use
set_clipboard("content") # local iOS
# When the iOS device is a remote device, or more than one wda is installed on the device, you need to specify the wda_bundle_id
set_clipboard("content", wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
For devices with local USB access, airtest combines the capabilities of tidevice
to encapsulate a TIDevice
object, providing several common interfaces as follows:
devices
: list the UDIDs of all devices connected by USBlist_app
: Lists the list of apps installed on the phone, supports filtering by type, including user/system/alllist_wda
: list the bundleIDs of all WDAs installed on the phonedevice_info
: get phone informationinstall_app
: install ipa package, support local path or URLuninstall_app
: Uninstall the package body corresponding to bundle_idstart_app
: start the package body corresponding to bundle_idstop_app
: Stop the package body corresponding to bundle_idps
: get the current process listps_wda
: Get a list of WDAs currently bootingxctest
: start wdaYou can refer to: https://github.com/AirtestProject/Airtest/blob/master/tests/test_tidevice.py
Example of code execution effect:
>>> from airtest.core.ios.ios import TIDevice
>>> devices = TIDevice.devices()
>>> print(devices)
['10da21b9091f799891557004e4105ebab3416cb9']
>>> udid = devices[0]
>>> print(TIDevice.list_app(udid))
[ ('com.230316modified.WebDriverAgentRunner.xctrunner', 'wda-Runner', '1.0'),]
>>> print(TIDevice.list_app(udid, "system"))
[('com.apple.calculator', 'Calculator', '1.0.0'),]
>>> print(TIDevice.list_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
>>> print(TIDevice.device_info(udid))
{'productVersion': '12.4.8', 'productType': 'iPhone7,2', 'modelNumber': 'MG472', 'serialNumber': 'DNPNW6EJG5MN', 'timeZone': 'Asia/Shanghai', 'uniqueDeviceID': '10da21b9091f799891557004e4105ebab3416cb9', 'marketName': 'iPhone 6'}
>>> TIDevice.start_app(udid, "com.apple.mobilesafari")
>>> TIDevice.stop_app(udid, "com.apple.mobilesafari")
>>> print(TIDevice.ps(udid))
[ {'pid': 215, 'name': 'MobileMail', 'bundle_id': 'com.apple.mobilemail', 'display_name': 'MobileMail'}]
>>> print(TIDevice.ps_wda(udid))
['com.test.WebDriverAgentRunner.xctrunner']
The execution example of the TIDevice.xctest
interface is as follows:
import threading
wda_bundle_id = TIDevice.list_wda(udid)[0]
# Create a thread to execute xctest
t = threading.Thread(target=TIDevice.xctest, args=(udid, wda_bundle_id), daemon=True)
t. start()
time. sleep(5)
ps_wda = TIDevice.ps_wda(udid)
print(ps_wda)
time. sleep(5)
# Terminate thread
t.join(timeout=3)
The function of the using
interface is to support another script to be referenced in the script, and at the same time, it can also allow airtest to correctly read the image path in other scripts.
Suppose the directory structure is as follows:
demo/
foo/
bar.air
baz.air
main.py
If we want to reference foo/bar.air
and baz.air
in main.py, we can set the project root path to ST.PROJECT_ROOT
, or make sure the project root path is the current working directory:
# main.py
from airtest.core.api import *
ST.PROJECT_ROOT = r"D:\demo" # This line can be ignored if it is the current working directory
using("foo/bar. air")
using("baz. air")
If we wanted to reference baz.air
in foo/bar.air
, we could write:
# foo/bar.air
from airtest.core.api import *
using("../baz.air")
If no device is currently connected, but some interfaces that need to be connected to the device are called, an exception will be thrown: NoDeviceError("No devices added.")
set_focus
on the windows platform has the same function as the original set_foreground
Android录屏目前提供两种模式,yosemite
和ffmpeg
,区别如下:
yosemite
:原有的默认模式,录屏清晰度和质量较高,但兼容性较差,部分机型可能有问题
orientation
, max_time
, bit_rate
, bit_rate_level
ffmpeg
: 在1.2.9之后加入的新模式,录屏帧率和质量较低,但兼容性更好,能兼容绝大多数设备
orientation
, max_size
, max_time
, fps
, snapshot_sleep
在1.2.10.2中的改动:
cv2
模式已经被舍弃,因为容易引发错误,效果也不如ffmpeg代码示例:
dev = connect_device("android:///")
dev.start_recording(output="test.mp4", mode="ffmpeg", max_size=800) # Android 支持mode指定使用ffmpeg模式
Android screen recording currently provides two modes, yosemite
and ffmpeg
, the differences are as follows:
yosemite
: the original default mode, the recording resolution and quality are higher, but the compatibility is poor, and some models may have problems
max_time
, orientation
, bit_rate
, bit_rate_level
ffmpeg
: a new mode added after 1.2.9, the screen recording frame rate and quality are lower, but the compatibility is better, compatible with most devices
max_time
, fps
, max_size
, snapshot_sleep
Changes in 1.2.10.2:
cv2
mode provided in 1.2.9 has been abandoned, because it is prone to errors and the effect is not as good as ffmpegCode 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
if __name__ == "__main__"
的写法了if __name__ == "__main__"
目前录屏功能不仅支持Android设备,还支持了windows、iOS设备!
函数 start_recording()
参数修改如下:
其中大部分参数使用默认值即可,最重要的参数有两个:
代码示例:
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的初始化字符串中,支持传入名为 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
迭代了windows的snapshot,修复了部分游戏截屏图像重复、黑屏等问题,同时修复了在双屏下的截图区域错误问题。
原先的逻辑是:只要整个运行过程中出现traceback,就认为此次任务运行失败 但通常会遇到一种情况是:在运行过程中会出现一些不太重要的脚本异常,我们希望脚本不卡在这里,而是catch住异常后继续往下跑,只要能跑到最后就算脚本成功。
因此将脚本的成功判断改为:当步骤列表的最后一个步骤有traceback,才认为本次脚本运行失败。
做了一些样式调整,修复了一些显示问题
报告html支持上下左右按键切换预览图片。
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:
Most of the parameters can use the default values, and there are two most important 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"
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.
Currently supports Android 13
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.
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.
Made some style adjustments and fixed some display issues
The report html supports up, down, left, and right buttons to switch the preview image.
1.2.7版本主要是新增了设备释放接口、大量断言的语句,新增了对Android 12L的支持,对安装接口的增强,和若干bug的修复。
device.disconnect()
接口原先的Airtest,在脚本长时间运行、或是使用了AirtestIDE反复连接多个不同手机时,可能会 建立大量adb连接未释放 ,一直占用资源。
这也会导致在部分手机上,反复切换横屏和竖屏应用时,会有概率出现 屏幕一半内容变成黑屏 的问题。
因此,1.2.7版本的Airtest新增了device.disconnect()
接口,用于:
dev.disconnect()
,如果还要继续使用这个设备对象,最好重新再创建一次 dev = connect_device("android:///")
在脚本编写中,断言语句是非常重要的组成部分,但airtest旧版只支持 assert_exists
和 assert_equal
两种类型的断言语句。
现在Airtest1.2.7版本,将所有断言语句单独放在 airtest/core/assertions.py
中,增加了更多类型,方便脚本编写工作。
目前Airtest1.2.7支持的断言列表: assertions
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
Airtest1.2.7除了让断言语句更加丰富以外,还支持设置断言时截取当前画面的图片,然后显示在Airtest报告中,这样报告的断言内容会更加清晰,也更具有airtest的截图特色:
# 默认情况下,断言截图会开启
assert_exists()
# 如不需要断言时截取当前画面,则可以设置关闭断言的截图
assert_exists(截图, snapshot=False)
已增加 minicap
对android 12L的支持,Poco的支持可以等待poco后续的更新。
pm_install
的增强对 pm_install
接口进行了较大的增强:
adb.install
保持一致),adb.pull()
和 adb.push()
接口,支持了中文路径、包含斜杠的路径(比如 \g
这样的字符也会有问题)、包含特殊符号(空格、括号等)的路径pm_install
安装完毕后,会进行 adb shell rm apk
的操作,超时时间30秒如果希望把自定义的函数显示到airtest的报告中,可以使用@logwrap
,例如:
@logwrap
def func1():
pass
如果希望在报告显示func1
内容的同时,还附带一张当前设备的截图的话,可以增加snapshot=True
参数在func1()
的定义中:
@logwrap
def func1(snapshot=True):
pass
adb.text()
在输入字母+数字时可能会导致乱序的问题,同时支持空格airtest.core.win.Windows
对象时,允许开发者选择性跳过 connect()
方法中的 set_foreground()
功能 #1068Android.get_render_resolution
中增加应用包名参数,
使得 get_render_resolution
能够获取到除top activity以外的应用的渲染区域 #1070pip install -U airtest
Version 1.2.7 mainly added device release interface, a large number of assertion statements, added support for Android 12L, enhanced installation interface, and fixed several bugs.
device.disconnect()
interfaceThe 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:
dev.disconnect()
, if you want to continue to use this device object, it is best to recreate it again dev = connect_device(" android:///")
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
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
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)
Added minicap
support for android 12L, Poco support can wait for poco's subsequent updates.
pm_install
Major enhancements to the pm_install
interface:
adb.install
),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.)pm_install
is installed, the adb shell rm apk
operation will be performed with a timeout of 30 secondsIf 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
adb.text()
could cause out-of-order when entering letters + numbers, while supporting spacesairtest.core.win.Windows
object, allow developers to selectively skip set_foreground()
function in connect()
method #1068Android.get_render_resolution
,
Enable get_render_resolution
to get the rendering area of applications other than top activity #1070pip install -U airtest
相关注意事项:
极少部分设备上,可能点击位置会有偏移,目前在AirtestIDE上无法修正鼠标点击的偏移,但是可以在代码中修复,例如:
我们测试到一台iPhone 7Plus手机,在点击时有坐标偏移的现象,因此通过如下方式在运行代码时可以修正:
>>> 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))
关于touch_factor
的解释:
touch_factor
这个值用于换算iOS设备的点击坐标:手机真实坐标 = touch_factor * 屏幕坐标 默认计算方式是:
self.display_info['window_height'] / self.display_info['height']
但在部分特殊型号手机上可能不准确,例如iOS14.4的7P,默认值为 1/3,但部分7P点击位置不准确,可自行设置为:self.touch_factor = 1 / 3.3
Poco相关的注意事项:
start_app
来打开,但本接口目前必须传入手机中已有的app包名,如果传入的包名不存在,可能会导致报错mstpl
的识别效果adb.file_size
接口获取文件大小失败的问题Related Notes:
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:
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 reportedmstpl
adb.file_size
interface fails to obtain the file size under the Android 6.0.1 system