主机使用python脚本对软件进行测试时,需要在主机安装对应的python模块:
1、安装uiautomator模块(ubuntu)
sudo apt-get install python-pip
pip install uiautomator
r如果安装失败
pip install uiautomator -i https://pypi.doubanio.com/simple
2、运行对应的脚本
d(resourceId="com.XXX.XXX.accountcenter:id/cropcircle_no") --为对应app报名,已经对应控件的id 在相应的xml文件中有描述。其他的可以看uiautimator的更详细的介绍
# coding=utf-8 from uiautomator import device as d import time import sys def getTimeStr(): tmMil = time.time() mil_str = '%03d' % int(tmMil % 1 * 1000) return time.strftime('%Y-%m-%d %H:%M:%S.', time.localtime(tmMil)) + mil_str i = 0 btnRet = d(resourceId="com.XXX.XXX.accountcenter:id/cropcircle_no") btbClick = d(resourceId="com.android.camera2:id/camera_app_root") while True: try: i += 1 # print " " * 5 + getTimeStr() if btbClick.exists: d.click(1890, 770) d.click(1890, 770) print(" " * 5 + 'btbClick.exists ' + getTimeStr()) # time.sleep(0.2) if btnRet.exists: btnRet.click() print(" " * 5 + 'btnRet.exists ' + getTimeStr()) # time.sleep(0.2) except Exception as e: print("except:" + repr(e)) pass print(getTimeStr() + " times:" + str(i))
注:坐标可以打开坐标定位选项,开发者选项中有,读取参数填入即可!