Android uiautomator Environment Construction and use

Source: Internet
Author: User

The Android automation framework is often used in many, and itself provides many automated testing frameworks, each with its advantages and disadvantages. Of course, for us to do UI Automation testing, easy to use.

Uiautomator is also an automated testing framework provided by Android that basically supports all Android event operations without the need for testers to understand the code implementation details. Testers can use the Uiauto horse into the viewer to crawl the app page control properties, do not need to look at the source code. Based on Java, the test code structure is relatively simple, easy to get started, the learning cost is not high, a compilation, all devices or simulators can run the test, can cross the app. Of course, the insufficiency is: only supports sdk16 and above, does not support Hybird app, WebApp. Below, let's take a small example to illustrate the uiautomator of the environment to build and use.

First, the Environment preparation

1. Installing the JDK is necessary.

2. Download Sdk/adt (ANDROID required, currently ADT comes with SDK and ECLIPSE,API requires more than 16), configure environment variables: first establish android_home, and then add%android_home%\tools in Path;

3. Install the ANT tool and configure the environment variables: first build the Ant_home variable, then add%ant_home%\bin in Path, test for success, run-ant.

4. Install Eclipse and install the ADT plugin.

Second, build Eclipse project

1. Open eclipse,new-New Java project, enter project name Uiautomator, and click Finish.

  

  2. Add Android Library

Locate the path sdk\platforms\android-20 below the Android.jar and Uiautomator.jar,copy to the Lib under project.

  

  

  

  Put Android.jar and Uiautomator.jar in the build path.

3. Create the first demo program

  

  Code, write Getuidevice (). Presshome (); a line of code to test.

 4. View the SDK ID

cmd into sdk\tools\ directory, run command: Android list, view SDK ID value of API greater than 15, and currently installed Android version, currently 1

  

  5. Generate the Bulid file

In the \sdk\tools\ directory, run the command: Android create uitest-project-n <name>-T <android-sdk-ID>-P <path>

where name is the name of the jar package that will be generated in the future, you can define it yourself, Android-sdk-id the 1,path that you saw in the previous step is the path name of project. Android Create uitest-project-n first-t 1-p E:\workspace\UIAutomator

  

After running the command, the Build.xml file will be generated in the project's root directory

  

  6. Compiling the Build Jar

CMD into the project catalog, then run the ant build, build the jar with ant build, and do the following:

  Generate RAR files in the bin directory

  

7. Push and run the jar

ADB push <jar file path > data/local/tmp

The actual execution command is: adb push E:\workspace\UIAutomator\bin\first.jar data/local/tmp

  

8. Run the jar file

adb shell uiautomator runtest <jar file name >-C < package name. class Name >

The actual Run command is: adb shell uiautomator runtest first.jar-c Com.iu.android.TestPage.TestDemoOne (be careful not to write the wrong package name and class name), you can see that your phone will follow the steps in runner automatically.

Android uiautomator Environment Construction and use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.