雷电模拟器python编程接口_【Python】雷电模拟器说明[附代码]
[Python] 纯文本查看 复制代码class Dnconsole:
# 请根据自己电脑配置
console = 'D:\\Changzhi\\dnplayer2\\dnconsole.exe '
ld = 'D:\\Changzhi\\dnplayer2\\ld.exe '
share_path = 'F:/share/Pictures'
#获取模拟器列表
@staticmethod
def get_list():
cmd = os.popen(Dnconsole.console + 'list2')
text = cmd.read()
cmd.close()
info = text.split('\n')
result = list()
for line in info:
if len(line) > 1:
dnplayer = line.split(',')
result.append(DnPlayer(dnplayer))
return result
#获取正在运行的模拟器列表
@staticmethod
def list_running() -> list:
result = list()
all = Dnconsole.get_list()
for dn in all:
if dn.is_running() is True:
result.append(dn)
return result
#检测指定序号的模拟器是否正在运行
@staticmethod
def is_running(index: int) -> bool:
all = Dnconsole.get_list()
if index >= len(all):
raise IndexError('%d is not exist' % index)
return all[index].is_running()
#执行shell命令
@staticmethod
def dnld(index: int, command: str, silence: bool = True):
cmd = Dnconsole.ld + '-s %d %s' % (index, command)
if silence:
os.system(cmd)
return ''
process = os.popen(cmd)
result = process.read()
process.close()
return result
#执行adb命令,不建议使用,容易失控
@staticmethod
def adb(index: int, command: str, silence: bool = False) -> str:
cmd = Dnconsole.console + 'adb --index %d --command "%s"' % (index, command)
if silence:
os.system(cmd)
return ''
process = os.popen(cmd)
result = process.read()
process.close()
return result
#安装apk 指定模拟器必须已经启动
@staticmethod
def install(index: int, path: str):
shutil.copy(path, Dnconsole.share_path + str(index) + '/update.apk')
time.sleep(1)
Dnconsole.dnld(index, 'pm install /sdcard/Pictures/update.apk')
#卸载apk 指定模拟器必须已经启动
@staticmethod
def uninstall(index: int, package: str):
cmd = Dnconsole.console + 'uninstallapp --index %d --packagename %s' % (index, package)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#启动App 指定模拟器必须已经启动
@staticmethod
def invokeapp(index: int, package: str):
cmd = Dnconsole.console + 'runapp --index %d --packagename %s' % (index, package)
process = os.popen(cmd)
result = process.read()
process.close()
print(result)
return result
#停止App 指定模拟器必须已经启动
@staticmethod
def stopapp(index: int, package: str):
cmd = Dnconsole.console + 'killapp --index %d --packagename %s' % (index, package)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#输入文字
@staticmethod
def input_text(index: int, text: str):
cmd = Dnconsole.console + 'action --index %d --key call.input --value %s' % (index, text)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#获取安装包列表
@staticmethod
def get_package_list(index: int) -> list:
result = list()
text = Dnconsole.dnld(index, 'pm list packages')
info = text.split('\n')
for i in info:
if len(i) > 1:
result.append(i[8:])
return result
#检测是否安装指定的应用
@staticmethod
def has_install(index: int, package: str):
if Dnconsole.is_running(index) is False:
return False
return package in Dnconsole.get_package_list(index)
#启动模拟器
@staticmethod
def launch(index: int):
cmd = Dnconsole.console + 'launch --index ' + str(index)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#关闭模拟器
@staticmethod
def quit(index: int):
cmd = Dnconsole.console + 'quit --index ' + str(index)
process = os.popen(cmd)
result = process.read()
process.close()
return result
# 设置屏幕分辨率为1080×1920 下次启动时生效
@staticmethod
def set_screen_size(index: int):
cmd = Dnconsole.console + 'modify --index %d --resolution 1080,1920,480' % index
process = os.popen(cmd)
result = process.read()
process.close()
return result
#点击或者长按某点
@staticmethod
def touch(index: int, x: int, y: int, delay: int = 0):
if delay == 0:
Dnconsole.dnld(index, 'input tap %d %d' % (x, y))
else:
Dnconsole.dnld(index, 'input touch %d %d %d' % (x, y, delay))
#滑动
@staticmethod
def swipe(index, coordinate_leftup: tuple, coordinate_rightdown: tuple, delay: int = 0):
x0 = coordinate_leftup[0]
y0 = coordinate_leftup[1]
x1 = coordinate_rightdown[0]
y1 = coordinate_rightdown[1]
if delay == 0:
Dnconsole.dnld(index, 'input swipe %d %d %d %d' % (x0, y0, x1, y1))
else:
Dnconsole.dnld(index, 'input swipe %d %d %d %d %d' % (x0, y0, x1, y1, delay))
#复制模拟器,被复制的模拟器不能启动
@staticmethod
def copy(name: str, index: int = 0):
cmd = Dnconsole.console + 'copy --name %s --from %d' % (name, index)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#添加模拟器
@staticmethod
def add(name: str):
cmd = Dnconsole.console + 'add --name %s' % name
process = os.popen(cmd)
result = process.read()
process.close()
return result
#设置自动旋转
@staticmethod
def auto_rate(index: int, auto_rate: bool = False):
rate = 1 if auto_rate else 0
cmd = Dnconsole.console + 'modify --index %d --autorotate %d' % (index, rate)
process = os.popen(cmd)
result = process.read()
process.close()
return result
#改变设备信息 imei imsi simserial androidid mac值
@staticmethod
def change_device_data(index: int):
# 改变设备信息
cmd = Dnconsole.console + 'modify --index %d --imei auto --imsi auto --simserial auto --androidid auto --mac auto' % index
process = os.popen(cmd)
result = process.read()
process.close()
return result
#改变CPU数量
@staticmethod
def change_cpu_count(index: int, number: int):
# 修改cpu数量
cmd = Dnconsole.console + 'modify --index %d --cpu %d' % (index, number)
process = os.popen(cmd)
result = process.read()
process.close()
return result
@staticmethod
def get_cur_activity_xml(index: int):
# 获取当前activity的xml信息
Dnconsole.dnld(index, 'uiautomator dump /sdcard/Pictures/activity.xml')
time.sleep(1)
f = open(Dnconsole.share_path + '/activity.xml' , 'r', encoding='utf-8')
result = f.read()
f.close()
return result
@staticmethod
def get_user_info(index: int) -> UserInfo:
xml = Dnconsole.get_cur_activity_xml(index)
usr = UserInfo(xml)
if 'id' not in usr.info:
return UserInfo()
return usr
#获取当前activity名称
@staticmethod
def get_activity_name(index: int):
text = Dnconsole.dnld(index, '"dumpsys activity top | grep ACTIVITY"', False)
text = text.split(' ')
for i, s in enumerate(text):
if len(s) == 0:
continue
if s == 'ACTIVITY':
return text[i + 1]
return ''
#等待某个activity出现
@staticmethod
def wait_activity(index: int, activity: str, timeout: int) -> bool:
for i in range(timeout):
if Dnconsole.get_activity_name(index) == activity:
return True
time.sleep(1)
return False
#找图
@staticmethod
def find_pic(screen: str, template: str, threshold: float):
try:
scr = cv.imread(screen)
tp = cv.imread(template)
result = cv.matchTemplate(scr, tp, cv.TM_SQDIFF_NORMED)
except cv.error:
print('文件错误:', screen, template)
time.sleep(1)
try:
scr = cv.imread(screen)
tp = cv.imread(template)
result = cv.matchTemplate(scr, tp, cv.TM_SQDIFF_NORMED)
except cv.error:
return False, None
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if min_val > threshold:
print(template, min_val, max_val, min_loc, max_loc)
return False, None
print(template, min_val, min_loc)
return True, min_loc
#等待某个图片出现
@staticmethod
def wait_picture(index: int, timeout: int, template: str) -> bool:
count = 0
while count < timeout:
Dnconsole.dnld(index, 'screencap -p /sdcard/Pictures/apk_scr.png')
time.sleep(2)
ret, loc = Dnconsole.find_pic(Dnconsole.share_path + '/apk_scr.png' , template, 0.001)
if ret is False:
print(loc)
time.sleep(2)
count += 2
continue
print(loc)
return True
return False
# 在当前屏幕查看模板列表是否存在,是返回存在的模板,如果多个存在,返回找到的第一个模板
@staticmethod
def check_picture(index: int, templates: list):
Dnconsole.dnld(index, 'screencap -p /sdcard/Pictures/apk_scr.png')
time.sleep(1)
for i, t in enumerate(templates):
ret, loc = Dnconsole.find_pic(Dnconsole.share_path + '/apk_scr.png' , t, 0.001)
if ret is True:
return i, loc
return -1, None
雷电模拟器python编程接口_【Python】雷电模拟器说明[附代码]相关推荐
- 雷电模拟器python编程接口_【Python实践】_接口模拟器
真正的稳定,是自己不断成长,不断寻找新的空间.与其要稳定,不如开始拥抱这个变化的时代,让自己准备好. python实践 [写在前面]: 周一的时候看mock,就萌发了搭建个mock server的冲动 ...
- python交互式程序设计导论答案第五周_学堂在线_计算机科学与Python编程导论_章节测试答案...
学堂在线_计算机科学与Python编程导论_章节测试答案 更多相关问题 素描的三种表现形式是:(). 运行下列程序:Private Sub form_Click()For i = 1 To 2x = ...
- 计算机编程导论python程序设计答案-学堂在线_计算机科学与Python编程导论_作业课后答案...
学堂在线_计算机科学与Python编程导论_作业课后答案 答案: 更多相关问题 近代中国完全沦为半殖民地半封建社会的标志是:A.<马关条约>B.<辛丑条约>C.<凡尔赛和 ...
- python编程基础_月隐学python第2课
python编程基础_月隐学python第2课 学习目标 掌握变量的输入和输出 掌握数据类型的基本概念 掌握算数运算 1.变量的输入和输出 1.1 变量输入 使用input输入 input用于输入数据 ...
- 计算机编程导论python程序设计答案-学堂云_计算机科学与Python编程导论_作业课后答案...
学堂云_计算机科学与Python编程导论_作业课后答案 答案: 更多相关问题 保本基金参与股指期货交易,应当根据风险管理的原则,以套期保值为目的.() 基金经理主要依据股票投资价值报告来决定实际的投资 ...
- python编程方式_自学python编程的方法路线
怎么自学python编程 如何自学Python编程?一堆的Python教程却感觉无从下手呢?我想这应该是很多Python初学者正在纠结的问题. 今天想要分享给大家的是如何自学Python编程,学习这件 ...
- 青少年python编程入门书籍_新书推荐 | 《青少年Python编程入门——图解Python》
原标题:新书推荐 | <青少年Python编程入门--图解Python> 随着信息时代的到来,在编程教育中进行计算思维培养正在成为信息技术教育关注的重点.<普通高中信息技术课程标准( ...
- python编程入门视频教程-PYTHON编程从0到1(视频教学版)
本书以Python语言构建了程序设计基础课程的教学体系.本书在对程序设计核心方法的探讨上较其他Python书籍更为全面和深入.通过对本书内容的学习,读者将全面地掌握用Python进行程序设计的基本能力 ...
- arcgis python编程案例-ArcGIS Python编程案例-电子资料链接
ArcGIS Python编程案例(1)-Python语言基础 https://www.jianshu.com/p/dd90816d019b ArcGIS Python编程案例(2)-使用ArcPy编 ...
最新文章
- Dipforge 3.0 a3 发布,基于 Web 的集成开发环境
- [leetcode] 103.二叉树的锯齿形遍历
- 原生js cookie的使用实例setCookie()、getCookie()方法
- 蓝桥杯 算法训练 区间k大数查询
- Windows 10 PC 安装 Docker CE
- 孙鑫VC学习笔记:第九讲 界面修改,工具栏,状态栏,启动画面的制作
- 51单片机蜂鸣器实现歌曲《起风了》代码
- 微信小程序毕业设计 基于微信景区景点旅游攻略小程序系统开题报告
- 人类究竟需要什么样的微积分原理
- ping端口的方法 - win下
- py的征途2之简例分享
- 计算机获取信息的过程是,“获取信息的过程与方法”的教学案例
- cf显示网络连接服务器失败怎么办,cf连接服务器失败怎么办
- 网络工程师_记录的一些真题_2017上半年上午
- MySQL业务账号需要哪些权限_MySQL 日常运维业务账号权限的控制
- 5GC 网元AMF、SMF、UPF、PCF、UDM等介绍
- 计算机安全概述ppt,计算机信息安全概述.ppt
- [数据分析] 逻辑树分析方法
- Hyperledger Fabric2中文文档-修改通道配置
- Matlab中meshgrid的用法简介