可以使用多线程或者多进程实现,这里使用的是多进程。修改appium监听的端口号,否则会启动失败。
# user/bin/env python # -*- coding:utf-8 -*- # __author__ = "Cc" from appium import webdriver import multiprocessing desired_caps_a = {'platformName': "Android", 'platformVersion': "", 'deviceName': "", 'appPackage': "", 'appActivity': "", 'noReset': True, 'unicodeKeyboard': True, 'resetKeyboard': True} desired_caps_b = {'platformName': "Android", 'platformVersion': "", 'deviceName': "", 'appPackage': "", 'appActivity': "", 'noReset': True, 'unicodeKeyboard': True, 'resetKeyboard': True} host_address_a = "http://localhost:4723/wd/hub" host_address_b = "http://localhost:4727/wd/hub" def start_mobile(desired_caps, host_address): """多进程启动设备 :desired_caps:启动手机端信息 :host_address:appium服务器端信息 :return:driver """ driver = webdriver.Remote(host_address, desired_caps) return driver desired_processes = [] if __name__ == '__main__': desired_process1 = multiprocessing.Process(target=start_mobile, args=(desired_caps_a, host_address_a)) desired_processes.append(desired_process1) desired_process2 = multiprocessing.Process(target=start_mobile, args=(desired_caps_b, host_address_b)) desired_processes.append(desired_process2) for process in desired_processes: process.start() for process in desired_processes: process.join() # 阻塞上下文环境的进程,直到调用此方法的进程结束