Appium python 框架

目录

前言

流程

结构

具体说说 run.py

思路

其他模块


前言

Appium是一个开源的移动应用自动化测试框架,它允许开发人员使用多种编程语言(包括Python)来编写自动化测试脚本。Appium框架提供了一套API和工具,可以与移动设备进行通信,并模拟用户在移动应用上的操作。

流程

1.打开 appium server
2.获取当前手机的 device Name 和 安卓版本号,打开 driver
3.运行 case
4.生成报告
5.关闭 driver
6.关闭 appium server

结构

具体说说 run.py

整个程序是从这个模块开始运行的,也是花了我最长时间的地方。下面上代码

# ========================================================
# Summary        :run
# Author         :tong shan
# Create Date    :2015-10-09
# Amend History  :
# Amended by     :
# ========================================================import readConfig
readConfigLocal = readConfig.ReadConfig()
import unittest
from testSet.common.DRIVER import myDriver
import testSet.common.Log as Log
import os
from time import sleepfrom selenium.common.exceptions import WebDriverException
import threadingmylock = threading.RLock()
log = Log.myLog.getLog()# ========================================================
# Summary        :myServer
# Author         :tong shan
# Create Date    :2015-10-10
# Amend History  :
# Amended by     :
# ========================================================
class myServer(threading.Thread):def __init__(self):global appiumPaththreading.Thread.__init__(self)self.appiumPath = readConfigLocal.getConfigValue("appiumPath")def run(self):log.outputLogFile("start appium server")rootDirectory = self.appiumPath[:2]startCMD = "node node_modules\\appium\\bin\\appium.js"#cd root directory ;cd appiuu path; start serveros.system(rootDirectory+"&"+"cd "+self.appiumPath+"&"+startCMD)# ========================================================
# Summary        :Alltest
# Author         :tong shan
# Create Date    :2015-10-10
# Amend History  :
# Amended by     :
# ========================================================
class Alltest(threading.Thread):def __init__(self):threading.Thread.__init__(self)global casePath, caseListLpath, caseList, suiteList, appiumPathself.caseListPath = readConfig.logDir+"\\caseList.txt"self.casePath = readConfig.logDir+"\\testSet\\"self.caseList = []self.suiteList = []self.appiumPath = readConfigLocal.getConfigValue("appiumPath")# =================================================================
# Function Name   : driverOn
# Function        : open the driver
# Input Parameters: -
# Return Value    : -
# =================================================================def driverOn(self):myDriver.GetDriver()# =================================================================
# Function Name   : driverOff
# Function        : colse the driver
# Input Parameters: -
# Return Value    : -
# =================================================================def driverOff(self):myDriver.GetDriver().quit()# =================================================================
# Function Name   : setCaseList
# Function        : read caseList.txt and set caseList
# Input Parameters: -
# Return Value    : -
# =================================================================def setCaseList(self):print(self.caseListPath)fp = open(self.caseListPath)for data in fp.readlines():sData = str(data)if sData != '' and not sData.startswith("#"):self.caseList.append(sData)# =================================================================
# Function Name   : createSuite
# Function        : get testCase in caseList
# Input Parameters: -
# Return Value    : testSuite
# =================================================================def createSuite(self):self.setCaseList()testSuite = unittest.TestSuite()if len(self.caseList) > 0:for caseName in self.caseList:discover = unittest.defaultTestLoader.discover(self.casePath, pattern=caseName+'.py', top_level_dir=None)self.suiteList.append(discover)if len(self.suiteList) > 0:for test_suite in self.suiteList:for casename in test_suite:testSuite.addTest(casename)else:return Nonereturn testSuite# =================================================================
# Function Name   : runTest
# Function        : run test
# Input Parameters: -
# Return Value    : -
# =================================================================def run(self):try:while not isStartServer():mylock.acquire()sleep(1)log.outputLogFile("wait 1s to start appium server")mylock.release()else:log.outputLogFile("start appium server success")suit = self.createSuite()if suit != None:log.outputLogFile("open Driver")self.driverOn()log.outputLogFile("Start to test")unittest.TextTestRunner(verbosity=2).run(suit)log.outputLogFile("end to test")log.outputLogFile("close to Driver")self.driverOff()else:log.outputLogFile("Have no test to run")except Exception as ex:log.outputError(myDriver.GetDriver(), str(ex))def isStartServer():try:driver = myDriver.GetDriver()if driver == None:return Falseelse:return Trueexcept WebDriverException:raiseif __name__ == '__main__':thread1 = myServer()thread2 = Alltest()thread2.start()thread1.start()while thread2.is_alive():sleep(10)#"allTest is alive,sleep10"else:#kill myServeros.system('taskkill /f /im node.exe')log.outputLogFile("stop appium server")

思路

刚接触的时候发现每次都要手动打开 appium 服务,然后再运行代码,想着是不是太麻烦了?就想试着可不可做成一步?
这一想,就费了我好多功夫。
1.打开 appium server
开始的时候,连如何用命令行打开服务都不会,在群里问了一圈(感谢回答问题的大大们!!!),然后自己又琢磨了一下,搞定了,可是!!!用 os.system(),居然阻塞进程,最后还是问了群里的大大解决(再次感谢!!!!)。
2.如何判断 server 是否被成功开启
这个问题我想了很久,现在我解决了,但是解决方法我不太满意,希望有大大可以给我一个好点的方法或者思路(跪谢!!)
目前做法:判断是否可以返回一个正常的 driver 对象

def isStartServer():try:driver = myDriver.GetDriver()if driver == None:return Falseelse:return Trueexcept WebDriverException:raise

3.关闭 appium server
目前的做法是强制杀死,还是不太满意,不知道以后会不会有什么不可预见的问题,希望有大大可以给我一个好点的方法或者思路(跪谢!!)

if __name__ == '__main__':thread1 = myServer()thread2 = Alltest()thread2.start()thread1.start()while thread2.is_alive():sleep(10)#"allTest is alive,sleep10"else:#kill myServeros.system('taskkill /f /im node.exe')log.outputLogFile("stop appium server")

其他模块

1.common.py 共同方法,主要指封装了一些方法,供其他模块使用。
2.DRIVER.py 获取 driver,这里是做成了一个单例模式,run.py 中打开,关闭,其他模块调用。
3.Log.py 中有 2 个类 log 和 myLog,同样也把 myLog 做成了一个单例模式
4.myPhone.py 主要使用了 adb 命令来识别和获取手机参数
5.readConfig.py 是读取配置文件

  作为一位过来人也是希望大家少走一些弯路

在这里我给大家分享一些自动化测试前进之路的必须品,希望能对你带来帮助。

(WEB自动化测试、app自动化测试、接口自动化测试、持续集成、自动化测试开发、大厂面试真题、简历模板等等)

相信能使你更好的进步!

点击下方小卡片

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

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

相关文章

基于单片机语音识别智能家居系统的设计与实现

功能介绍 以STM32单片机作为主控系统;液晶显示当前环境温湿度,用电器开关状态通过语音模块识别设定的语音;DHT11进行环境温湿度采集;通过语音播报模块报当前温湿度,智能回复通过语音识别可以打开灯,窗帘&am…

C语言-排序,初识指针

目录 【1】冒泡排序&#xff08;从小到大&#xff09; 【2】选择排序 【3】二维数组 【4】指针 【5】指针修饰 【6】大小端 【7】初见二级指针 练习&#xff1a; 【1】冒泡排序&#xff08;从小到大&#xff09; #include <stdio.h> //数组哪里的\0?自己和字符串…

Flink 在新能源场站运维的应用

摘要&#xff1a;本文整理自中南电力设计院工程师、注册测绘师姚远&#xff0c;在 Flink Forward Asia 2022 行业案例专场的分享。本篇内容主要分为四个部分&#xff1a; 建设背景 技术架构 应用落地 后续及其他 点击查看原文视频 & 演讲PPT 一、建设背景 建设背景主要…

Yalmip入门教程(3)-约束条件的定义

博客中所有内容均来源于自己学习过程中积累的经验以及对yalmip官方文档的翻译&#xff1a;https://yalmip.github.io/tutorials/ 之前的博客简单介绍了约束条件的定义方法&#xff0c;接下来将对其进行详细介绍。 首先简单复习一下&#xff1a; 1.定义约束条件可以使用矩阵拼接…

GRE和MGRE

目录 GRE GRE环境的搭建 MGRE MGRE的配置 MGRE环境下的RIP网络 MGRE实验 VPN 说到GRE&#xff0c;我们先来说个大家熟悉一点的&#xff0c;那就是VPN技术。 背景需求 企业、组织、商家等对专用网有强大的需求。 高性能、高速度和高安全性是专用网明显的优势。 物理专…

Notepad++ 配置python虚拟环境(Anaconda)

Notepad配置python运行环境步骤&#xff1a; 打开Notepad ->”运行”菜单->”运行”按钮在弹出的窗口内输入以下命令&#xff1a; 我的conda中存在虚拟环境 (1) base (2) pytorch_gpu 添加base环境至Notepad中 cmd /k chdir /d $(CURRENT_DIRECTORY) & call cond…

TX Barcode .NET for WPF Crack

TX Barcode .NET for WPF Crack 用于WPF软件的TX Barcode.NET包括一天完成的功能以及用于WPF的软件的2D条形码控制。 用于WPF的TX Barcode.NET的功能和属性&#xff1a; 它具有以下特性和属性&#xff0c;如&#xff1a; 常见的文字处理功能&#xff1a;它可以为用户和开发人员…

Spark和Hive概念

Spark介绍&#xff1a; Spark是一个开源的分布式数据处理引擎&#xff0c;最初由加州大学伯克利分校的AMPLab开发。它被设计用来处理大规模数据集&#xff0c;提供快速、通用、易用的数据处理框架。Spark能够在内存中快速处理数据&#xff0c;支持多种数据源&#xff0c;包括Ha…

FastEdit ⚡:在10秒内编辑大型语言模型

概述&#xff1a; 这个仓库旨在通过一个单一的命令&#xff0c;有效地将新鲜且定制化的知识注入到大型语言模型中&#xff0c;以辅助开发人员的工作。 支持的模型&#xff1a;○ GPT-J (6B)○ LLaMA (7B/13B)○ BLOOM (7.1B)○ Falcon (7B)○ Baichuan (7B/13B)○ InternLM (7…

Java语法和C#语法有哪些异同?

Java和C#是两种流行的面向对象编程语言&#xff0c;它们有许多相似之处&#xff0c;因为它们都受到C和面向对象编程的影响。但它们也有一些语法上的异同&#xff0c;让我们来看看它们的一些主要异同点&#xff1a; 相同点&#xff1a; 1、面向对象编程&#xff1a;Java和C#都…

stable diffusion windows本地搭建的坑

刚刚2小时前&#xff0c;我搭好了&#xff0c;欣喜若狂&#xff0c;开放端口&#xff0c;同事也尝试了。我的配置 16G内存&#xff0c;AMD卡&#xff0c;有gpu但是没有用。这里不说具体步骤&#xff0c;只说坑点。 首先就是安装gfpgan、clip、openclip问题&#xff0c;我参考…

MySQL的MVCC是否解决幻读

MySQL的MVCC是否解决幻读 MySQL事务隔离级别 ✓ 读未提交&#xff08;Read Uncommitted&#xff09;&#xff1a;最低的隔离级别&#xff0c;会读取到其他事务还未提交的内容&#xff0c;存在脏读。 ✓ 读已提交&#xff08;Read Committed&#xff09;&#xff1a;读取到的内容…

Linux/ubuntu 如何使用 SCP 和 SFTP 安全传输文件

本文章向大家介绍Linux如何使用 SCP 和 SFTP 安全传输文件&#xff0c;主要内容包括使用 SCP 复制文件、使用 SFTP 复制文件、总结、基本概念、基础应用、原理机制和需要注意的事项等&#xff0c;并结合实例形式分析了其使用技巧&#xff0c;希望通过本文能帮助到大家理解应用这…

ChatGPT在音乐创作和生成中的应用如何?

ChatGPT在音乐创作和生成领域的应用非常有趣且多样化。虽然ChatGPT是一种自然语言处理模型&#xff0c;它并不是专门为音乐生成设计的&#xff0c;但它具有创造性和想象力&#xff0c;可以在一定程度上用于音乐创作。在音乐生成领域&#xff0c;有许多方法和技术可以将自然语言…

Kind | Kubernetes in Docker 把k8s装进docker!

有点像杰克船长的黑珍珠 目录 零、说明 一、安装 安装 Docker 安装 kubectl 安装 kind 二、创建/切换/删除集群 创建 切换 删除 将镜像加载到 kind 群集中 零、说明 官网&#xff1a;kind Kind&#xff1a; Kubernetes in Docker 的简称。kind 是一个使用 Docker 容…

用C语言写单片机驱动步进电机正反转角度程序

下面是一个简单的例子实现步进电机的正反转角度控制&#xff1a; c #include <reg51.h> #define MOTOR_PORT P1 // 步进电机的控制端口 // 定义正转和反转的步进电机序列 unsigned char forward_seq[4] {0x01, 0x02, 0x04, 0x08}; unsigned char backward_seq[4] …

CentOS5678 repo源 地址 阿里云开源镜像站

CentOS5678 repo 地址 阿里云开源镜像站 https://mirrors.aliyun.com/repo/ CentOS-5.repo https://mirrors.aliyun.com/repo/Centos-5.repo [base] nameCentOS-$releasever - Base - mirrors.aliyun.com failovermethodpriority baseurlhttp://mirrors.aliyun.com/centos/$r…

数据仓库建设-数仓分层

数据仓库能够帮助企业做出更好的决策&#xff0c;提高业务效率和效益&#xff1b;在数据仓库建设时&#xff0c;绕不开的话题就是数仓分层。 一、数据分层的好处 1. 降低数据开发成本 通用的业务逻辑加工好&#xff0c;后续的开发任务可以基于模型快速使用&#xff0c;数据需…

数据库管理-第九十三期 19c OCM之路-第四堂(01)(20230719)

第九十三期 19c OCM之路-第四堂&#xff08;01&#xff09;&#xff08;20230719&#xff09; 距离上一期19c OCM之路已经过去了整整8天了&#xff0c;这中间发生的事情详见第九十二期。本期来到第四堂Performance management性能管理&#xff0c;但是一开始需要把上一堂的一些…

IDEA使用方式

1.翻译 1.Plugins插件&#xff1a;Chinese中文插件 文件F 编辑E 视图V 导航N 代码C 分析Z 重构R 构建B 运行U 工具T VCSS 窗口W 帮助H文件N 新建N 打开 打开最近 关闭项目 设置T 项目结构 文件属性 保存全部S 从磁盘全部重新加载 作废缓存/重启 导出/导入操作 其他设置 导出 打…