python appium 并行多设备_appium 多设备并行运行

# coding=utf-8fromappium importwebdriver

importtime

importyaml

importos

fromtomorrow importthreads

defstart_appium(port,bootstrap,udid):

a = os.popen('netstat -ano | findstr "%s" '% port)

time.sleep(2)

t1 = a.read()

if"LISTENING"int1:

print("appium服务已经启动:%s"% t1)

# s = t1.split(" ")

# s1 = [i for i in s if i != '']

# pip = s1[-1].replace("\n", "")else:

# 启动appium服务

# appium -a 127.0.0.1 -p 4740 -U emulator-5554 127.0.0.1:62001 --no-reset

# os.system("start /b appium -a 127.0.0.1 -p %s -U %s --no-reset" % (port, udid))

# appium -a 127.0.0.1 -p 4724 -bp 4725 -U 127.0.0.1:62001os.system("start /b appium -a 127.0.0.1 -p %s -bp %s -U %s"% (port,bootstrap,udid))

defstop_appium(): # 关闭所有的appium进程os.system("start /b taskkill /F /t /IM node.exe")

defget_desired_caps(devices_name):

"""

从yaml读取desired_caps配置信息

参数name:设备名称,如:夜神/真机1:return: desired_caps字典格式

"""curpath = os.path.dirname(os.path.realpath(__file__))

print("路径为:"+curpath)

yamlpath = os.path.join(curpath,"yaml_appium.yaml")

print("配置地址:%s"% yamlpath)

f = open(yamlpath,"r",encoding="utf-8")

a = f.read()

f.close()

# 把yaml文件转字典d = yaml.load(a)

print(d)

forii ind:

print(ii)

ifdevices_name inii["desc"]: # 判断输入的设备名称是否存在

# 启动服务devicesname = ii['desired_caps']['udid']

print("devicesName: %s"% devicesname)

print("port: %s"%ii['port'])

print("bootstrap: %s"% ii['bootstrap-port'])

print("udid: %s"% ii['desired_caps']['udid'])

start_appium(port=ii['port'],bootstrap=ii['bootstrap-port'],udid=ii['desired_caps']['udid'])

# start_appium(port=ii['port'], udid=devicesName)returnii['desired_caps'],ii['port']

@threads(2)

defrun_app(devices_name):

# 配置参数desired_caps = get_desired_caps(devices_name)

#app测试用例操作

# 执行代码

driver= webdriver.Remote('http://127.0.0.1:%s/wd/hub'% desired_caps[1],desired_caps[0])

if__name__ == "__main__":

devices = ["夜神","真机1"]

fori indevices:

run_app(devices_name=i)

stop_appium()

yaml 文件内容如下:- desc: 设备名称_真机1,appium启动服务端口号_4723

port: 4723

desired_caps:

platformName: Android

deviceName: 192.168.93.210:5555

appPackage: com.jifen.qukan.debug

app: C:\Users\admin\PycharmProjects\locust_test\apps\qutoutiao_debug.apk

appActivity: com.jifen.qkbase.main.MainActivity

clearSystemFiles: true

noSign: True

noReset: !!bool False

platformVersion: 4.4.2

udid: 192.168.93.210:5555

newCommandTimeout: 120

bootstrap-port: 4726

- desc: 设备名称_夜神,appium启动服务端口号_4724

port: 4724

desired_caps:

platformName: Android

noSign: True

deviceName: 127.0.0.1:62001

appPackage: com.jifen.qukan.debug

app: C:\Users\admin\PycharmProjects\locust_test\apps\qutoutiao_debug.apk

appActivity: com.jifen.qkbase.main.MainActivity

clearSystemFiles: true

noReset: !!bool False

platformVersion: 4.4.2

udid: 127.0.0.1:62001

newCommandTimeout: 120

bootstrap-port: 4725

================================================

第一台设备:adb tcpip 端口(5555) adb connect 手机ip:端口(5555)

第二台设备:adb devices 查看手机的udid ,然后adb -s udid tcpip 端口(5556) adb connect 手机ip:端口(5556)

你可能感兴趣的:(python,appium,并行多设备)