auto_setup interface connect_device | init_device

auto_setup is an interface used to initialize the environment, and it accepts 5 parameters. We can set the path of the current script, specify the device to run the script, set the default log path, set the script parent path, and specify the screenshot accuracy

auto_setup(basedir=None,devices=None,logdir=None,project_root=None,compress=0)
自动配置运行环境,如果当前没有连接设备,默认尝试连接Android设备
参数
·basedir -设置当前脚本所在路径,也可以直接传__file__变量进来
·devices - 一个内容为connect_device uri 字符串的列表
·logdir - 可设置脚本运行时log保存路径,默认值为None则不保存log,如果设置为True则自动保存在<basedir>/log目录中
·project_root - 用于设置PROJECT_ROOT变量,方便using接口的调用

The second parameter specifies the device to run the script, we can pass in the uri string of the device to be connected here, for example

#连接本机默认端口连的一台设备号为SJE5T17B17的手机
auto_setup(__file__,devices=["Android://127.0.0.1:5037/SJE5T17B17"])

Note that the devices passed in is a list of strings, so if you need to connect to multiple devices, use it directly to separate multiple URI strings.

#连接本机默认端口连的设备号为123和456的两台手机
auto_setup(__file__,devices=["Android://127.0.0.1:5037/123","Androd://127.0.0.1:5037/456"])
AirtestIDE中py脚本,初始化代码
from airtest.core.api import *
from airtest.cli.parser import cli_setup

if not cli_setup():
    auto_setup(__file__, logdir=True, devices=[
        "Android:///?cap_method=javacap&ori_method=adbori",
    ])
了解过auto_setup接口后,可以知道,
一个纯.py的初始化代码,可以是这样
from airtest.core.api import *
from airtest.cli.parser import cli_setup

if not cli_setup():
	auto_setup(__file__,logdir=True,devices=["Android://127.0.0.1:5037/SJE5T17B17"])

2. Use connect_device interface

在connect_device接口中传入设备的uri字符串即可连接一台设备
dev = connect_device("Android://127.0.0.1:5037/SJE5T17B17")
connect_device(uri)
用uri来初始化设备,并且设置为当前设备
参数 uri 一个用于初始化设备的uri字符串
返回 device对象
多台设备 可以编写多条connect_device脚本,并且用set_current来切换到当前使用设备
#连上第一台手机
dev1 = connect_device("Android://127.0.0.1:5037/serialno1")
#连上第二台手机
dev2 = connect_device("Android://127.0.0.1:5037/serialno2")

#切换当前操作手机到序列号为serialno1的手机
set_current('serialno1')

3. Use the init_device interface

init_device 接口只需要传入 设备平台和设备的uuid即可
init_device(platform = 'Android',uuid='SJE5T17B17')

Guess you like

Origin blog.csdn.net/weixin_42540340/article/details/108344476