uiautomator python version

Summary:

Use jsonrpc technology directly packaged uiautomator, call uiautomator of api written in the local direct the script, and then run the test case, so than with Java to write, and then packaged, runcase much simpler, the key is that he has extended many useful ways, than google native to be a bit more powerful.

Name:

Python wrapper of Android uiautomator test tool

author:

He Xiaocong

Github:

https://github.com/xiaocong

 

Server class bundle.jar jsonrpc used in support of the jar package

 

 

Very simple to use, download two jar package: bunder.jar, uiautomator-stub.jar. Can at github, I'll also share. Under these two good jar, to push them to android phone, then start the server, I wrote a batch run directly cmd.bat:

 

adb forward tcp:9008 tcp:9008
adb push bundle.jar /data/local/tmp
adb push uiautomator-stub.jar /data/local/tmp
adb shell uiautomator runtest uiautomator-stub.jar bundle.jar -c com.github.uiautomatorstub.Stub


When the server is started it will be displayed as follows:

 

In this case the server is running, well, start writing case uiautomator it. Since it is a python, of course python environment must be configured, I will not elaborate on this, and say that you want to use this tool, have to install some module Follow the instructions on the website.

 

 

 

 

我安装了uiautomator.py,jsonrpclib包,urllib3包,具体你可以详细看看github上的说明,当一切准备就绪的时候,就来享受一下该工具带给你的解放吧。所以很感谢作者的付出,因为有了这些人,才让我们感觉到技术的美好。

 

我还是不忘我的初衷,我就是要做用uiautomator来获得界面 控件的信息,看看该工具能不能实现。直接上代码:

 

# -*- coding: utf8 -*-

from uiautomator import device as d
#点亮屏幕
#d.screen.on()
#dump界面信息
#device.dump("hierarchy.xml")
#获取界面控件信息并打印
xml = d.dump()
print xml

运行后结果:

 

 


我要的目的达到了,下面看看我之前苦苦无法解决的问题就是动态界面的问题。我们调到秒表界面,运行该脚本:

 

 

 

 

 

 

我能对作者表达一下爱慕么,虽然我也是男人。哈哈!Done it!速度还比用uiautomator工具要快。

 

那么我要的东西都已经得到,来看看还有什么强大的功能。

 

d(text="WLAN").right(className="android.widget.Switch").click()


在设置里,我们想要点击WLAN右边的开关键,用上面的一行代码就可以搞定。这个方法很有用,搞过uiautomator的人应该知道,在一些没有resource-id来唯一辨识该switch的地方,我之前是通过index来获得,因为当前界面有2个开关。用上面的方法就很精确,就是执行的时候有点慢,因为它要先找到WLAN这个控件,然后向右比对控件,可能是这个原因造成的效率慢。

 

d(scrollable=True).gesture((100, 100), (100, 400)).to((200, 500), (300, 200))

 

https://blog.csdn.net/itfootball/article/details/28392295

 

 

Guess you like

Origin www.cnblogs.com/aliceyang/p/11962803.html