Overview
- Uiautomator Compliance with JUNIT3 standards
Configuring the Authoring Environment
- Configuring the Java Development environment
- JAVA_HOME:JDK root directory
- Path: Add%java_home%\bin;%java_home%\jre\bin;
- CLASSPATH:.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar;
- Andrid Environment Configuration
- ANDROID_HOME:SDK root directory
- Path: Configure the Tools directory in the Android SDK (verified by Android List command) and the Platform-tools directory (successfully added via ADB command) to Path
- Ant Environment Configuration
- Ant_home:ant root directory
- Path: Configure the%ant_home%/bin directory to path (verify the Add success with the ANT command)
New Test Project
- New Java Project (note not Android engineering)
- Add Android.jar and Uiautomator.jar to the build Path
- New Libs directory in the project to hold dependent packages
- Copy the two files in the%ANDROID_HOME\%PLATFORMS\ANDROID-XX directory to the Libs directory
- Android.jar
- Uiautomator.jar
- Add two jar packages to BuildPath
- New test class, inheriting uiautomatortestcase
To write a use case, the method must begin with test. Such as:
Public void Testdemo () { uidevice.getinstance (). Presshome ();}
Compiling and running test code
- Create a Build file
- Execution at the command line: Android create uitest-project-n-T 1-p
- N: The name of the jar package that needs to be published, such as: Demo
- T: The ID number of the SDK version that needs to be compiled, can be obtained by using the Android List command
- P: Current Project root directory
- After execution, refresh the project directory in Eclipse, you will find more Build.xml files
- Modify the Build file
- Open Build.xml File
- Modify <project name= "Demo" default= "Help" > To build
- Start compiling
- Under the command line, go to the project directory and execute the ant command
- When the compilation is complete, look at the result of the command line output in the jar package path, such as D:\android\workspace\Java_TestAndroid_UiAutomator\bin\demo.jar
- Push jar package to the phone
- ADB push <jar_path>/data/local/tmp
- For example: adb push D:\android\workspace\Java_TestAndroid_UiAutomator\bin\/data/local/tmp
Run Tests
- You can then see the effect of the test case execution in the emulator
Running commands and quick commissioning
- The steps described above cannot be debugged directly in eclipse
- command debugging cumbersome and efficient under
- Resolution: Convert the debugging steps to a script
- Create build file, modify build file, start compilation, push file, run test
Implementation steps
- Open Https://github.com/fan2597/UiAutomatorHelper
- clone project to local, import to eclipse
- Copy Uiautomatorhelper.java to the test project
-
Create a new main function in the test class, such as
public static void Main (string[] args) {String jarname =" Demo "; // jar Package name String TestClass = "Com.test.Test"; // test class full name String testcasename = "Testdemo"; // test case name String Androidid = "1" ; new Uiautomatorhelper (Jarname,
TestClass, Testcasename, Androidid);}
- Run the Java project, and then
Uiautomator Learning Note 1. Environment configuration and compilation run