https://github.com/openatx/uiautomator2
第一步:安装 weditor
https://github.com/openatx/weditor
下载 weditor 库,安装方法 :pip install -U weditor
命令窗口 执行 weditor --help
weditor成功.png
创建快捷方式:weditor --shortcut,可以在桌面看到,运行页面,进行元素定位,脚本录制。
快捷方式.png
运行效果.png
第二步:安装 uiautomator2
命令如下:
git clone https://github.com/openatx/uiautomator2
pip install -e uiautomator2
由于我想通过adb命令安装 apk,所以需要安装 android-sdk 。下次介绍
第三步:命令 adb install path
class appInstall:
def __init__(self, path):
self.path = path
def auto_install(self):
# 获取path路径下的所有文件
files = os.listdir(self.path)
for file in files:
if file[len(file) - 3:len(file)] == "apk":
print(self.path)
print(file)
string = 'adb install %s\\\\"%s\"' % (self.path, file)
# string = 'adb install %s\\%s' % (self.path, file)
print(string)
os.popen(string)
print("%s 正在安装中...." %string )
time.sleep(5)
else:
time.sleep(10)
print("finished")
# time.sleep(1000)
return 200
第四步:启动 运行apk
序列码.png
class applogin:
def __init__(self,user, password):
self.user= user
self.password = password
def auto_login(self):
user= self.user
password=self.password
d = u2.connect('序列码') # alias for u2.connect_usb('123456789F')
d.screen_on()
d.press("home")
d(resourceId="com.miui.home:id/icon_icon", description="apk名称").click()
time.sleep(3)
d.press("back")
d(resourceId="com.XXX").clear_text
d(resourceId="com.XXX").send_keys(user)
d.press("back")
d(resourceId="com.XXX").clear_text
time.sleep(1)
d(resourceId="com.XXX").send_keys(password)
d.press("back")
d(resourceId="com.XXX").click()
time.sleep(3)
image.png
通过执行脚本 完成安装,已经登录操作。
待掌握方向:1.android 前端页面元素的定位;2.模拟用户行为的操作;3.用户信息的保存和清楚;4.登录时 拼图,验证码等 方式;5.ui自动化测试 代码覆盖率;6.报告。 万里长征完成了第一步