您的位置:首页 > 编程语言 > Python开发

python+uiautomator测试环境搭建

2015-11-07 15:37 561 查看
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 Device

d = Device('014E05DE0F02000E')

d.info



----Turn on/off screen

# Turn on screen
d.screen.on()
# Turn off screen
d.screen.off()



# wakeup the device
d.wakeup()
# sleep the device, same as turning off the screen.
d.sleep()

---Press hard/soft key


# press home key
d.press.home()
# press back key
d.press.back()
# the normal way to press back key
d.press("back")
# press keycode 0x07('0') with META ALT(0x02) on
d.press(0x07, 0x02)


---Click the screen


# click (x, y) on screen
d.click(x, y)


---Long click the screen


# long click (x, y) on screen
d.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 steps
d.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 steps
d.drag(sx, sy, ex, ey, steps=10)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: