autopc.basic.basic_airtest module

class BasicAirtest[源代码]

基类:object

airtest的基础api

static auto_setup(connect_name: str, device_type: str = 'Android', ip: str = '127.0.0.1:5037', hwnd: str = '', title: str = '')[源代码]

设备连接,支持Android和Windows,默认使用Android连接

参数:
  • connect_name – 连接名称

  • device_type – 设备类型

  • ip – IP和端口(Android连接)

  • hwnd – 句柄(windows连接)

  • title – 窗口标题(windows连接)

返回:

None

static snapshot(img_path: str = '')[源代码]

设备截图函数,打印或不打印图片到指定路径

参数:

img_path – 图片路径及名称(打印)

返回:

ndarray

static loop_find(template: Template, timeout=20, threshold=None, interval=0.5, intervalfunc=None, random_area=0)[源代码]

判断模板图片在设备上是否存在,如果存在返回坐标

参数:
  • template – 图片类

  • timeout – 超时时间

  • threshold – 相似度

  • interval – 识别间隔

  • intervalfunc

  • random_area – 随机区域,默认0,取中心点,大于零小于等于1则区域内随机

返回:

static exists(template: Template, cvstrategy: [] = ['mstpl', 'tpl', 'sift', 'brisk'], timeout: float = 3, random_area=0)[源代码]

判断模板图片在设备上是否存在,如果存在返回坐标

参数:
  • template – 图片类

  • cvstrategy – 图像识别算法

  • timeout – 超时时间

  • random_area – 随机区域,默认0,取中心点,大于零小于等于1则区域内随机

返回:

bool

static touch(template: Template, cvstrategy: [] = ['mstpl', 'tpl', 'sift', 'brisk'], timeout: float = 3, times: int = 1, **kwargs)[源代码]

判断模板图片在设备上是否存在,如果存在点击 :param times: 点击次数 :param cvstrategy: 图像识别算法 :param template: 图片类 :param timeout: 超时时间 :return: bool

static touch_coordinate(pos: (), times: int = 1, **kwargs)[源代码]

点击坐标 :param pos: 坐标信息(x,y) :param times: 点击次数 :return: bool

static adb_stop_app(package: str)[源代码]

停止APP

参数:

package – app的包名

返回:

static adb_start_app(package: str)[源代码]

启动APP

参数:

package – app的包名

返回:

static adb_restart_app(package: str)[源代码]

重启APP

参数:

package – app的包名

返回:

static swipe(v1: [], v2: [], duration: float = 0.1)[源代码]

滑动 :param duration: 间隔 :param v1: 坐标1 :param v2: 坐标2 :return: bool

static crop_image(x1, y1, x2, y2)[源代码]

局部截图

参数:
  • x1 – x1

  • y1 – y1

  • x2 – x2

  • y2 – y2

返回:

ndarray

static resolution_ratio()[源代码]

获取当前设备分辨率

返回:

Tuple

static cvt_color(screen)[源代码]

颜色空间转换 BGR->RGB

参数:

screen – 图片

返回:

ndarray

static find_all(template: Template, cvstrategy: [] = ['mstpl', 'tpl', 'sift', 'brisk'], timeout: float = 20)[源代码]

在设备屏幕上查找所有出现的目标并返回它们的坐标

参数:
  • template – template对象

  • timeout – 超时时间

  • cvstrategy – 图像识别算法

返回:

[{‘result’: (x, y),’rectangle’: ( (left_top, left_bottom, right_bottom, right_top) ),’confidence’: 0.9},…]

static cv_match(template: Template, screen, cvstrategy: [] = ['mstpl', 'tpl', 'sift', 'brisk'])[源代码]

图片中查找图片信息

参数:
  • template – 图片1 template格式

  • screen – 图片2 ndarray格式

  • cvstrategy – 图像识别算法

返回:

[{‘result’: (x, y),’rectangle’: ( (left_top, left_bottom, right_bottom, right_top) ),’confidence’: 0.9},…]

static match_in(template: Template, screen, cvstrategy: [] = ['mstpl', 'tpl', 'sift', 'brisk'], timeout: float = 3)[源代码]

判断图片是否存在图片并返回坐标(x,y)

参数:
  • screen – 局部截图

  • template – 图片类

  • cvstrategy – 图像识别算法

  • timeout – 超时时间

返回:

(x,y)

static text(word: str)[源代码]

输入文字

参数:

word – 文字内容

返回:

None

static get_cap_method(serialno)[源代码]

获取截图方法

参数:

serialno – 安卓设备序列号

返回:

str

static check_fast_method(serialno)[源代码]

检查最快的、可用的截图方法

参数:

serialno – 安卓设备序列号

返回:

str

static check_method(serialno)[源代码]

检查当前设备使用的截图方法

参数:

serialno – 安卓设备序列号

返回:

str