airtest.core.ios.ios module

decorator_retry_session(func)[source]

When the operation fails due to session failure, try to re-acquire the session, retry at most 3 times

当因为session失效而操作失败时,尝试重新获取session,最多重试3次

decorator_retry_for_class(cls)[source]

Add decorators to all methods in the class

为class里的所有method添加装饰器 decorator_retry_session

class IOS(addr='http://localhost:8100/', cap_method='MJPEG', mjpeg_port=None)[source]

Bases: airtest.core.device.Device

ios client

  • before this you have to run WebDriverAgent
  • xcodebuild -project path/to/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$(idevice_id -l)" test
  • iproxy $port 8100 $udid
ip

Returns the IP address of the host connected to the iOS phone It is not the IP address of the iOS phone. If you want to get the IP address of the phone, you can access the interface get_ip_address

For example: when the device is connected via http://localhost:8100, return localhost If it is a remote device http://192.168.xx.xx:8100, it returns the IP address of 192.168.xx.xx

Returns:

uuid
using_ios_tagent

当前基础版本:appium/WebDriverAgent 4.1.4 基于上述版本,2022.3.30之后发布的iOS-Tagent版本,在/status接口中新增了一个Version参数,如果能检查到本参数,说明使用了新版本ios-Tagent 该版本基于Appium版的WDA做了一些改动,可以更快地进行点击和滑动,并优化了部分UI树的获取逻辑 但是所有的坐标都为竖屏坐标,需要airtest自行根据方向做转换 同时,大于4.1.4版本的appium/WebDriverAgent不再需要针对ipad进行特殊的横屏坐标处理了 Returns:

is_pad

Determine whether it is an ipad(or 6P/7P/8P), if it is, in the case of horizontal screen + desktop, the coordinates need to be switched to vertical screen coordinates to click correctly (WDA bug)

判断是否是ipad(或 6P/7P/8P),如果是,在横屏+桌面的情况下,坐标需要切换成竖屏坐标才能正确点击(WDA的bug) Returns:

device_info

get the device info.

Note

Might not work on all devices

Returns:dict for device info, eg. AttrDict({
’timeZone’: ‘GMT+0800’, ‘currentLocale’: ‘zh_CN’, ‘model’: ‘iPhone’, ‘uuid’: ‘90CD6AB7-11C7-4E52-B2D3-61FA31D791EC’, ‘userInterfaceIdiom’: 0, ‘userInterfaceStyle’: ‘light’, ‘name’: ‘iPhone’, ‘isSimulator’: False})
window_size()[source]

return window size namedtuple:

Size(width , height)
orientation

return device oritantation status in LANDSACPE POR

get_orientation()[source]
display_info
touch_factor
get_render_resolution()[source]

Return render resolution after rotation

Returns:offset_x, offset_y, offset_width and offset_height of the display
get_current_resolution()[source]
home()[source]
snapshot(filename=None, quality=10, max_size=None)[source]

take snapshot

Parameters:
  • filename – save screenshot to filename
  • quality – The image quality, integer in range [1, 99]
  • max_size – the maximum size of the picture, e.g 1200

Returns:

get_frame_from_stream()[source]
touch(pos, duration=0.01)[source]
Parameters:
  • pos – coordinates (x, y), can be float(percent) or int
  • duration (optional) – tap_hold duration

Returns: None

Examples

>>> touch((100, 100))
>>> touch((0.5, 0.5), duration=1)
double_click(pos)[source]
swipe(fpos, tpos, duration=0, *args, **kwargs)[source]
Parameters:
  • fpos – start point
  • tpos – end point
  • duration (float) – start coordinate press duration (seconds), default is 0
Returns:

None

Examples

>>> swipe((1050, 1900), (150, 1900))
>>> swipe((0.2, 0.5), (0.8, 0.5))
keyevent(keyname, **kwargs)[source]

Perform keyevent on the device

Parameters:
  • keyname – home/volumeUp/volumeDown
  • **kwargs

Returns:

press(keys)[source]

some keys in [“home”, “volumeUp”, “volumeDown”] can be pressed

text(text, enter=True)[source]

Input text on the device :param text: text to input :param enter: True if you need to enter a newline at the end

Returns:None

Examples

>>> text("test")
>>> text("中文")
install_app(uri, package)[source]

curl -X POST $JSON_HEADER -d “{“desiredCapabilities”:{“bundleId”:”com.apple.mobilesafari”, “app”:”[host_path]/magicapp.app”}}” $DEVICE_URL/session https://github.com/facebook/WebDriverAgent/wiki/Queries

start_app(package, *args)[source]
Parameters:package – the app bundle id, e.g com.apple.mobilesafari
Returns:None

Examples

>>> start_app('com.apple.mobilesafari')
stop_app(package)[source]
Parameters:package – the app bundle id, e.g com.apple.mobilesafari

Returns:

app_state(package)[source]
Parameters:package
Returns:
{
“value”: 4, “sessionId”: “0363BDC5-4335-47ED-A54E-F7CCB65C6A65”

}

value 1(not running) 2(running in background) 3(running in foreground)? 4(running)

Examples

>>> 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()[source]

get the app current

Notes

Might not work on all devices

Returns:
{“pid”: 1281,
”name”: “”, “bundleId”: “com.netease.cloudmusic”}
Return type:current app state dict, eg
get_ip_address()[source]

get ip address from webDriverAgent

Returns:raise if no IP address has been found, otherwise return the IP address
device_status()[source]

show status return by webDriverAgent Return dicts of infos

is_locked()[source]

Return True or False whether the device is locked or not

Notes

Might not work on some devices

Returns:True or False
unlock()[source]

Unlock the device, unlock screen, double press home

Notes

Might not work on all devices

Returns:None
lock()[source]

lock the device, lock screen

Notes

Might not work on all devices

Returns:None
alert_accept()[source]

Alert accept-Actually do click first alert button

Notes

Might not work on all devices

Returns:None
alert_dismiss()[source]

Alert dissmiss-Actually do click second alert button

Notes

Might not work on all devices

Returns:None
alert_wait(time_counter=2)[source]

if alert apper in time_counter second it will return True,else return False (default 20.0) time_counter default is 2 seconds

Notes

Might not work on all devices

Returns:None
alert_buttons()[source]

get alert buttons text. .. rubric:: Notes

Might not work on all devices

Returns:(“设置”, “好”)
Return type:# example return
alert_exists()[source]

get True for alert exists or False.

Notes

Might not work on all devices

Returns:True or False
alert_click(buttons)[source]

when Arg type is list, click the first match, raise ValueError if no match

eg. [“设置”, “信任”, “安装”]

Notes

Might not work on all devices

Returns:None
clear_app(package)
home_interface()[source]

get True for the device status is on home interface.

Reason:
some devices can Horizontal screen on the home interface

Notes

Might not work on all devices

Returns:True or False
list_app(**kwargs)
shell(*args, **kwargs)
uninstall_app(package)