precondition:
- You need to use Apache Ant to build and deploy the corresponding project. just download and use it.
- Android provides the uiautomatorviewer tool, which allows you to analyze the user interface of an application. You can use this tool to find the index, text or attribute of the application.
- Eclipse installed.
Steps:
- Create a standalone Java project which the JUnit3 library and the uiautomator.jar and android.jar files from the
android-sdk/platforms/api-version
directory added to the build path. - Test case like:
public class MainRunner extends UiAutomatorTestCase {
public void testDemo00() throws UiObjectNotFoundException,
InterruptedException {
//to do
}
} - android createuitest -project -n [your jar name] -t 21 -p [you project location]. This command is used to create a build.xml file.
-
# build the test jar ant build # push JAR to device adb push output.jar /data/local/tmp/ # Run the test adb shell uiautomator runtest you_jar_name.jar -c your_package_name_classname.
ant build # push JAR to device adb push output.jar /data/local/tmp/ # Run the test adb shell uiautomator runtest you_jar_name.jar -c your_package_name_classname.
ISSUES:
- Take care of your jave environment. ant build. it will read C:\Program Files (x86)\Java\jre1.8.0_45\lib\tool.jar. sometimes no. just copy it from C:\Program Files (x86)\Java\jdk1.8.0_45\lib.
- if you want to Run a method of the class, just run the test like
adb shell uiautomator runtest you_jar_name.jar -c your_package_name_classname#your_methodname.
you_jar_name.jar -c your_package_name_classname#your_methodname.