栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python+uiautomator2+adb+安卓模拟器

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python+uiautomator2+adb+安卓模拟器

python python安装
  1. 安装python3.7.4 下载地址
  2. 配置环境变量
adb adb安装
  1. 下载安装adb 下载地址
  2. adb.exe 加入Path环境变量
  3. 查看版本,检测是否安装成功
D:workpyqt_5.12.1>adb version
Android Debug Bridge version 1.0.41
Version 33.0.1-8253317
Installed as D:workplatform-toolsadb.exe
adb常用指令
adb devices # 查看当前设备
adb shell pm list packages # 查看手机里面所有包名
adb shell pm list packages -3 # 查看手机里面所有第三方包名
adb shell dumpsys activity activities  # 该命令的功能是获取当前正在被操作的app的activity相关信息
adb shell pm clear com.ablesky.ui.activity # 清除缓存数据

# 启动程序 
# 格式:常规命令 + 包名/activity
# 注意:appActivity返回值本来是com.jingdong.app.mall/.main.MainActivity,需要去掉中间的反斜线!
adb shell am start -n com.jingdong.app.mall/com.jingdong.app.mall.MainFrameActivity 

adb shell pm clear com.jingdong.app.mall # 关闭程序并且清除所有数据,相当于重新安装
adb shell am force-stop com.jingdong.app.mall # 停止运行程序
adb shell "ps | grep com.jingdong.app.mall" # 查看程序进程,判断是否运行
adb shell /system/bin/screencap -p /sdcard/xx.png # 截频并保存文件在手机上为xx.Png
adb pull /sdcard/xx.png D:/xx.png # 将手机xx.png文件保存到D盘文件下
adb push D:/xx.text /adcard/xx.text # 将电脑文件导入手机
adb shell screenrecord /sdcard/demo.mp4 # 录制视频

adb shell input text 123  # 输入内容

adb shell input keyevent 4 # 按键操作
# 4 返回操作
# 1 菜单
# 3 主页
# 21 光标左移
# 22 光标右移
# 67 删除
# 61 tab

adb shell input tap 282 923 # 点击某个坐标
adb shell input swipe 300 1000 300 500 # 下滑500px
adb shell input swipe 288 929 288 929 1000 # 长按1000ms
uiautomator2 uiautomator2安装
  1. 安装uiautomator2
 # 用于控制手机 核心包
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --pre -U uiautomator2 
pip install pillow  # 这个包用于截图,有需要可以装
  1. 安装atx,用于控制手机app
python -m uiautomator2 init # 手机端安装ATX
uiautomator2常用方法

https://blog.csdn.net/adorable_/article/details/121998945

weditor
# 可能会安装失败
pip install -i https://pypi.douban.com/simple weditor # 豆瓣安装
pip install --pre -U weditor

# 上面如果安装失败的话 直接安装指定版本 0.6.4 / 0.6.3
pip install --upgrade weditor==0.6.4

# 启动 weditor
python -m weditor

# 创建快捷方式
python -m weditor –shortcut

夜神模拟器 下载安装

下载地址亲测可用

adb版本不一致问题
  1. 安装完毕以后,设置分辨率等参数

  2. 打开开发者模式,打开设置 滑到最下面 疯狂点击版本号

  3. 开启usb调试模式,开启指针位置,方便查看坐标

  4. 把adb安装目录下的 adb.exe 重命名,放入夜神模拟器bin目录替换文件(替换之前先备份一下)。

uiautomatorviewer.bat 无法连接解决办法 :https://www.jianshu.com/p/c8581a70d1bc

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/918682.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号