1. After the Uiautomator environment is set up, it can be used formally, and the specific operation of building and running in Eclipse is as follows:
(1) Create a project in Eclipse (Java project).
(2) Next->libraries->add Library, add junit libraries.
(3) Add External JARs:
Add the Android.jar and Uiautomator.jar below the android-sdk\platforms\android-17\.
(4) Add Class in SRC
(5) Find the SDK ID:
CMD into the \android-sdk\tools\ directory, run the command:
Android List
(6) Create a build file
Under the \android-sdk\tools\ directory, run the command:
Android Create Uitest-project-n <name>-T <android-sdk-ID>-P <path>
Like what:
Android Create Uitest-project-n autorunner-t 60-p E:\workspace\AutoRunner
The above name is the name of the jar package to be generated in the future, can be defined by itself, Android-sdk-id is the above 6;
Path is the route to Eclipse's new project, and after the command is run, the Build.xml file is generated in the project's root directory. If not generated, check the steps above.
(7) Compile build jar
CMD enters the project catalog and then runs the ant build, which builds the jar using ant compilation.
The generated jar will be in the bin directory.
(8) Push and run jar
ADB push <jar file path > data/local/tmp
adb shell uiautomator runtest <jar file name >-C < class name in project, including package name >
Like what:
ADB push E:\workspace\AutoRunner\bin\AutoRunner.jar data/local/tmp
adb shell uiautomator runtest autorunner.jar-c com. Runner
Then you can see that the phone will follow the steps in runner automatically.
2. Cannot get control problem in Chinese
Modify the file encoding format of the project in Eclipse, right-click the project->properties->resource->text file encoding from GBK to UTF-8, and recompile the project to run.
3, the Uiautomator method is the method name contains the method of test, if there is no method in the class name contains test, it will fail, if there are multiple names containing the test method, then these methods will be executed sequentially.
Uiautomator Learning Essays