Recently in the company has done a phase of mobile app automation testing, is in the existing environment based on the development of scripts, all the foundation of the environment is not very clear, and later on their own free to work at home to build a bit under, and then share with you about the construction process.
A: The basic environment required to build a mobile app automation test environment is as follows:
1.jdk:java Operating Environment
2.SDK: Requires API above 15
3.Eclipse: For developing scripts and installing ADT plugins, viewing elements
4.ANT: For compiling build jar Package
II: Install the JDK and configure environment variables
1) Get the JDK installation package:
Method One: Official: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Method Two: To my Baidu network disk download: https://pan.baidu.com/disk/home#list/path=%2F&vmode=list
2): Configure Java Environment variables:
1, open the computer--Properties--Advanced system settings--advanced--Environment variables:
2. New System variables Java_home and Classpath
Variable name: Java_home variable Value: C:\Program files\java\jdk1.8.0_111 (Note: Here is the actual installation path of the JDK, modified according to the actual path)
Variable name: CLASSPATH variable value:.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar;
3. Modify path path, add bin path
Variable Name: PATH variable value:%java_home%\bin;%java_home%\jre\bin; (here is the Bin directory added in the path path)
4. Verify that the environment variable is OK
Enter cmd into the console, then enter "Java-version" To view the Java version of the configuration, if you can query, prove environment variable configuration OK.
Two: Download the SDK and configure environment variables
sdk:http://sdk.android-studio.org/
Unzip the. zip package after the download is complete and configure the environment variables
1) Under System variables, click New Android, where the variable value is the path of the SDK after unpacking itself
2) Add%android% in path;
3) Check whether the environment is OK
In the cmd window input: ADB, the following message appears indicating that the environment variable was added successfully.
4) If necessary, you can download and update the SDK development package, open the Android SDK Manager, select the package you need, click "Install Packages", then in the next step, click each package name and select "Accept". Then click "Install".
Three: Install Eclipse
Method One: Official: https://www.eclipse.org/downloads/
Method Two: To my Baidu network disk download: https://pan.baidu.com/disk/home#list/path=%2F&vmode=list
IV: Install the ADT plugin in eclipse
adt:http://adt.android-studio.org/
(1) To open Eclipse, select help-> Install New software in the menu bar and the following interface appears:
(2) After clicking on the Add button, the following interface appears:
Name:android or ADT (the name can be defined on its own);
location:https://dl-ssl.google.com/android/eclipse/(If an error occurs, change HTTPS to HTTP) and follow the instructions to finish
2) Verify that ADT is installed OK
After the installation is successful, a row of Android SDK manager and Android Virtual Device manager Android icons will appear on the menu bar, see:
Five: Install ant, and configure environment variables
: http://ant.apache.org/bindownload.cgi
Build the Ant_home variable first, and then add the%ant_home%\bin in path
VI: Install Python and install the Pydev plugin in eclipse
1) Windows Environment Installation Python is relatively simple, directly click Python-2.7.msi, the next step until the installation is complete.
2) Configure the Python environment variable to increase the Python installation path under the system variable path.
III: Install the Pydev plugin in eclipse
1) Open Eclipse, click Help-->install New Software-->add, and in the pop-up menu, name fill in: Pydev, location filled in: Http://pydev.org/updates,
After a few minutes, you will see the figure (2), followed by the Next button until finish, this Pydev plug-in installation is complete.
Figure (1)
Figure (2)
Quad: Configure Pydev interpreter in eclipse
1) Click on Windows->preferences. In the dialog box that pops up, click the Pydev->interpreters-->python interpreter menu, then click the New button in the menu that pops up, Select the path of the Python.exe, and a window with many checkboxes appears when opened. Click OK
This completes the PYDEV interpreter parser installation.
Seven: Creating a Python Project
Start Eclipse, create a new project, file->new->projects ... Select Pydev->pydevproject to enter the project name.
New PyDev package. You can write the code.
Eight: Add JUnit Library, Android Library
Right-click on the project name, Bulid path->configure Bulid path->add library->junit, import the Junit library, Use the same method to import Android.jar and Uiautomator.jar
After all libraries have been added, such as:
Ten: view the SDK ID
CMD into the Sdk\tools\ directory, run the command: Android list
View the ID value of the SDK with API greater than 15, which is currently 2;
Create a Bulid file
Still under 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 2,path that you saw in the previous step is the path name of the new project
Android Create Uitest-project-n autorunner-t 2-p D:\adt-bundle-windows-x86_64-20140702\eclipse\workspace\ChpJavaTwo
After running the command, the Build.xml file will be generated in the project's root directory
Compile build jar
CMD enters the project catalog, then runs the ant build and builds the jar using ant build, which is done as follows:
Generate a jar file in the bin directory
Push and run the jar
ADB push <jar file path > data/local/tmp
The actual execution of the command is
ADB push D:\adt-bundle-windows-x86_64-20140702\eclipse\workspace\ChpJavaTwo\bin\AutoRunner.jar data/local/tmp
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 autorunner.jar-c testpackage. TestClass (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.
Mobile phone automation test environment Construction (eclipse+python+uiautomator)