Python启动多个Appium Services

复制代码
#! /usr/bin/env pyhton
# -*- coding:utf-8 -*-
# author:jeff.xie
# datetime:2024/4/12 16:23
# software:PyCharm

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)

def run_case(host, port):
    print(time.strftime("%H:%M:%S"))
    desired_caps = {}
    # 系统
    desired_caps['platformName'] = 'Android'
    # 手机版本,在手机中:设置--关于手机
    desired_caps['platformVersion'] = '11'
    # 设备号
    desired_caps['deviceName'] = '9b2157cfaedb'
    # 包名
    desired_caps['appPackage'] = 'welab.bank.mobile.stage'
    # desired_caps['appPackage'] = 'welab.bank.sit'
    # # 启动名
    desired_caps['appActivity'] = 'com.welabfrontend.MainActivity'
    # desired_caps["unicodeKeyboard"] = "True"#appium提供的一种输入法,可以传中文。测试时直接用这个输入法
    # desired_caps["resetKeyboard"] = "True"#程序结束时重置原来的输入法
    # desired_caps["noReset"] = "True"#不初始化手机app信息(类似不清除缓存)
    # driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
    driver = webdriver.Remote("http://"+host+":"+str(port)+"/wd/hub", desired_caps)

    driver.wait_activity("com.welabfrontend.MainActivity", 50)
    sleep(5)
    print(time.strftime("%H:%M:%S"))


if __name__ == '__main__':
    host = '127.0.0.1'
    # 运行一个端口
    # port = 4723
for i in range(2):
port = 4723 + 2\* i
appium_start(host, port)

    run_case(host, 4723)
    run_case(host, 4725)



一.端口号设置
Appium服务器端口:4723 bp端口:4724
Appium服务器端口:4725 bp端口:4726
可以看到appium服务器端口和bp端口是相差一位的
什么是bp端口?
bp端口就是bootstrap port,是appium和手机之间的通讯端口,
如果不能指定到,则无法运行多台设备
二.脚本命令写法
在cmd窗口,我们运行设备,是 appium -a host -p 端口号 -bp 端口号
那么我们写在python脚本就是一样的,只不过参数化而已  
/b 是指不打开cmd弹窗运行‘
三.输入到日志
stdout=open('./appium_log/'+str(port)+'.log','a')

启动校验

3.1 通过cmd命令查看

3.1.1查看指定端口号

netstat -ano | findstr 端口号

3.1.2 查看全部端口号

netstat -ano

3.2 通过生成的log文件查看

直接在生成的log文件中,查看即可

3.2.1生成的log文件

3.2.2log文件的内容

相关推荐
默_笙3 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003963 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技3 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读3 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时3 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊3 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1233 天前
2026年第38周GitHub趋势周报
python·科技·github
IZero073 天前
Jev 与 Laya
python·语言模型