qt4i.icontrols Package

iOS基础UI控件模块

class qt4i.icontrols.ActionSheet(root, locator=None, **ext)

基类:qt4i.icontrols.Element

UIActionSheet弹出框

buttons

ActionSheet上面的所有按钮

click_button(text)

点击text对应的按钮

参数:text (str) – 按钮上的文本
class qt4i.icontrols.Alert(root, locator="/classname='UIAAlert' & maxdepth = 20", **ext)

基类:qt4i.icontrols.Element

弹出框

由于弹出框在iOS不同版本中的UI逻辑不一致(QPath不同),但业务逻辑相对统一(确定/取消),故单独封装成一个类

buttons

Alert控件上的所有按钮

click_button(text)

点击指定文本的按钮

参数:text (str) – 按钮上的文本
title

提示文本内容

class qt4i.icontrols.Button(root, locator, **ext)

基类:qt4i.icontrols.Element

Button控件

class qt4i.icontrols.Cell(element, locators={})

基类:object

TableCell控件

class qt4i.icontrols.ControlContainer

基类:object

控件集合接口

Controls

返回子控件集合 - 示例:XX_Window.Controls[‘XX_按钮’].click()

clearLocator()

清空控件定位参数

hasControlKey(control_key)

是否包含控件control_key

参数:control_key (str) – 控件名
返回类型:boolean
isChildCtrlExist(childctrlname, timeout={'interval': 0.005, 'timeout': 2.0})

判断子控件是否存在

参数:childctrlname (str) – 控件名
返回类型:boolean
updateLocator(locators)

更新控件定位参数

参数:locators (dict) – 定位参数,格式是 {‘控件名’:{‘type’:控件类, 控件类的参数dict列表}, …}
class qt4i.icontrols.Element(root, locator, **ext)

基类:qt4i.icontrols.ControlContainer

控件(UI框架是由各种控件组合而成)

children

获取子控件(仅含相对本控件的第二层子控件,不含第三层以及更深层的子控件,建议用此方法解决动态Path的场景)

返回:[Element, …]
返回类型:list
click(offset_x=None, offset_y=None)

点击控件

参数:
  • offset_x (float or None) – 相对于该控件的坐标offset_x,百分比( 0 -> 1 ),不传入则默认该控件的中央
  • offset_y (float or None) – 相对于该控件的坐标offset_y,百分比( 0 -> 1 ),不传入则默认该控件的中央
double_click(offset_x=0.5, offset_y=0.5)

双击控件

参数:
  • offset_x (float) – 相对于该控件的坐标offset_x,百分比( 0 -> 1 ),不传入则默认该控件的中央
  • offset_y (float) – 相对于该控件的坐标offset_y,百分比( 0 -> 1 ),不传入则默认该控件的中央
drag(from_x=0.9, from_y=0.5, to_x=0.1, to_y=0.5, duration=0.5)

回避控件边缘,在控件体内拖拽(默认在控件内从右向左拖拽)

参数:
  • from_x (float) – 起点 x偏移百分比(从左至右为0.0至1.0)
  • from_y (float) – 起点 y偏移百分比(从上至下为0.0至1.0)
  • to_x (float) – 终点 x偏移百分比(从左至右为0.0至1.0)
  • to_y (float) – 终点 y偏移百分比(从上至下为0.0至1.0)
  • duration (float) – 持续时间(秒)
drag2(direct='Left')

回避边缘在控件体内拖拽

参数:direct (EnumDirect.Left|EnumDirect.Right|EnumDirect.Up|EnumDirect.Down) – 拖拽的方向
enabled

控件是否开启

返回类型:boolean
exist()

控件是否存在

返回类型:boolean
find_elements(locator)

通过相对于当前父对象的Path搜索子孙控件(建议用此方法解决动态Path的场景)

参数:locator (QPath | str) – 相对当前对象的 - 子Path对象 或 子Path字符串 (搜索的起点为当前父对象)
返回:[Element, …]
返回类型:list
first_with_name(name)

通过name文本获取第一个匹配的子element

参数:name (str) – 子控件的name
返回类型:Element or None
first_with_predicate(predicate)

通过predicate文本获取第一个匹配的子element

参数:predicate (str) – 预期子element的predicate (例如:“name beginswith ‘xxx’”)
返回类型:Element or None
first_with_value_for_key(key, value)

通过匹配指定key的value,获取第一个匹配的子element

参数:
  • key (str) – key (例如:label、name、value)
  • value (str or int) – 对应key的value值
返回类型:

Element or None

flick(from_x=0.9, from_y=0.5, to_x=0.1, to_y=0.5)

滑动/拂去(默认从右向左回避边缘进行滑动/拂去)该接口比drag的滑动速度快,如果滚动距离大,建议用此接口

参数:
  • from_x (float) – 起点 x偏移百分比(从左至右为0.0至1.0)
  • from_y (float) – 起点 y偏移百分比(从上至下为0.0至1.0)
  • to_x (float) – 终点 x偏移百分比(从左至右为0.0至1.0)
  • to_y (float) – 终点 y偏移百分比(从上至下为0.0至1.0)
flick2(direct='Left')

回避边缘在控件体内滑动/拂去

参数:direct (EnumDirect.Left|EnumDirect.Right|EnumDirect.Up|EnumDirect.Down) – 滑动/拂去的方向
force_touch(pressure=1.0, duration=2.0)

3D touch

参数:
  • pressure (float) – 按压力度(取值:0-1.0)
  • duration (float) – 按压持续的时间(单位:秒)
get_attr_dict()

获取元素的属性信息,返回字典

返回类型:dict
get_metis_view()

返回MetisView

label

控件的label

返回类型:str or None
long_click(duration=3, offset_x=0.5, offset_y=0.5)

单指长按

参数:
  • duration (int) – 持续时间(秒)
  • offset_x (float) – 相对于该控件的坐标offset_x,百分比( 0 -> 1 ),不传入则默认该控件的中央
  • offset_y (float) – 相对于该控件的坐标offset_y,百分比( 0 -> 1 ),不传入则默认该控件的中央
name

控件的name

返回类型:str or None
parent

获取上一级的父控件

返回类型:Element
print_uitree()

打印当前控件的UI树

rect

控件的矩形信息

返回类型:Rectangle
screenshot(image_path=None, image_type=None)

截屏

Attention:

裁剪图像使用了PIL库,使用该接口请安装Pillow,如下:pip install Pillow

参数:
  • image_path (str) – 截屏图片的存放路径
  • image_path – 截屏图片的存放路径
返回:

截屏结果和截屏文件的路径

返回类型:

tuple (boolean, str)

scroll_to_visible(rate=1.0, drag_times=20)

自动滚动到元素可见(技巧: Path中不写visible=true,当对象在屏幕可视范围之外,例如底部,调用此方法可以自动滚动到该元素为可见)

参数:drag_times (int) – 最多尝试下滑次数,默认20次
send_keys(keys)

输入字符串

参数:keys (str) – 字符串内容
Attention:该接口不支持中文,中文输入请使用value=’中文’
value

控件的value

返回类型:None | str
visible

控件是否可见

返回类型:boolean
wait_for_exist(timeout, interval)

控件是否存在

参数:
  • timeout (float) – 超时值(秒),例如对象需要等待网络拉取10秒才出现
  • interval (float) – 轮询值(秒),轮询值建议 0.005 秒
返回类型:

boolean

with_name(name)

通过name文本获取匹配的子elements

参数:name (str) – 子控件的name
返回类型:list
with_predicate(predicate)

通过predicate文本获取第一个匹配的子element :param predicate: 预期子element的predicate (例如:“name beginswith ‘xxx’”) :type predicate: str :rtype: Element or None

with_value_for_key(key, value)

通过匹配指定key的value,获取所有匹配的子element

参数:
  • key (str) – key (例如:label、name、value)
  • value (str or int) – 对应key的value值
返回类型:

Element or None

class qt4i.icontrols.MetisView(element)

基类:object

click(offset_x=None, offset_y=None)

点击

参数:
  • offset_x (float or None) – 相对于该控件的坐标offset_x,百分比( 0 -> 1 ),不传入则默认该控件的中央
  • offset_y (float or None) – 相对于该控件的坐标offset_y,百分比( 0 -> 1 ),不传入则默认该控件的中央
drag(from_x=0.5, from_y=0.5, to_x=0.5, to_y=0.1, duration=0.5)

拖拽

参数:
  • from_x (float) – 起点 x偏移百分比(从左至右为0.0至1.0)
  • from_y (float) – 起点 y偏移百分比(从上至下为0.0至1.0)
  • to_x (float) – 终点 x偏移百分比(从左至右为0.0至1.0)
  • to_y (float) – 终点 y偏移百分比(从上至下为0.0至1.0)
  • duration (float) – 持续时间(秒)
os_type

系统类型,例如”android”,”ios”,”pc”

rect

元素相对坐标(x, y, w, h)

screenshot()

当前容器的区域截图

class qt4i.icontrols.PickerWheel(root, locator, **ext)

基类:qt4i.icontrols.Element

滚轮选择框

class qt4i.icontrols.SecureTextField(root, locator, **ext)

基类:qt4i.icontrols.Element

密码输入框

class qt4i.icontrols.Slider(root, locator="/classname='UIASlider' & maxdepth = 20", **ext)

基类:qt4i.icontrols.Element

进度条

value

控件的value

返回类型:None | str
class qt4i.icontrols.TableView(root, locator=None, **ext)

基类:qt4i.icontrols.Element

TableView控件

class qt4i.icontrols.TextField(root, locator, **ext)

基类:qt4i.icontrols.Element

文本输入框

class qt4i.icontrols.Window(root, locator=None, **ext)

基类:qt4i.icontrols.Element

窗口基类