python+uiautomator测试环境搭建

来源:互联网 发布:坐久了腰疼 知乎 编辑:程序博客网 时间:2024/05/22 18:21

1.安装python2.7,配置python环境变量C:\Python27


2.安装setuptools   http://pypi.python.org/pypi/setuptools(安装setuptools后才能安装pip工具)

下载后解压setuptools压缩包,进入到setuptools目录下,打开cmd 运行 python setup.py install 即可自动完成安装 


3.接下来就是安装pip工具,http://pypi.python.org/pypi/pip#downloads 下载解压后 cd到setup.py 目录下,打开cmd 运行 python setup.py install ,如果要在命令行使用pip 还需要配置环境变量,将pip.exe所在目录C:\Python27\Scripts添加到环境变量path中


4.打开cmd 窗口  运行pip install uiautomator


当然如果是python3.0以上就不用这么麻烦,因为3.0以后在安装python时已经集成了setuptools和pip工具,并且配置好了环境变量,所以只需要一步操作,打开cmd 窗口  运行pip install uiautomator 即可。


此python-uiautomator实现乃是大神贺晓聪提供   https://github.com/xiaocong/uiautomator

有了这个基础我们可以在此框架上进行二次开发了。

附上部分基本操作实现如下:

from uiautomator import Deviced = Device('014E05DE0F02000E')
d.info

----Turn on/off screen

# Turn on screend.screen.on()# Turn off screend.screen.off()
# wakeup the deviced.wakeup()# sleep the device, same as turning off the screen.d.sleep()
---Press hard/soft key
  • # press home keyd.press.home()# press back keyd.press.back()# the normal way to press back keyd.press("back")# press keycode 0x07('0') with META ALT(0x02) ond.press(0x07, 0x02)
  • ---Click the screen
  • # click (x, y) on screend.click(x, y)
  • ---Long click the screen
  • # long click (x, y) on screend.long_click(x, y)
  • ---Swipe
  • # 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)
  • ---Drag
  • # 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)

0 1