栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python自动化测试(一)--uiautomator总结

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python自动化测试(一)--uiautomator总结

1.初始化
  • 单个设备

from uiautomator import device as d
  • 多个设备

from uiautomator import Device
d=Device('014E05DE0F02000E')
2.按键操作
KEYS = ["home","back","left",'right',"up","down","center","menu","search","enter","delete","recent","volume_up", "volume_down", "volume_mute","camera","power"] for key in KEYS:     print key
     d.press(key)
     time.sleep(1)
3.坐标操作
#点屏d.click(2023, 1256)# #长按屏幕# long click (x, y) on screen
 d.long_click(201, 0235)
4.滑动
# swipe from (sx, sy) to (ex, ey)d.swipe(sx, sy, ex, ey)# # swipe from (sx, sy) to (ex, ey) with 10 stepsd.swipe(sx, sy, ex, ey, steps=10)
5.拖动
# drag from (sx, sy) to (ex, ey)d.drag(sx, sy, ex, ey)# drag from (sx, sy) to (ex, ey) with 10 stepsd.drag(sx, sy, ex, ey, steps=10)
6.屏幕
print d.info# 打开屏幕d.screen.on()# 关闭屏幕d.screen.off()# # natural 或者 n 代替# # left 或者 l 代替# # right 或者 r 代替# # upsidedown或 u(不能设定)# #获取orientation(方向),可能是上述中的任意一种orientation = d.orientationprint orientation# #设置定向和冻结旋转。# #说明:"upsidedown"不能用于Android 4.3 以前的版本d.orientation="l"d.orientation="r"d.orientation="n"# 打开通知消息栏,不能用于Android 4.3以前的版本d.notification()# 打开快速设置栏,不能用于Android 4.3以前的版本d.open.quick_settings()# 等待当前窗口空闲d.wait.idle()# 等待直到窗口发生刷新事件d.wait.update()
7.监视器
#当一个选择器找不到匹配时,uiautomator 会运行全部已经注册的观察者#条件匹配时点击目标d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait").click(text="Force Close")#条件匹配时按下按键d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait").press("back", "home")
8.选择器
#选择器支持以下参数# text,textContains,textMatches,textStartsWith# className, classNameMatches# description,descriptionContains,descriptionMatches,descriptionStartsWith# checkable,checked,clickable,longClickable# scrollable,enabled,focusable,focused,selected# packageName, packageNameMatches# resourceId, resourceIdMatches# index, instanced(text="Settings").clear_text()  # clear the text(清除文本信息)d(text="Settings").set_text("My text...")  # set the text(设置文本信息)d(text="Settings").click()
d(text="Settings").long_click()#d(text="Settings").drag.to(x, y, steps=100)d(text="Settings").drag.to(text="Clock", steps=50)
d(text="Settings").swipe.right()
d(text="Settings").swipe.left(steps=10)
d(text="Settings").swipe.up(steps=10)
d(text="Settings").swipe.down()# d(text="Settings").gesture((sx1, sy1), (sx2, sy2)).to((ex1, ey1), (ex2, ey2))# d().gestureM((sx1, sy1), (sx2, sy2),(sx3, sy3)).to((ex1, ey1), (ex2, ey2),(ex3,ey3))d(text="Settings").wait.exists(timeout=3000)
d(text="Settings").exists(timeout=3000)
d(text="Settings").wait.gone(timeout=1000)



作者:Godric_wsw
链接:https://www.jianshu.com/p/874e5ceb72bb


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/220974.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号