Python 启动Appium Service然后执行APP自动化case

复制代码
#! /usr/bin/env pyhton
# -*- coding:utf-8 -*-
# author:jeff.xie
# datetime:2024/4/11 16:54
# 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
appium_start(host, port)
run_case(host, port)
相关推荐
氵文大师10 分钟前
A机通过 python -m http.server 下载B机的文件
linux·开发语言·python·http
程序员爱钓鱼19 分钟前
用 Python 批量生成炫酷扫光 GIF 动效
后端·python·trae
封奚泽优21 分钟前
下降算法(Python实现)
开发语言·python·算法
java1234_小锋26 分钟前
基于Python深度学习的车辆车牌识别系统(PyTorch2卷积神经网络CNN+OpenCV4实现)视频教程 - 自定义字符图片数据集
python·深度学习·cnn·车牌识别
爱笑的眼睛1134 分钟前
深入理解MongoDB PyMongo API:从基础到高级实战
java·人工智能·python·ai
辣椒酱.40 分钟前
jupyter相关
python·jupyter
郝学胜-神的一滴44 分钟前
Python中常见的内置类型
开发语言·python·程序人生·个人开发
火白学安全1 小时前
《Python红队攻防零基础脚本编写:进阶篇(一)》
开发语言·python·安全·web安全·网络安全·系统安全
FreeCode1 小时前
LangGraph1.0智能体开发:运行时系统
python·langchain·agent
青瓷程序设计2 小时前
植物识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习