首页 > 编程语言 >Python+uiautomator2写安卓手机脚本前期准备

Python+uiautomator2写安卓手机脚本前期准备

时间:2023-02-21 14:35:51浏览次数:33  
标签:13 uiautomator Python 34 apk init 写安卓 uiautomator2 210304

1.安装adb

网上找一个或者FQ后官网下,然后配置环境变量即可

C:\Users\lenovo>adb version
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as D:\work\auto\adb\adb.exe

2.安装python-uiautomator2包

pip install uiautomator2

3.连接手机

3.1 用模拟器模拟手机直接启动即可

3.2 连接自己手机需要通过数据线初始化

# 手机开发调试开启,下面命令会自动安装服务到手机
python -m uiautomator2 init
复制代码
C:\Users\lenovo>python -m uiautomator2 init
[I 210304 13:34:43 init:155] uiautomator2 version: 2.13.0
[I 210304 13:34:43 init:352] Install minicap, minitouch
[D 210304 13:34:43 init:62] Download https://tool.appetizer.io/openatx/stf-binaries/raw/0.2.2/node_modules/minitouch-prebuilt-beta/prebuilt/x86/bin/minitouch
minitouch |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 33.6 KB/33.6 KB
[?25h[D 210304 13:34:43 init:232] Push to /data/local/tmp/minitouch:0755
[I 210304 13:34:43 init:356] abi:x86 seems to be android emulator, skip install minicap
[D 210304 13:34:43 init:250] apk-debug package-info: None
[D 210304 13:34:43 init:251] apk-debug-test package-info: None
[I 210304 13:34:43 init:367] Install com.github.uiautomator, com.github.uiautomator.test 2.3.1
[D 210304 13:34:43 init:162] Shell: ('pm', 'uninstall', 'com.github.uiautomator')
[D 210304 13:34:44 init:162] Shell: ('pm', 'uninstall', 'com.github.uiautomator.test')
[D 210304 13:34:45 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.1/app-uiautomator.apk
app-uiautomator.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 2.1 MB/2.1 MB
[?25h[D 210304 13:34:49 init:232] Push to /data/local/tmp/app-uiautomator.apk:0644
[D 210304 13:34:49 init:162] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator.apk')
[I 210304 13:34:51 init:332] - app-uiautomator.apk installed
[D 210304 13:34:51 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.1/app-uiautomator-test.apk
app-uiautomator-test.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 1.2 MB/1.2 MB
[?25h[D 210304 13:34:54 init:232] Push to /data/local/tmp/app-uiautomator-test.apk:0644
[D 210304 13:34:54 init:162] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator-test.apk')
[I 210304 13:34:55 init:332] - app-uiautomator-test.apk installed
[I 210304 13:34:55 init:340] Install atx-agent 0.9.5
[D 210304 13:34:55 init:62] Download https://tool.appetizer.io/openatx/atx-agent/releases/download/0.9.5/atx-agent_0.9.5_linux_386.tar.gz
atx-agent_0.9.5_linux_386.tar.gz |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 4.2 MB/4.2 MB
[?25h[D 210304 13:35:07 init:232] Push to /data/local/tmp/atx-agent:0755
[D 210304 13:35:08 init:162] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[D 210304 13:35:08 init:162] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d')
[D 210304 13:35:08 init:162] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d')
[I 210304 13:35:08 init:377] Check atx-agent version
[D 210304 13:35:08 init:390] Forward: local:tcp:64449 -> remote:tcp:7912
[D 210304 13:35:09 init:393] atx-agent version 0.9.5
Successfully init AdbDevice(serial=127.0.0.1:62028)
复制代码

4.代码确认

import uiautomator2 as ut
d=ut.connect('127.0.0.1:62028')
print(d.device_info)

5.调试

复制代码
#手机打开应用后,通过这个命令可以只是应用名称
C:\Users\lenovo>uiautomator2 current
{
    "package": "com.eg.android.AlipayGphone",
    "activity": "com.eg.android.AlipayGphone.AlipayLogin"
}
#自动打开应用
d.app_start("com.eg.android.AlipayGphone")
复制代码
https://github.com/openatx/uiautomator2/blob/master/QUICK_REFERENCE.md

标签:13,uiautomator,Python,34,apk,init,写安卓,uiautomator2,210304
From: https://www.cnblogs.com/zyf531/p/17140916.html

相关文章

  • 基于UIAutomation+Python+Unittest+Beautifulreport的WindowsGUI自动化测试框架common
    1框架工具说明工具说明使用Unittest框架开源自动化测试框架,直接使用批量或指定用例运行Unittest框架可支持此功能log日志使用Python的logging库即可......
  • Python列表与元组
    1.列表的格式列表也是一个容器是可变数据类型[数据1,数据2,数据3,数据4,......]列表可以存储多个不同类型的数据2.列表基础操作列表是一个可变数据类型,所执行的操......
  • #Python 缺失值的检测与处理,检测部分
    Python 缺失值的检测与处理,分两部分笔记,第一部分是检测缺失值部分        ......
  • python+playwright 学习-3.页面操作Action
    前言Playwright可以与HTML输入元素交互,例如文本输入、复选框、单选按钮、选择选项、鼠标单击、键入字符、键和快捷方式以及上传文件和焦点元素。fill()输入文字使用......
  • Python 学习记录
    前言Python3.5安装步骤Python官网Pycharm第一个程序.pyprint("hellopython")基本语法type(a)=数据类型整数(在线进制转换)定义a=12Python可以......
  • Excel文件 利用MySQL/Python 实现自动处理数据的功能
    目录问题描述:解决方案:一、SQL查询二、SQL、python处理三、python处理四、优化python处理1.手动执行代码2.开机自动执行代码对比四种方案:总结:问题描述:在没有服务器存储数......
  • python+playwright 学习-2.Selector 选择器定位元素
    前言Selector选择器,也就是通常说的元素定位了,页面上点点点的操作,都是基于元素定位,所以这块是重点需要学的核心内容。Selector选择器说到元素定位,大家肯定会首先想到s......
  • python super()
    还未看:​​https://www.runoob.com/w3cnote/python-super-detail-intro.html​​参考文章:​​https://www.runoob.com/python/python-func-super.html​​......
  • 02Python输入输出
    输入输出print()函数sep=''数据之间一空格分割,默认是空格end='\n'在打印后会额外的加一个数据,默认是换行符print("hello","world") print("hello","worl......
  • python 递归创建文件夹
    os.makedirs(name,mode=0o777,exist_ok=False)作用用来创建多层目录(单层请用os.mkdir)参数说明 name:你想创建的目录名mode:要为目录设置的权限数字模式,默认的模式为......