搭建Eclipse+UIAutomator 环境

来源:互联网 发布:阿隆戈登数据 虎扑nba 编辑:程序博客网 时间:2024/06/01 09:05

在前面一篇文章中已经介绍了如何搭建 Java+Eclipse环境,现在介绍下如何在Eclipse基础上搭建UIAutomator环境,进行移动端测试。

第一步:安装Android SDK

Link:http://developer.android.com/sdk/installing/index.html . 因为是在Eclipse下,我选的是Stand-alone SDK Tools。进行Download 和Install.

指定Android SDK的安装目录,为了方便使用Android SDK包含的开发工具,我们在系统环境变量中的Path设置Android SDK的安装目录下的tools目录。
 在Android SDK的安装目录下,双击“SDK Manager.exe”,打开Android SDK Manager,Android SDK Manage负责下载或更新不同版本的SDK包,我们看到默认安装的Android SDK Manager只安装了一个版本的sdk tools。


设置环境变量:ANDROID_HOME = D:\Program Files (x86)\Android\android-sdk

设置Path:Path= ;%ANDROID_HOME%\tools


第二步:在Eclipse中安装ADT(AndroidDeveloperTools) 插件及配置

SDK Tools Integration
Many of the tools that you can start or run from the command line are integrated into ADT. They include:
    Traceview: Allows you to profile your program's execution (Window > Open Perspective > Traceview).
    android: Provides access to the Android SDK Manager and AVD Manager. Other android features such as creating or updating projects (application and library) are integrated throughout the Eclipse IDE.
    Hierarchy Viewer: Allows you to visualize your application's view hierarchy to find inefficiencies (Window > Open Perspective > Hierarchy Viewer).
    Pixel Perfect: Allows you to closely examine your UI to help with designing and building. (Window > Open Perspective > Pixel Perfect).
    DDMS: Provides debugging features including: screen capturing, thread and heap information, and logcat (Window > Open Perspective > DDMS).
    adb: Provides access to a device from your development system. Some features of adb are integrated into ADT such as project installation (Eclipse run menu), file transfer, device enumeration, and logcat (DDMS). You must access the more advanced features of adb, such as shell commands, from the command line.
    ProGuard: Allows code obfuscation, shrinking, and optimization. ADT integrates ProGuard as part of the build, if you enable it.


插件link:    https://dl-ssl.google.com/android/eclipse/

To add the ADT plugin to Eclipse 步骤:

(1)Start Eclipse, then select Help > Install New Software.
(2)Click Add, in the top-right corner.
(3)In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:  https://dl-ssl.google.com/android/eclipse/
(4)Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.Click OK.
(5)In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
(6)In the next window, you'll see a list of the tools to be downloaded. Click Next.
(7) Read and accept the license agreements, then click Finish.
(8)If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
    When the installation completes, restart Eclipse.

配置ADT Plugin

在Eclipse重启后,你需要指定Android SDK directory
(1)In the "Welcome to Android Development" window that appears, select Use existing SDKs.Browse and select the location of the Android SDK directory you recently downloaded and unpacked. Click Next.
(2)Your Eclipse IDE is now set up to develop Android apps, but you need to add the latest SDK platform tools and an Android platform to your environment. To get these packages for your SDK, continue to Adding Platforms and Packages.

第三步 在Ecliplse中创建UIAutomator 测试project

(1)在Eclipse中创建一个JavaProject。

(2)添加jar, 点击Java Project,Menu - Project — Properties, Java Build Path - Libraries,Add External JARs... - 把android-sdk\platform\android-xx里面的android.jar和uiautomator.jar添加进来, Add Library... - 添加JUnit - JUnit3类库
(3)在src里添加目录src/com/uia/example/my
(4)在my下添加一个JUnit Test Case,名为LaunchSettings
(5)把http://developer.android.com/tools/testing/testing_ui.html下的sample复制黏贴至testcase,保存
(6)打开cmd运行命令:
  - <android-sdk>/tools> android create uitest-project -n <name> -t 1 -p <path> (<name>就是LaunchSettings, <path>就是项目所在目录), 这时会发现在Project目录下有个build xml生成

(7)修改build.xml文件中的default=bulid 

<?xml version="1.0" encoding="UTF-8"?>
<project name="MyAndroidTest" default="build">

(8)可以切换到项目所在目录(build.xml文件所在目录),运行
  - ant build
  完成后会在/bin下生成LaunchSettings.jar

       也可以直接在Eclipse中,右击“build.xml” 选择“Run As—>Ant Build”, 我选择的是这种方法
(9)使用adb push命令,把test case(LaunchSettings.jar)上传到被测试设备上
  - <android-sdk>\platform-tools>adb push <path_to_output_jar> /data/local/tmp/  (<path_to_output_jar>:jar的文件目录)
(10)最后,运行命令,那个sample的test case就会在设备上跑起来了。
  - <android-sdk>\platform-tools>
adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings


0 0
原创粉丝点击