appium实现多个模拟器同时启动Demo

appium关于实现多个模拟器同时启动

multi_devices:

from appium import webdriver
import yaml
from time import ctime
from os import path
import multiprocessing

with open(path.join(path.dirname(path.dirname(__file__)), 'config/desired_caps.yaml'), 'r', encoding='utf-8') as file:
    data = yaml.load(file, Loader=yaml.FullLoader)

devices_list = ['127.0.0.1:62025', '127.0.0.1:62026']

def appium_desired(udid, port):
    desired_caps = {}
    desired_caps['platformName'] = data['platformName']
    desired_caps['platformVersion'] = data['platformVersion']
    desired_caps['deviceName'] = data['deviceName']
    desired_caps['udid'] = udid

    desired_caps['app'] = data['app']
    desired_caps['appPackage'] = data['appPackage']
    desired_caps['appActivity'] = data['appActivity']
    desired_caps['noReset'] = data['noReset']
    # desired_caps['unicodeKeyboard'] = data['unicodeKeyboard']
    # desired_caps['resetKeyboard'] = data['resetKeyboard']

    print('appium port:%s start run %s at %s' %(port, udid, ctime()))
    driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(port) + '/wd/hub', desired_caps)
    driver.implicitly_wait(5)
    return driver


# 构建desired进程组
desired_process = []

# 加载多个desired进程
for i in range(len(devices_list)):
    port = 4723 + 2 * i
    desired = multiprocessing.Process(target=appium_desired, args=(devices_list[i], port))
    desired_process.append(desired)


if __name__ == '__main__':
    # 启动多个设备进行测试
    for desired in desired_process:
        desired.start()
    for desired in desired_process:
        desired.join()

multi_appium:

import subprocess
from time import ctime
import multiprocessing


def appium_start(host, port):
    bootstrap_port = str(port + 1)
    cmd = 'start /b appium -a ' + host + ' -p ' + str(port) + ' -bp ' + str(bootstrap_port)

    print("%s at %s" %(cmd, ctime()))
    subprocess.Popen(cmd, shell=True, stdout=open('./../log/'+str(port)+'.log', 'a'), stderr=subprocess.STDOUT)


appium_process = []


for i in range(2):
    host = '127.0.0.1'
    port = 4723 + 2 * i
    appium = multiprocessing.Process(target=appium_start, args=(host, port))
    appium_process.append(appium)

if __name__ == '__main__':
    # 自动启动端口
    for appium in appium_process:
        appium.start()
    for appium in appium_process:
        appium.join()

还有重要的YAML文件

platformName: Android
platformVersion: 5.1.1
deviceName: 127.0.0.1:62025
app: C:\Users\Administrator\Desktop\1.apk
appPackage: com.sssss
appActivity: org.tel.LaunchActivity
noReset: False
unicodeKeyboard: True
resetKeyboard: True
ip: 127.0.0.1
#port: 4725

你可能感兴趣的:(appium)