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-versiondirectory 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.

本文介绍了如何使用Apache Ant、Android SDK中的uiautomator工具以及Eclipse来构建和部署Android应用,并进行UI自动化测试。通过创建独立的Java项目并添加相关库文件到构建路径,编写测试用例来验证应用的界面元素。同时解决了Java环境配置和运行测试时可能遇到的问题。
1205

被折叠的 条评论
为什么被折叠?



