主要实现多台手机同时安装app 同时设置app 设置的结果截图与标准图比较,如果不一样,返回false并保存截图

代码如下:

# coding:utf-8
import os
import threading
import time
# from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi
from com.android.monkeyrunner import MonkeyRunner as mr
# from com.android.monkeyrunner.easy import By
# from com.android.monkeyrunner.easy import EasyMonkeyDevice as emd
# 工具类 有两个方法
# getDeviceSerial:读取保存devices,并保存到devices[]
# viewServerisOpen:判断viewserver是否可用
class Tools(object):
def __init__(self, deviceSerial):
self.deviceSerial = deviceSerial
# ************************************************************************
# 判断手机 是否打开viewserver 如果打开 可以使用EasyMonkeyDevice
# ************************************************************************
def viewServerIsOpen(self):
# print(self.deviceSerial)
command = "adb -s "+self.deviceSerial
viewServer = os.system(command + " shell service call window 3")
# viewServer = subprocess.getstatusoutput(
# command + " shell service call window 3")
# print(viewServer)
# if viewServer[0] == 1:#monkeyrunner 不支持该方法
if viewServer == 1:
# print("你的手机已经打开viewServer")
return True
else:
# print("开启ViewServer")
ovs = os.system(command+" shell service call window 1 i32 4939")
# ovs = subprocess.getstatusoutput(
# command+" shell service call window 1 i32 4939")
# print(ovs)
# if ovs[0] == 1:
if ovs == 1:
# print("你的手机已经打开viewServer")
return True
else:
# print("你的手机无法打开viewserver 无法使用EasyMonkeyDevice")
return False
# ************************************************************************
# 获取所有的设备 返回所有设备的数组
# ************************************************************************
@ classmethod
def getdeviceSerial(self):
# print("获取所有的devices,并返回devices[]")
# 创建一个数组用来存放devices
devices = []
# 将所有的devices 写入devices.text
# devicesPath = str(os.getcwd())
devicesPath = "D:/PythonProject/MonkeyRunner"
os.system("adb devices > "+devicesPath+"/a3s/devices.text")
# 读取devices.text
f = open(devicesPath+"/a3s/devices.text", "r")
content = f.readlines()
i = 1 # 因为第一行没有device的信息 所以下标从1开始,而且最后一行空白的所以i要小于len-1
# print(len(content))
while i < len(content)-1:
# 找到空格的位置或者有时识别不出空客 用device
# findNumber = content[i].find(" ")
findNumber = content[i].find("device")-1
# print(findNumber)
# 截取空格之前的字符串保存到devices[]
devices.append(content[i][0:findNumber])
i += 1
# 读取所有的devices
# for device in devices:
# print(device)
return devices
# ************************************************************************
# 设置完成后截图和标准图片对比 如果一致输入all right;
# 如果不一致 输出错误 并保存截图
# ************************************************************************
def compareImages(device, imageNum, deviceNumber):
imagePath = r"D:\PythonProject\MonkeyRunner\a3s\images"
standardImage1 = mr.loadImageFromFile(
imagePath + r"\standard\supersu_1.png")
standardImage2 = mr.loadImageFromFile(
imagePath + r"\standard\supersu_2.png")
standardImage3 = mr.loadImageFromFile(
imagePath + r"\standard\supersu_3.png")
image = device.takeSnapshot().getSubImage((0, 300, 720, 750))
if imageNum == 1:
result = mi.sameAs(
image, standardImage1.getSubImage((0, 300, 720, 750)))
if result:
print("step1 is all right")
else:
imagePath = imagePath+"\\"+deviceNumber
device.takeSnapshot().writeToFile(imagePath+"_supersu_1.png")
print("step1 is wrong!!")
elif imageNum == 2:
result = mi.sameAs(
image, standardImage2.getSubImage((0, 50, 720, 750)))
if result:
print("step2 is all right")
else:
imagePath = imagePath+"\\"+deviceNumber
device.takeSnapshot().writeToFile(imagePath+"_supersu_2.png")
print("step2 is wrong!!")
else:
result = mi.sameAs(
image, standardImage3.getSubImage((0, 50, 720, 750)))
if result:
print("step3 is all right")
else:
imagePath = imagePath+"\\"+deviceNumber
device.takeSnapshot().writeToFile(imagePath+"_supersu_3.png")
print("step3 is wrong!!")
# 方法1:通过monkeydevice的installPackage 安装appp
def installApp(device):
print("begin install app by monkeyrunner")
# 安装jkt
device.installPackage("D:\\JKT\\apks\\JKT_V1.2.24-release.apk")
print("安装jkt--ok")
# 安装weike2.1.16
device.installPackage("D:\\JKT\\apks\\Weike_V2.1.16-release.apk")
print("安装weike--ok")
# 安装test
device.installPackage(
"D:\\JKT\\apks\\Weike_V2.1.10-debug-androidTest.apk")
print("安装test--ok")
# 安装wechat6.6.5
device.installPackage("D:\\JKT\\apks\\Wechat_V6.6.5.apk")
print("wechat--ok")
print("install app end ")
# 设置supersu
def setUpSperSU(device, deviceNumber):
print("***********************supersu begining**************************")
command = "eu.chainfire.supersu/eu.chainfire.supersu.MainActivity-Material"
device.startActivity(component=command)
mr.sleep(3)
# 点击设置
device.touch(600, 210, "DOWN_AND_UP")
mr.sleep(1)
# 点击重新验证
device.touch(500, 900, "DOWN_AND_UP")
mr.sleep(1)
# 点击默认操作
device.touch(200, 1100, "DOWN_AND_UP")
mr.sleep(1)
# 点击默认操作--授权
device.touch(200, 650, "DOWN_AND_UP")
mr.sleep(1)
compareImages(device, 1, deviceNumber)
# 下滑
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
# 点击开机允许所有授权申请
device.touch(500, 900, "DOWN_AND_UP")
mr.sleep(1)
compareImages(device, 2, deviceNumber)
# 下滑
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
device.drag((500, 1000), (500, 400), 2, 10)
mr.sleep(0.1)
# 点击开机允许所有授权申请
device.touch(500, 600, "DOWN_AND_UP")
mr.sleep(1)
compareImages(device, 3, deviceNumber)
print("***********************supersu end**************************")
class myThread(threading.Thread):
def __init__(self, device):
threading.Thread.__init__(self)
self.deviceSerial = device
self.device = mr.waitForConnection(1.0, device)
def run(self):
if __name__ == '__main__':
print(self.deviceSerial)
# 判断能否使用EasyMonkeyDevice
tool = Tools(self.deviceSerial)
if tool.viewServerIsOpen():
# 能使用
print("viewServer is opened!")
# easyDevice = emd(device)
else:
print("Can't open viewServer ")
# print("link device")
# device = mr.waitForConnection(1.0, temp)
os.system("adb -s " + temp +
" shell am force-stop eu.chainfire.supersu")
installApp(self.device)
setUpSperSU(self.device, self.deviceSerial)
if __name__ == '__main__':
try:
# 获取所有的devices[]
devices = Tools.getdeviceSerial()
# 创建线程组
tt = []
# 遍历devices,
for temp in devices:
# print(temp)
t = myThread(temp)
tt.append(t)
for t in tt:
t.start()
time.sleep(5)
for t in tt:
t.join()
except Exception:
print("线程运行失败")

monkeyrunner +python 多台真机 多线程相关推荐

  1. 基于docker搭建zookeeper集群、kafka集群(多台真机之间的集群)

    基于docker搭建zookeeper集群.kafka集群---二(多台真机之间的集群) https://blog.csdn.net/diebiao6526/article/details/10143 ...

  2. UWA Pipeline 2.0 功能详解|私有云真机远程调试

    UWA Pipeline 是一款面向游戏开发团队的本地协作平台,旨在为游戏开发团队搭建专属的DevOps研发交付流水线. 为帮助大家更好了解最新2.0版本中的各项新功能,我们将陆续为大家进行详解. 今 ...

  3. iOS - 真机无线调试

    真机无线调试步骤: 1.连接真机调试数据线,在Xcode工具栏,点击 Window -> Devices and Simulators 点击后显示: 选中Connect via network, ...

  4. app测试模拟器和真机区别

    转载1: 平时测试过程中,经常有组内同学们问,使用模拟器测试完之后,是否可以代替真机的兼容测试了. 先来看看模拟器和真机的直观区别: 多点触摸(比如两个手指放大文本字体大小) 网络通话(没有真实的呼入 ...

  5. 【为什么要用真机】——谈模拟器与真机的差别

    今天语音对话应用调试时要用两台手机,无奈模拟器打开不了app.网上查阅资料,发现我的问题应该是模拟器无法获取语音权限导致的.感觉这篇文章比较全面,分享给大家参考,同时也建议大家尽量用真机测试.转载地址 ...

  6. 简述Android模拟机和真机的区别,谈谈android模拟器和真机的差别

    虽说android模拟器做得很完善几乎跟真机一样,但本人实际开发发现还是有不少不一样的,没有一个真机测试还真难保证自己的应该能够在真机上顺畅跑起来. 列举下我遇到的不同之处: 1.模拟器上安装的apk ...

  7. IDA真机调试环境搭建及原理

    IDA真机调试环境搭建及原理 如果想脱壳,使用IDA调试so文件是不可避免的.工欲善其事必先利其器,本文将详细介绍IDA调试的环境准备以及操作的步骤和原理,尽量做到知其然知其所以然. 手机环境 1) ...

  8. 模拟器真机环境_Appium+python自动化(二)- 环境搭建—下(超详解)

    上一篇android测试开发环境已经准备好, 那么接下来就是appium的环境安装和搭建了. 菲哥和小伙伴们开个玩笑,不要觉得自人品不好,就不会成功那都是骗人的.搭建环境和人品半毛钱关系也没有,搭建环 ...

  9. android ida多线程调试,C/C++知识点之ida动态调试.so 动态加载(必须真机)

    本文主要向大家介绍了C/C++知识点之ida动态调试.so 动态加载(必须真机),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助. 第一步连接安卓手机 查看设备 localhost: ...

最新文章

  1. SqlServer的SSIS导入导出数据时找不到连接错误处理
  2. 使用友盟的社会化组件,发新浪微博的 error:redirect_uri_mismatch的解决方法
  3. 纸牌游戏10点半c语言,python10点半纸牌游戏_【Python】Python编的纸牌游戏
  4. nrf51822-提高nordic ble数据发送速率
  5. LintCode: Single Number II
  6. (*长期更新)软考网络工程师学习笔记——数据链路层与网络层的相关计算题
  7. 前端获取不了rest请求自定义headers的问题
  8. Vue入门指南-05 Vue实例的生命周期(快速上手vue)
  9. 别看微信,微博,头条用户都很多,自媒体作者也很多
  10. 专业RAW图像处理软件Capture One Pro 22
  11. 在数据库中如果组合主键(假设为stuID和stuName)存在则更新,不存在则新增
  12. 中国工业企业数据库stata处理
  13. 5G接入网与基站演进
  14. 35枚不同风格的设计师个人网站欣赏
  15. 2G通信项目-物联网小尺寸模组M26与M6315功耗测试对比分析
  16. 基于GEE洪水发生前后的分析
  17. 通过sql给表添加字段
  18. SOLIDWORKS Simulation攻略丨赫兹接触应力分析
  19. 个人投资课 张潇雨_张潇雨:个人投资课(节选) 如今我们一说到选股大师,最先想到的就是股神巴菲特。但早在80年代,整个投资界最耀眼的明星不止巴菲特一个,还有被称作“对冲... - 雪球...
  20. Oracle数据库习题整理

热门文章

  1. Unity物体围绕中中心旋转加角度
  2. 比赛记录:ICME-2022 安全AI挑战者计划第九期:小样本商标检测挑战赛
  3. 信息系统项目管理师必背核心考点(七十)安全审计功能
  4. 经济学十大原理之二:理性人考虑边际量
  5. 有哪些句子帮你熬过崩溃期的?
  6. 《当程序员的那些狗日日子》(十七)短暂的混乱
  7. 吉大计算机学院大一课表,大学计算机基础(吉林大学)大学计算机基础课程计划及方案.doc...
  8. PHP抖音无水印解析api
  9. 绿色版eclipse
  10. 照相机模型和增强现实的实现