Android Automated test-uiautomator Environment setupFirst, the Environment preparation 1. Install the Android SDK and configure the environment variables2. Install Android Studio, domestic access to the official website is limited, if not downloaded, you can go to my Baidu cloud disk download:Https://pan.baidu.com/s/1bpq5wK3This cloud disk has Uiautomator2-dependent jar packages that can be downloaded at the same time Second, the new Android Studio
[UiAutomator] the difference between using the instance and index methods in UiSelector to locate controls.
When you use UiAutomator to write test cases, the most common operation is the control query operation.
In UiSelector, there are two methods for locating controls: instance and index. So what are the differences between the two methods?
First, let's take a look at the official api description:
Instanc
In the first article:
Comparison of controls obtained by hierarchyviewer and uiautomatorviewer in android automated testing (1)
I said that an error will be reported when uiautomatorviewer obtains the dynamic interface. The error is as follows:
Today, when I learned uiautomator and used dumpWindowHierarchy () to obtain control information, I found that this method can obtain dynamic interface information. This makes up for the defect of uiautoma
Python+android+uiautomator the environment to buildPythonDownload the appropriate version of the system and install it, tick the path to add it when installingVerify: Open cmd input python under WindowsThe following interface appears to indicate successful installationAndroidDownload installation path: HTTP://TOOLS.ANDROID-STUDIO.ORG/INDEX.PHP/SDKDownload the installation JDK firstJDK Installation Documentation: http://jingyan.baidu.com/article/6dad50
1. The default code on the phone is utf-8, so the project needs to be set to UTF-8 encoding;2. Open the mobile phone developer mode, the first time the phone connected with the computer, you need to download the driver, to pop up the allowed debug box, computer-side with the app Bao and other software connected to the mobile phone will automatically download the driver;3. Use ADB devices to see if the phone is authorized successfully;4. Hit the jar pack and push the jar package to the phone. ADB
Get coordinates and coordinates clickKnowledge related to coordinates:1) Phone screen coordinates: Upper left corner start to bottom right corner end2) DP: device independent pixels, such as 320 pixel display to 640 pixels to stretch one times3) point: Represents a dot (x, y), and the upper-left corner of the coordinate is always (0,0)Two, coordinate related API:
return value
Method name
Describe
Boolean
Click (int x, int y)
Use coordinates to tap
Method/Step
1In fact, the stop is very simple, just to end the process of monkey offHow to stop it?
2PS command to find the Uiautomator processOpen cmd Command Line windowInput:ADB Shell PS | grep MonkeyThe first number returned, which is the process number of the monkey
3The KILL command ends the process to continue typing:ADB shell kill [process number just found]End other processes as well, and other applications can also use this method
The various types of environment configurations that are configured in Uiautomator today are based on the documentation,Result input in cmd: ant-versionPage report ant is not an internal command, instant dumbfounded, I was not configured error Ah, the result and re-looked at the document, or not wrong, but after the input command, or always error;1. Configuration environment:New :( variable value in system variable depends on each person extracting th
, open the Build.xml file, and modify the second line of help to build
Start compiling: ant, use the command line to open the project root directory and execute ant directly
Note the JAR package location information in the output results
Push file to Mobile: adb push
Run test: adb shell uiautomator runtest
-C
Test all the use cases under a class, Package_name.class_name
To test
Why do I need quick commissioning?
Uiautomator cannot be debugged directly at Eclipse
Inefficient command-line debugging
For quick Commissioning Steps
Open Https://github.com/fan2597/UiAutomatorHelper
Download the project
Copy the Uiautomatorhelper.java to the test project
New Java Main method, fill in the following code Public Static void Main (string[] args) { String jarname, TestClass, testname, Androidid;
[UiAutomator] usage of instance and index in UiSelector, instanceof usage
When you use UiAutomator to write test cases, the most common operation is the control query operation.
In UiSelector, there are two methods for locating controls: instance and index. So what are the differences between the two methods?
First, let's take a look at the official api description:
Instance (int instance ):Set the search c
.getpixel (j, i) = = Bitmap1.getpixel (j, i)) {piccount++; } piccountall++; } }intresult = (int) (((float) piccount)/Piccountall * -);NewPrintln (Piccount +"/"+ Piccountall);NewPrintln ("Similarity is:"+ result);returnResult }}Exceptions Other modulesDefines some exception classes, the main function is used to prompt, the role of this hint will be used later.Added a way to start the app and close the app, using the shell command.Runtime.getRuntime().exec("am sta
First, Hierarchyviewer:Pros: Intuitive access to information about UI layout design structures and various properties in a visual perspectiveCons: 1) Poor stability, there are some situations in which the probability of obtaining a certain control is not obtained.2) performance is not good, when using the Hierarchyviewer function test, get control and so on when the execution efficiency is very low, resulting in the entire test time use particularly long, consumption of debugging time3) Only use
:
Iautomationsupport
Getautomationsupport ()
To report a temporary state when you run a test case
Bundle
Getparams ()
Get Command line arguments
Uidevice
Getuidevice ()
Get Uidevice instances
void
Sleep (Long ms)
Sleep time
Inheritance method:Junit.framework.TestCaseJunit.framework.AssertJunit.framework.TestJava.lang.ObjectExceptionsCom.android.uiautomator.core.UiObjectNotFoundExeption
)
Focus Properties
Uiselector
Fromparent (uiselector selector)
Search Parent Class
Uiselector
Index (int index)
Search by number of nodes in the layout layer, unreliable, generally used as a last resort
Uiselector
instance (int instance)
Search indexes such as: Uiselector (). ClassName ("Android.widget.ImageView"). Enabled (TRUE). instance (2);
Uiselector
Longclickable (Boolean val)
Long Press Pr
boolean performtwopointergesture (Point staretPoint1, point StatsPoint2, point EndPoint1, point endPoint2, int St EPsPerform any two finger touch gestures to simulate two finger gestures2.public boolean pinchin (int precent, int steps)Gesture operation, two-point inward contraction3.public boolean pinchout (int percent, int steps)Gesture operation, open two points outward4.public boolean performmultipointergesture (Pointercoords ... touches)Perform a single finger touch gesture to define any ge
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.