Skip to content

v1.3.0

Compare
Choose a tag to compare
@yimelia yimelia released this 18 Jul 11:13
· 74 commits to master since this release

重要改动

从airtest v1.3.0起,放弃对python2的支持

新增

ios设备接口新增

iOS设备对象IOS,新增以下接口的支持:

  1. (仅支持本地USB设备)安装 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
  1. (仅支持本地USB设备)卸载 uninstall
uninstall("com.netease.cloudmusic")

dev = device()

dev.uninstall_app("com.netease.godlike")
  1. (仅支持本地USB设备)列出所有的app,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)
  1. 获取剪贴板内容, get_clipboard
text = get_clipboard()
print(text)

注意:当iOS设备为远程设备、或者安装了不止一个wda时,需要指定具体的wda_bundle_id才能使用:

text = get_clipboard(wda_bundle_id="com.WebDriverAgentRunner.xctrunner")
  1. 设置剪贴板内容,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")

iOS新增tidevice相关接口

针对本地USB接入的设备,airtest结合tidevice的能力,封装了一个TIDevice对象,提供了几个常用接口如下:

  • devices:列出USB连接的所有设备的 UDID 列表
  • list_app: 列出手机上安装的应用列表,支持对类型进行筛选,包括 user/system/all
  • list_wda: 列出手机上安装的所有WDA的bundleID
  • device_info:获取手机信息
  • install_app:安装ipa包,支持本地路径或URL
  • uninstall_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接口的改动

using接口的作用是,支持在脚本中引用另外一个脚本,同时还能够让airtest正确地读取到其他脚本中的图片路径。

假设目录结构如下:

            demo/
                foo/
                    bar.air
                baz.air
                main.py

如果我们希望在main.py中引用 foo/bar.airbaz.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

如果当前未连接任何设备,但又调用了某些需要连接设备才可以调用的接口时,抛出异常:NoDeviceError("No devices added.")

其他改动

  1. 当airtest脚本引发了assert异常时,退出码为20,以便和其他报错区分
  2. 更新了Yosemite.apk,修复了一些稳定性问题
  3. windows平台新增接口 set_focus,与原先的set_foreground 功能相同

Important changes

From airtest v1.3.0, drop support for python2

add

ios function enhancement

iOS adds support for the following interfaces:

  1. (Only local USB devices are supported) Install 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
  1. (Only local USB devices are supported) Uninstall uninstall
uninstall("com.netease.cloudmusic")

or

dev = device()

dev.uninstall_app("com.netease.godlike")
  1. (Only support local USB devices) list all apps, 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)
  1. Get clipboard content, 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")
  1. Set clipboard content, 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")

New tidevice related interface for iOS

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 USB
  • list_app: Lists the list of apps installed on the phone, supports filtering by type, including user/system/all
  • list_wda: list the bundleIDs of all WDAs installed on the phone
  • device_info: get phone information
  • install_app: install ipa package, support local path or URL
  • uninstall_app: Uninstall the package body corresponding to bundle_id
  • start_app: start the package body corresponding to bundle_id
  • stop_app: Stop the package body corresponding to bundle_id
  • ps: get the current process list
  • ps_wda: Get a list of WDAs currently booting
  • xctest: start wda

You 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)

Changes to the using interface

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")

New error type NoDeviceError

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.")

Other changes

  1. When the airtest script raises an assert exception, the exit code is 20 to distinguish it from other errors
  2. Updated Yosemite.apk and fixed some stability issues
  3. The new interface set_focus on the windows platform has the same function as the original set_foreground