zoukankan      html  css  js  c++  java
  • Appium+Python3 并发启动测试设备

    开启多个设备,但是非并发

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-25 11:38
    # @Author : zhouyang
    # @File : mulit_devices.py
    
    '''多设备启动,非并发
    在命令窗口输入命令:appium -p 4723 可启动设备4723
    '''
    from selenium import webdriver
    import yaml
    from time import ctime
    
    with open('desired_caps.yaml','r') as f:
        data = yaml.load(f)
    
    desired_list=['127.0.0.1:62001','127.0.0.1:62025']
    def appium_devices(udid,port):
        desired_caps={}
        desired_caps['platformName']=data['platformName']
        desired_caps['platformVerion']=data['platformVersion']
        desired_caps['deviceName']=data['deviceName'] #没有实际作用
    
        desired_caps['udid']=udid
    
        desired_caps['app']=data['app']
        desired_caps['noReset']=data['noReset']
        desired_caps['appPackage']=data['appPackage']
        desired_caps['appActivity']=data['appActivity']
    
        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_devices(desired_list[0],4723)
        appium_devices(desired_list[1],4725)

    多进程并发启动多设备

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-25 11:38
    # @Author : zhouyang
    # @File : mulit_devices.py
    
    '''多进程 并发 启动设备
    在命令窗口输入命令:appium -p 4723 可启动设备4723
    '''
    from appium import webdriver
    import yaml
    from time import ctime
    import multiprocessing
    
    with open('desired_caps.yaml','r') as f:
        data = yaml.load(f)
    
    desired_list=['127.0.0.1:62001','127.0.0.1:62025']
    def appium_devices(udid,port):
        desired_caps={}
        desired_caps['platformName']=data['platformName']
        desired_caps['platformVerion']=data['platformVersion']
        desired_caps['deviceName']=data['deviceName'] #没有实际作用
    
        desired_caps['udid']=udid
    
        desired_caps['app']=data['app']
        desired_caps['noReset']=data['noReset']
        desired_caps['appPackage']=data['appPackage']
        desired_caps['appActivity']=data['appActivity']
    
        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
    
    #创建desired进程组
    desired_process=[]
    #加载进程
    for i in range(len(desired_process)):
        port=4723+2*i
        deired=multiprocessing.Process(target=appium_devices(),args=(desired_process[i],port))
        desired_process.append(deired)
    
    if __name__ == '__main__':
        #开启进程
        for deired in desired_process:
            deired.start()
        #关闭进程
        for deired in desired_process:
            deired.join()
  • 相关阅读:
    转 UICollectionView 详解
    springboot配置ssl证书
    服务器ganglia安装(带有登录验证)
    eureka配置说明
    Servlet中获取请求参数问题
    apidoc学习(接口文档定义取代word)
    markdown语法
    JVM分析
    ftp上传或下载文件工具类
    ubuntu命令安装
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/11322213.html
Copyright © 2011-2022 走看看