多设备启动
前面我们已经启动了多个appium服务,那么接下来我们可以基于这些服务来启动不同的设备。
测试场景
连接以下2台设备,然后分别启动App
- 设备1:127.0.0.1:62001
- 设备2:127.0.0.1:62025
代码实现
multi_device.py
from appium import webdriver import yaml from time import ctime import os with open('kyb_caps.yaml','r',encoding="utf-8")as file: data=yaml.load(file,Loader=yaml.FullLoader) devices_list=['127.0.0.1:62001','127.0.0.1:62025'] def appium_desire(udid,port): desired_caps={} desired_caps['platformName']=data['platformName'] desired_caps['platformVersion']=data['platformVersion'] desired_caps['deviceName']=data['deviceName'] #devicesName 虽然是强制要求写的,但是没啥用,只要写一个就行如下yaml的配置 desired_caps['udid']=udid base_dir = os.path.dirname(os.path.dirname(__file__)) app_path = os.path.join(base_dir, 'app', data['appname']) desired_caps['app'] = app_path desired_caps['appPackage']=data['appPackage'] desired_caps['appActivity']=data['appActivity'] desired_caps['noreset']=data['noreset'] 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) return driver if __name__ == '__main__': appium_desire(devices_list[0],4723) appium_desire(devices_list[1],4725)
yaml 的 配置
platformName: Android #模拟器 platformVersion: 5.1.1 deviceName: 127.0.0.1:62025 #deviceName: 127.0.0.1:62001 #mx4真机 #platformVersion: 5.1 #udid: 750BBKL22GDN #deviceName: MX4 appname: EGStar1.03.200316.beta.apk noreset: False unicodeKeyboard: True resetKeyboard: True appPackage: com.southgnss.egstar3 appActivity: com.southgnss.egstar.EGStarSplash ip: 127.0.0.1 #port: 4723