uiautomator2学习【一】

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了uiautomator2学习【一】脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一、uiAutomator2简介

uiautomator2 是一个可以使用Python对AndROId设备进行UI自动化的库。

其底层基于GOOGLE uiautomator,Google提供的uiautomator库可以获取屏幕上任意一个APP的任意一个控件属性,并对其进行任意操作。

二、环境准备

  • pip install uiautomator2

Windows下使用pip安装包的时候出现如下问题:

“WARNING: pip is configured wITh locations that require TLS/SSL, however the ssl module in Python is not available”

解决办法:

在环境变量Path中加入anaconda3的如下路径:

D:PRogramDataAnaconda3condabinD:ProgramDataAnaconda3ScriptsD:ProgramDataAnaconda3LibrarybinD:ProgramDataAnaconda3

  • python

Window10系统在命令行中输入python会跳转到商店问题解决方法:

where python命令出现两个地址:

uiautomator2学习【一】

一个是Python的,一个是应用商店的地址,在Win10菜单搜索【管理应用执行别名】关闭最下面的两个按钮:

uiautomator2学习【一】

再进入cmd输入where python 就只有一个地址了:

 

uiautomator2学习【一】

 需要将设备调至开发者模式

【系统应用】-【设置】-【关于平板脑】-【版本号】连续单机5次。

  • ADB下载

uiautomator2学习【一】

adb devices

查看连接设备序列号及状态:

 

uiautomator2学习【一】

adb shell wm size

查看屏幕分辨率:

uiautomator2学习【一】

adb get-state

查看当前连接设备的状态:

uiautomator2学习【一】

 adb connect ip:端口号

连接本机的模拟器只需要修改所安装的模拟器端口,雷电模拟器端口号是5555:

uiautomator2学习【一】

截图并拉取至指定文件夹:

通过adb命令截图 :adb shell screencap -p /sdcard/01.png

拉取到电脑:adb pull <设备里的文件路径> [电脑上的目录]

uiautomator2学习【一】

使用adb install 【apk路径】安装程序

uiautomator2学习【一】

使用adb shell input keyevent 25:减小音量

使用adb shell input keyevent 24:增加音量

使用adb shell input keyevent 164:静音

uiautomator2学习【一】

多媒体暂停/播放/下一首/上一首:

adb shell input keyevent KEYCODE_MEDIA_STOP

adb shell input keyevent KEYCODE_MEDIA_play

adb shell input keyevent KEYCODE_MEDIA_NEXT

adb shell input keyevent KEYCODE_MEDIA_PrevIOUS

adb shell input keyevent 3:回到Home

adb shell input keyevent 4:返回键

KeyCode大全:https://blog.csdn.net/h_bpdwn/article/details/91425599

 

 

 

 

脚本宝典总结

以上是脚本宝典为你收集整理的uiautomator2学习【一】全部内容,希望文章能够帮你解决uiautomator2学习【一】所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。