Packaging Uiautomator with JSONRPC technology

Source: Internet
Author: User

Yesterday one day in the online search to solve the exception in the previous article:


Monkeyrunner built-in uiautomator cause of error


Although no solution was found. But I stumbled upon a good tool, a better tool than sl4a. Direct packaging Uiautomator. Call Uiautomator's API to script directly locally and then execute the test case, which is better than writing in Java. and then pack. Runcase to be much simpler, the key is that he also stretches a lot of practical ways, more powerful than Google native.

Let's get it on the go.


Name:

Python wrapper of Android uiautomator test tool

Author

He Xiaoqun

Github:

Https://github.com/xiaocong


Very easy to use. Download 2 jar packages: Bunder.jar,uiautomator-stub.jar.

can be under GitHub. I'll share it in a minute.

With these 2 jars, push them to the Android phone, and then start the server, I wrote a batch that directly executes the Cmd.bat:


ADB forward tcp:9008 tcp:9008adb push bundle.jar/data/local/tmpadb push uiautomator-stub.jar/data/local/tmpadb Shell UI Automator runtest  Uiautomator-stub.jar bundle.jar-c com.github.uiautomatorstub.Stub


When the server starts it will show a demo sample such as the following:




Now that the server is executing, OK. Start writing Uiautomator's case. Since it is python, of course, the environment of Python must be configured well. Here I do not elaborate this, to say, want to use this tool, you have to follow the instructions on the site to install some module.





I installed the Uiautomator.py,jsonrpclib package, URLLIB3 package. Specifically, you can see the instructions on GitHub, and when everything is ready, enjoy the liberation of the tool. So thank the author of the pay, because of these people, just let us feel the good technology.


I still do not forget the original intention. I'm just going to use the uiautomator to get the interface control information and see if the tool can be implemented.

Directly on the code:


#-*-Coding:utf8-*-from uiautomator import device as d# lit screen #d.screen.on () #dump界面信息 #device.dump ("Hierarchy.xml") # Gets the interface control information and prints the XML = D.dump () print XML

Results after execution:




The purpose I want is achieved. Here's a look at some of the problems I've struggled with in the past are dynamic interfaces. We tuned to the stopwatch screen. Execute the script:





Can I express my affection to the author? Although I am also a man. Ha ha! Done it!

Faster than using Uiautomator tools.


So I've got everything I need to see what the powerful features are.


D (text= "WLAN"). Right (classname= "Android.widget.Switch"). Click ()


In the settings. We want to click on the right side of the WLAN to open the key, with the above line of code can be done. This method is very practical. People who have done uiautomator should know that in some places where there is no resource-id to identify the switch, I have previously obtained it through index. Since the current interface has 2 switches. Using the method above is very accurate, is the time to run a little slow. Because it wants to find the WLAN this control first. Then the right is more inefficient than the control, which may be caused by this reason.




D (scrollable=true). Gesture ((+), ((+)). to ((200, 500), (300, 200))

Sangori How to zoom out when viewing photos.


I will introduce these methods, others to the author site carefully read it. Remember to be thankful and thankful for the dedication of the author. But in JSONRPC tool execution process, want to use Uiautomatorviewer to view control information, is not possible, directly will error!

Packaging Uiautomator with JSONRPC technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.