UIAutomator测试工具的配置以及使用
来源:互联网 发布:淘宝怎么设置优惠卷 编辑:程序博客网 时间:2024/05/16 02:01
运行系统条件:
1)Android Studio
2)系统版本:sdk 要求api18以及以上
配置:
1)配置build.gradle(app目录下的):加入引用库
androidTestCompile 'com.android.support.test:runner:0.2'androidTestCompile 'com.android.support.test:rules:0.2'androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'androidTestCompile 'com.android.support:support-annotations:23.2.0'
2)build.gradle(app目录下的)packagingOptions是与compileOptions、compileSdkVersion平级关系的。 android { packagingOptions { exclude 'LICENSE.txt' } }
创建测试工程:
1)在 androidTest 目录下创建一个新的测试的java类,名字随意,我这里起名字为MyFirstTest,需要注意的是必须继承自InstrumentationTestCase。
2)Alt+Insert添加必要的方法,比如下图的1,、2。其中2为必须要实现的方法,这里可以获取设备实例。
3、查看Launcher UI
连接你的Android设备到电脑上,点击home按键,进入主界面。
打开你安装Android SDK的目录,进入到 tools目录下,点击 uiautomatorviewer.bat 。启动 UI Automater Viewer后看到如下界面:
鼠标移动到不同位置,会有不同选中的框,然后右侧显示这个控件的详细信息。一般关注class、text、content-desc、这些属性,后面需要根据这些找到具体的控件。
下面是测试代码,具体语法参考:http://www.tuicool.com/articles/RVzIrm
http://wenku.baidu.com/link?url=AjD16IN1PHztrcLcEa5MoR8YYwS-mYefZW7KGRzxkLz4nYs3vSMliH3QR2dOnR3d9pPmpC6weVTF4CkjvEMauOsVBbOXJQlHzBlKpqm-PaG
编写完后,直接在java文件右键,然后run这个test文件即可。
package com.tomtop.shop;import android.support.test.uiautomator.By;import android.support.test.uiautomator.UiDevice;import android.support.test.uiautomator.UiObject2;import android.support.test.uiautomator.Until;import android.test.InstrumentationTestCase;/** * author: tc * date: 2016/4/12 & 16:40 * version 1.0 * description * modify by */public class MyFirstTest extends InstrumentationTestCase { private UiDevice device; private static final String TAG = MyFirstTest.class.getSimpleName(); @Override public void setUp() throws Exception { super.setUp(); device = UiDevice.getInstance(getInstrumentation()); } public void testClick() throws Exception { device.wait(Until.hasObject(By.clazz("android.widget.TextView").text("TOMTOP")), 3000); UiObject2 appsButton = device.findObject(By.clazz("android.widget.TextView").text("TOMTOP")); appsButton.click(); Thread.sleep(20000); clickNextByText("Tablet PC & Cellphone"); Thread.sleep(20000); clickNextByText("Sort"); clickNextByText("Review"); clickNextByText("Apply"); Thread.sleep(20000); clickNextByDesc("imageview1"); Thread.sleep(20000); clickNextByText("Buy Now"); Thread.sleep(10000); clickNextByText("Continue"); Thread.sleep(15000); clickNextByText("1"); device.wait(Until.hasObject(By.clazz("android.widget.EditText")), 3000); UiObject2 btn = device.findObject(By.clazz("android.widget.EditText") ); btn.setText("10"); Thread.sleep(2000); clickNextByText("Confirm"); Thread.sleep(2000); clickNextByText("Check Out"); Thread.sleep(15000); } private void clickNextByText(String text) throws InterruptedException { device.wait(Until.hasObject(By.text(text)), 3000); UiObject2 btn = device.findObject(By.text (text)); btn.click(); Thread.sleep(1000); } private void clickNextByDesc(String text) throws InterruptedException { device.wait(Until.hasObject(By.desc(text)), 3000); UiObject2 btn = device.findObject(By.desc (text)); btn.click(); Thread.sleep(1000); }}
- UIAutomator测试工具的配置以及使用
- 在Macbook上配置使用Android自动化测试工具uiautomator
- Android自动化测试工具 UiAutomator使用详解
- 自动化测试UiAutomator的基本使用
- UiAutomator自动化测试框架的使用
- Android Uiautomator工具使用
- Android自动化测试工具uiautomator
- android 4.1 UI 工具测试的新利器, uiautomator
- android 4.1 UI 工具测试的新利器, uiautomator
- 基于 uiautomator 与 shell 的自动化测试工具
- 基于uiautomator与shell的自动化测试工具
- 使用uiautomator做UI测试
- 使用uiautomator做UI测试
- 使用uiautomator 做UI测试
- 使用uiautomator做UI测试
- 使用uiautomator做UI测试
- 使用uiautomator做UI测试
- 使用uiautomator做UI测试
- JAVA多线程学习笔记
- dispatch_sync死锁问题研究
- 对象的克隆
- TimesTen 应用层数据库缓存学习:6. Aging策略
- 一个c++封装的zookeeper库
- UIAutomator测试工具的配置以及使用
- 十的阶乘
- android开发中的九宫格布局的实现
- 腾讯2016春季校园实习招聘技术岗终面(HR面)问题汇总(CC++后台)
- AngularJS_3 Form
- 数据结构与算法汇总(持续更新中)
- 一位数 * 一位数
- 【PHP-Laravel框架学习】在ubuntu上配置环境
- 十个随机数求和 1044 郑明雨