Python之手机APP自动化测试学习笔记

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/zym326975/article/details/102588227

Android环境搭建

Android Platform Tools https://developer.android.com/studio/releases/platform-tools.html,解压,并加包含adb.exe的目录加入到系统的PATH中。

adb devices

UIAutomator安装

pip install --pre -U uiautomator2

手机设备环境搭建

手机链接pc,输入adb命令adb devices发现设备后表明设备已连接成功
pc终端输入命令,以安装atx-agent至手机

python -m uiautomator2 init

手机连接方式

  • 使用wifi连接
import uiautomator2 as u2  //依赖包
d = u2.connect('10.242.23.215')
  • 使用USB连接

手机的序列号可以通过adb devices获取到,假设序列号是123456f,连接代码为

import uiautomator2 as u2
d = u2.connect_usb('xxxxx')

控件识别

使用weditor进行元素识别

pip  install --pre weditor

UI自动化编写

具体参考git:
https://github.com/openatx/uiautomator2

操作控件

# click
d(text="Settings").click()

# long click
d(text="Settings").long_click()

# 等待元素的出现
d(text="Settings").wait(timeout=10.0)

中文字符输入

d(text="Settings").set_text("你好")

参考文献

https://www.jianshu.com/p/e5ed2ddb3f27

猜你喜欢

转载自blog.csdn.net/zym326975/article/details/102588227