首页 > 其他 > 详细

uiautomation2进阶

时间:2019-02-28 18:44:36      阅读:694      评论:0      收藏:0      [点我收藏+]

点击控件的具体位置

d(text="Settings").click(offset=(0.5, 0.5))   点击控件的中间位置

d(text="Settings").click(offset=(0, 0))  点击控件的左上方

d(text="Settings").click(offset=(1, 1)) 点击控件的右下方

拖动控件

d(text="Settings").swipe("right")
d(text="Settings").swipe("left", steps=10)
d(text="Settings").swipe("up", steps=20)
d(text="Settings").swipe("down", steps=20)
# 1 steps is about 5ms, so 20 steps is about 0.1s

特定UI对象上的两点手势从边缘到中心向外,从中心到边缘


# 从边缘到中心
d(text="Settings").pinch_in(percent=100, steps=10)
# 从中心到边缘
d(text="Settings").pinch_out()
等待特定的界面出现或者消失
# 等待UI出现
d(text="Settings").wait(timeout=3.0) # return bool
# 等待UI消失
d(text="Settings").wait_gone(timeout=1.0)
对特定的UI对象执行Fling(可滚动)默认时间20s
# 向前(默认) 
d(scrollable=True).fling()
# 掷球前水平
d(scrollable=True).fling.horiz.forward()
# 垂直向后投掷
d(scrollable=True).fling.vert.backward()
# 水平开始
d(scrollable=True).fling.horiz.toBeginning(max_swipes=1000)
# 垂直抛向末端
d(scrollable=True).fling.toEnd()

对特定的UI对象执行滚动

水平或垂直

向前或向后,或开始或结束,

# 垂直向前滚动(默认)
d(scrollable=True).scroll(steps=10)
# 水平向前滚动
d(scrollable=True).scroll.horiz.forward(steps=100)
# 垂直向后滚动
d(scrollable=True).scroll.vert.backward()
# 水平
d(scrollable=True).scroll.horiz.toBeginning(steps=100, max_swipes=1000)
# 垂直滚动到结尾
d(scrollable=True).scroll.toEnd()
# 垂直向前滚动,直到出现特定的UI对象
d(scrollable=True).scroll.to(text="Security")

当选择器找不到匹配项时,uiautomator2将运行所有注册的观察程序,条件匹配时单击目标
d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait")                              .click(text="Force Close")
#使用不带参数的click
d.watcher("ALERT").when(text="OK").click()
#same as
d.watcher("ALERT").when(text="OK").click(text="OK")
#当条件为真时按键
d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait")                              .press("back", "home")
#检查指定的观察程序是否触发一个观察者被触发,这意味着观察者已经运行并且其所有条件都匹配。
# true in case of the specified watcher triggered, else false

d.watcher("watcher_name").triggered #展示所有watch
d.watchers
#通常可以用来自动点击权限确认框,或者自动安装
d.watcher("OK").when(text="OK").click(text="OK")
# enable auto trigger watchers
d.watchers.watched = True

# disable auto trigger watchers
d.watchers.watched = False

# get current trigger watchers status
assert d.watchers.watched == False


 


 

 
 
 

uiautomation2进阶

原文:https://www.cnblogs.com/zhujunsheng/p/10452073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!