Appium 并发测试之 python 启动 appium 服务


python 启动appium服务,需要使用subprocess模块,该模块可以创建新的进程,并且连接到进程的输入,输出,错误等管道信息,并且可以获取进程的返回值

测试场景
使用python启动2台appium服务,端口配置如下:
Appium服务器端口:4723 bp端口:4724
Appium服务器端口:4725 bp端口:4726
可以看到appium服务器端口和bp端口是相差一位的
什么是bp端口?
bp端口就是bootstrap port,是appium和手机之间的通讯端口,
如果不能指定到,则无法运行多台设备

1.启动单个appium服务

import  subprocess
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import time

def appium_start(host, port):

    # 指定bp端口号
    bootstrap_root = str(port+1)
    # 把cmd弹窗输入的命令,直接些在这里
    cmd = 'start /b appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)
    # 去掉 /b 即可打开cmd弹窗运行
    cmd = 'start  appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)

    #打印输入的cmd命令以及时间
    print('%s at %s' %(cmd, time.ctime()))
    subprocess.Popen(cmd, shell= True, stdout=open('./appium_log/'+str(port)+'.log','a'), stderr=subprocess.STDOUT)
    
if __name__ == '__main__':
    host = '127.0.0.1'
    # 运行一个端口
    port = 4723
    appium_start(host, port)

    

启动校验

1.启动后生成日志文件
2.启动后我们需要检验服务是否启动成功
首先查看有没有生成对应的log文件,查看log里面的内容

使用如下命令查看,cmd输入
netstat -ano | findstr 端口号

netstat 命令解释
netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表,、实际的网络练连接以及每一个网络接口设备的状态信息.输入netstat -ano回车。可以查看本机开放的全部端口;输入命令netsat -h 可以查看全部参数含义

关闭Appium服务
关闭进程有2中方式,具体如下:
1.通过 netstat 命令找到对应的 Appium 进程 pid 然后可以在系统任务管理器去关闭进程;win7 系统任务管理器 PID 显示
打开电脑的任务管理器 —> 详细信息,找到对应 pid 后,关闭进程即可
使用如下命令来关闭:
taskkill -f -pid appium进程pid
注意:pid即通过上面netstat命令查看的状态信息
关闭成功后如图所示:


二、启动多个 appium 服务

只需要在执行环境使用循环调用即可。
import  subprocess
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import time


def appium_start(host, port):

    # 指定bp端口号
    bootstrap_root = str(port+1)
    # 把cmd弹窗输入的命令,直接些在这里
    cmd = 'start /b appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)
    # 去掉 /b 即可打开cmd弹窗运行
    cmd = 'start  appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)

    #打印输入的cmd命令以及时间
    print('%s at %s' %(cmd, time.ctime()))
    subprocess.Popen(cmd, shell= True, stdout=open('./appium_log/'+str(port)+'.log','a'), stderr=subprocess.STDOUT)

if __name__ == '__main__':
    host = '127.0.0.1'
    # 运行一个端口
    # port = 4723

    for i in range(2):
        port = 4723 + 2* i
        appium_start(host, port)


启动成功后显示:


用以上方法启动两个 appium 服务,由于显示启动时间较快,看不出区别,实际两个 appium 服务不是同时启动的
会生成两个日志文件:


三、多进程并发启动 appium 服务

python 多进程并发启动 appium 服务需要导入 multiprocessing 多进程模块


# 多进程并发启动多个appium服务
import multiprocessing
import subprocess
from time import ctime
import time


def appium_start_sync(host, port):

    # 指定bp端口号
    bootstrap_root = str(port+1)
    # 把cmd弹窗输入的命令,直接些在这里
    cmd = 'start /b appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)
    # 去掉 /b 即可打开cmd弹窗运行
    # cmd = 'start  appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)

    #打印输入的cmd命令以及时间
    print('%s at %s' %(cmd, time.ctime()))
    subprocess.Popen(cmd, shell= True, stdout=open('./appium_log/'+str(port)+'.log','a'), stderr=subprocess.STDOUT)


# 构建进程组
appium_process = []

host = '127.0.0.1'
# 运行一个端口
# port = 4723
# 加载appium进程
for i in range(2):
    port = 4723 + 2 * i
    appium_sync = multiprocessing.Process(target=appium_start_sync, args=(host, port))
    appium_process.append(appium_sync)


# 测试函数,在手机运行过程中可以注释
if __name__ == '__main__':

    # 并发启动appium服务
    for appium in appium_process:
        appium.start()

    for appium in appium_process:
        appium.join()

# 多进程并发启动多个appium服务
import multiprocessing
import subprocess
from time import ctime
import time

class AppiumStartSync:
    def appium_start_sync(host, port):

        # 指定bp端口号
        bootstrap_root = str(port+1)
        # 把cmd弹窗输入的命令,直接些在这里
        cmd = 'start /b appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)
        # 去掉 /b 即可打开cmd弹窗运行
        cmd = 'start  appium -a ' + host + ' -p ' +str(port)+' -bp ' +str(bootstrap_root)

        #打印输入的cmd命令以及时间
        print('%s at %s' %(cmd, time.ctime()))
        subprocess.Popen(cmd, shell= True, stdout=open('./appium_log/'+str(port)+'.log','a'), stderr=subprocess.STDOUT)


    # 构建进程组
    appium_process = []

    host = '127.0.0.1'
    # 运行一个端口
    # port = 4723
    # 加载appium进程
    for i in range(2):
        port = 4723 + 2 * i
        appium_sync = multiprocessing.Process(target=appium_start_sync, args=(host, port))
        appium_process.append(appium_sync)


# 测试函数,在手机运行过程中可以注释
if __name__ == '__main__':
    appium_start = AppiumStartSync()
    # 并发启动appium服务
    for appium in appium_start.appium_process:
        appium.start()
    for appium in appium_start.appium_process:
        appium.join()
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/817280.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

面试经典150题——轮转数组

面试经典150题 day6 题目来源我的题解方法一 使用额外数组方法二 循环替换方法三 数组翻转 题目来源 力扣每日一题;题序:189 我的题解 方法一 使用额外数组 使用一个额外数组暂存最终答案,最后再赋值给nums 时间复杂度:O(n) 空…

永久关闭 Windows 11 系统更新

永久关闭 Windows 11 系统更新 请注意,关闭系统更新可能会使您的系统面临安全风险。确保您了解可能的后果,并在必要时考虑重新启用更新。 使用组策略编辑器(仅限 Windows 11 Pro 和 Enterprise 版) 步骤 1:打开本地…

Unsupervised Learning ~ Anomaly detection

unusual events vibration: 振动 Density estimation: Gaussian(normal) Distribution. standard deviation: 标准差 variance deviation sigma Mu Parameter estimation Anomaly detection algorithm 少量异常样本点的处理经验 algorithm evaluation skewed datatsets:…

【第十五届】蓝桥杯省赛C++b组

今年的蓝桥杯省赛已经结束了,与以往不同,今年又回到了8道题,而22,23年出现了10道题 大家觉得难度怎么样,欢迎进来讨论,博主今年没参加哈,大家聊聊,我听听大家的意见和看法哈 试题A:…

HTML制作跳动的心形网页

作为一名码农 也有自己浪漫的小心思嗷~ 该网页 代码整体难度不大 操作性较强 祝大家都幸福hhhhh 效果成品&#xff1a; 全部代码&#xff1a; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE> 一个…

静电对集成电路封装的危害及防范措施

在现代工业生产中&#xff0c;静电已经成为一个不可忽视的问题。特别是在集成电路&#xff08;IC&#xff09;封装领域&#xff0c;静电可能对产品质量和生产效率造成严重的影响。本文将探讨静电对IC封装的危害&#xff0c;并介绍一些防范措施以减少静电带来的风险。 静电对IC封…

Python数据挖掘项目开发实战:使用转换器抽取特征

注意&#xff1a;本文下载的资源&#xff0c;与以下文章的思路有相同点&#xff0c;也有不同点&#xff0c;最终目标只是让读者从多维度去熟练掌握本知识点。 Python数据挖掘项目开发实战&#xff1a;使用转换器抽取特征 一、项目背景与目标 在数据挖掘项目中&#xff0c;特征…

ubuntu下的串口调试工具cutecom

系统&#xff1a;ubuntu20.04 &#xff08;1&#xff09;接线 使用 rs485&#xff1c;-----> rs232 转接口&#xff08; 设备直接出来的是rs485&#xff09;&#xff0c;电脑主机接入一根 rs232&#xff1c;-----> USB口 连接线&#xff0c;ubuntu系统下打开 termin…

Gateway基础配置详解

Gateway基础配置详解 随着微服务的流行&#xff0c;API网关作为微服务架构中的关键组件&#xff0c;扮演着越来越重要的角色。在众多的API网关解决方案中&#xff0c;Spring Cloud Gateway以其强大的功能和灵活的配置受到了广泛的关注。本文将详细介绍Spring Cloud Gateway的基…

Redis 集群模式整理

Redis Sentinel 体量较小时&#xff0c;选择 Redis Sentinel &#xff0c;单主 Redis 足以支撑业务。Redis Cluster Redis 官方提供的集群化方案&#xff0c;体量较大时&#xff0c;选择 Redis Cluster &#xff0c;通过分片&#xff0c;使用更多内存。Twemprox Twemprox 是 Tw…

【深入理解Java IO流0x09】解读Java NIO核心知识(下篇)

1. NIO简介 在开始前&#xff0c;让我们再简单回顾一下NIO。 在传统的 Java I/O 模型&#xff08;BIO&#xff09;中&#xff0c;I/O 操作是以阻塞的方式进行的。也就是说&#xff0c;当一个线程执行一个 I/O 操作时&#xff0c;它会被阻塞直到操作完成。这种阻塞模型在处理多…

nssm注册成win10平台的服务

一条命令nssm install 服务名 exe文件目录 如&#xff1a;nssm install wgcloud-agent-release E:\wgcloud-v3.3.5\agent\wgcloud-agent-release.exe 然后找到服务 手动启动一下就可以了&#xff0c;后面就会自动重启服务了。 nssm下载地址

封装Axios

封装Axios 。Axios 是一个基于 Promise 的 HTTP 客户端&#xff0c;它可以帮助我们在浏览器和 Node.js 中发送网络请求。它简洁而强大&#xff0c;但是我们可以通过封装它来增加一些额外的功能&#xff0c;让它变得更好用&#xff01; 好了&#xff0c;让我们来创建一个名为 …

FreeSWITCH在centos7中使用systemctl控制启动和停止以及开机自启

systemctl介绍 systemctl是Linux下的一个系统管理工具&#xff0c;它基于systemd&#xff0c;用于启动、停止、重启、显示状态以及管理系统单元。 systemd是Linux下的一个系统和服务管理器&#xff0c;负责初始化系统并管理系统进程。systemd使用unit&#xff08;单元&#xff…

2024/4/15 AD/DA

AD&#xff08;Analog to Digital&#xff09;&#xff1a;模拟-数字转换&#xff0c;将模拟信号转换为计算机可操作的数字信号 DA&#xff08;Digital to Analog&#xff09;&#xff1a;数字-模拟转换&#xff0c;将计算机输出的数字信号转换为模拟信号 AD/DA转换打开了计算…

Qt事件处理机制3-事件函数的分发

Qt开发中&#xff0c;经常重写event函数和具体的事件处理函数&#xff0c;例如mousePressEvent、paintEvent等&#xff0c;那么这些具体的事件处理函数是怎样被调用的呢&#xff1f;答案是由继承自QObject的类中的event函数来处理事件分发。这里以间接继承自QWidget的派生类MyB…

风控迁徙率报表逻辑和开发(Python)

出品人&#xff1a;东哥起飞 原创&#xff1a;&#x1f449;原创大数据风控课程《100天风控专家》 一、迁徙率介绍 什么是迁徙率呢&#xff1f; 我们说&#xff0c;一个账户现在处于某一逾期状态&#xff08;比如M1&#xff09;&#xff0c;一个月后&#xff0c;这个账户要么…

vscode只修改几行,git却显示整个文件都被修改

原因&#xff1a;不同的操作系统默认的回车换行符是不一样的&#xff0c;有些编辑器会自动修改回车换行&#xff0c;然后就整个文件都变化了。 Unix/Linux/Mac使用的是LF&#xff0c;但Windows一直使用CRLF【回车(CR, ASCII 13, r) 换行(LF, ASCII 10, n)】作为换行符。 解决&a…

Zookeeper(从入门到掌握)看完这一篇就够了

文章目录 一、初识 Zookeeper1.Zookeeper 概念2.Zookeeper 数据模型3.Zookeeper 服务端常用命令4.Zookeeper 客户端常用命令 二、ZooKeeper JavaAPI 操作1.Curator 介绍1.Curator API 常用操作&#xff08;1&#xff09;建立连接&#xff08;2&#xff09;添加节点&#xff08;…

电脑重启后word文档空白或打不开,word无法自动修复,如何拯救

最近编辑word文档&#xff0c;写了好几个星期的内容随着电脑重启的一瞬间&#xff0c;灰飞烟灭&#xff0c;让我简直痛不欲生&#xff01; 好在&#xff0c;天无绝人之路&#xff0c;以下两个方法拯救了地球 第一&#xff0c;普通的文档word自动修复不好使的时候&#xff0c;…