python 常用 uiautomator语法

来源:互联网 发布:域名查询腾讯 编辑:程序博客网 时间:2024/06/15 22:03

原文:http://www.bkjia.com/Pythonjc/1200927.html

1.获取设备信息

语法:d.info

返回值:

{ u'displayRotation': 0,

  u'displaySizeDpY': 640,

  u'displaySizeDpX': 360,

  u'currentPackageName': u'com.android.launcher',

  u'productName': u'takju',

  u'displayWidth': 720,

  u'sdkInt': 18,

  u'displayHeight': 1184,

  u'naturalOrientation': True

}

返回值解释如下:

displayRotation  0 代表竖屏 1 代表横屏

currentPackageName  当前的Activity的Package名字

productName  当前设备名称

displayWidth  当前设备屏幕宽度  当 displayRotation 取值为 1 时,也就是说当前是横屏状态时,displayWidth 取值会和 displayHeight 互换

displayHeight 当前设备屏幕高度  当 displayRotation 取值为 1 时,也就是说当前是横屏状态时,displayHeight 取值会和 displayWidth 互换

sdkInt 当前SDK版本

naturalOrientation 当 displayRotation 取值为 1 时,也就是说当前是横屏状态时,取值为False,为竖屏状态时,取值为:True

2.系统常用操作

点亮或熄灭屏幕(Turn on/off screen)

# Turn on screen

d.screen.on()

# Turn off screen

d.screen.off()

检查屏幕状态,关闭OR点亮?

if d.screen == "on":  # of d.screen != "off"

    # do something in case of screen on

    pass

if d.screen == "off":  # of d.screen != "on"

    # do something in case of screen off

    pass

# home键

d.press.home()

# 返回

d.press.back()

# 返回

d.press("back")

3.与设备交互(单击、长按、滑动(手势密码)、拖拽)

# 单击屏幕坐标点

d.click(x, y)

# 长按屏幕坐标点

d.long_click(x, y)

# 在屏幕上滑动

# swipe from (sx, sy) to (ex, ey)

d.swipe(sx, sy, ex, ey)

# swipe from (sx, sy) to (ex, ey) with 10 steps

d.swipe(sx, sy, ex, ey, steps=10)

# 在屏幕上拖拽

# drag from (sx, sy) to (ex, ey)

d.drag(sx, sy, ex, ey)

# drag from (sx, sy) to (ex, ey) with 10 steps

d.drag(sx, sy, ex, ey, steps=10)

锁屏/解除锁屏

# freeze rotation

d.freeze_rotation() #锁屏

# un-freeze rotation

d.freeze_rotation(False) #解锁

# 截屏操作

d.screenshot("home.png")

# 打开通知或快速设置

# open notification, can not work until Android 4.3.

d.open.notification()

# open quick settings, can not work until Android 4.3.

d.open.quick_settings()

注意:(如果notification已经打开了,调用d.open.quick_settings()不会打开快速设置)

# 等待空闲或窗口更新(Wait for idle or window update)

# wait for current window to idle

d.wait.idle()

# wait until window update event occurs

d.wait.update()


0 0
原创粉丝点击