构建android UI automation test测试环境

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:

  1. 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.
  2. Test case like:
    public class MainRunner extends UiAutomatorTestCase {
    public void testDemo00() throws UiObjectNotFoundException,
    InterruptedException {
    //to do
    }
    }
  3. android createuitest -project -n [your jar name] -t 21 -p [you project location]. This command is used to create a build.xml file.
  4. # 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:

  1. 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.
  2. 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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值