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 I didn't find a solution, I stumbled upon a good tool, a better tool than sl4a, wrapping uiautomator directly, calling Uiautomator's API to write scripts locally, and then running the test case, which is better than writing in Java and then packaging, Runcase is much simpler, the key is that he also stretches a lot of useful methods, more powerful than the original Google. Let's make it come up below.


Name:

Python wrapper of Android uiautomator test tool

Author

He Xiaoqun

Github:

Https://github.com/xiaocong


Using the method is simple, download 2 jar package: Bunder.jar,uiautomator-stub.jar. can be on GitHub and I'll share it in a minute. With these 2 jars, push them to the Android phone, and start the server, I wrote a batch and ran the Cmd.bat directly:


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 appear as follows:




Now that the server is running, well, start writing Uiautomator's case. Since it is python, of course, Python environment 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 website to install some module.





I installed the Uiautomator.py,jsonrpclib package, URLLIB3 package, specifically you can take a closer look at the instructions on GitHub, when everything is ready to enjoy the tool to give you the Liberation bar. 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 just want to do with Uiautomator to get the interface control information, 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

Post-run results:




I want to achieve the purpose, the following look at my previous hard to solve the problem is the dynamic interface problem. We tune to the stopwatch screen and run the script:





I can express 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 useful, people who have done uiautomator should know that in some no resource-id to the only way to identify the switch, I was previously through the index to obtain, because the current interface has 2 switches. Using the method above is very accurate, is the execution of a bit slow, because it to find the WLAN this control, and then to the right than the control, it may be the cause of slow efficiency.




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

How to zoom out of pictures when viewing photos in a photo album.


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

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.