Uiautomator环境搭建
2015-11-21 14:59
495 查看
下载依赖库
进入https://github.com/,搜索android-testing下载工程googlesamples/android-testing
工程中android-testing-master\ui\espresso\BasicSampleBundled\libs目录中就是需要的依赖库(不需要其中的android-support-v4.jar)
AndroidStudio配置
打开AndroidStudio,新建工程切换到Project视图,新建libs文件夹,把刚才下载的依赖库拷贝到文件夹中,并添加到编译目录中
切换回Android视图,在测试包下新建测试类(例如:UiTestDemo)
编写测试类,代码如下:
package mqqzt.myuitest1; import android.os.RemoteException; import android.support.test.InstrumentationRegistry; import android.support.test.uiautomator.UiDevice; import android.view.KeyEvent; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Created by mqqzt-yang on 2015/11/21. */ @RunWith(JUnit4.class) public class UiTestDemo { @Test public void testPress() throws RemoteException { UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); uiDevice.pressMenu(); uiDevice.pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN); uiDevice.pressRecentApps(); uiDevice.pressHome(); } }
编辑运行器
build.gradle文件defaultConfig代码块增加运行器
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
相关文章推荐
- GPUImage简单滤镜使用之色阶(三)
- 对频率论(Frequentist)方法和贝叶斯方法(Bayesian Methods)的一个总结
- UIView的userInteractionEnabled属性的意义
- easyui datagrid 部分参数
- Spoj 1716 Can you answer these queries III
- spoj SPOJ 1043 Can you answer these queries I
- Java中EventQueue.invokeLater干什么用的
- UITableViewCell 初始化
- PAT 1041. Be Unique (20)
- Eclispe环境启动遇This Android SDK requires Android Developer Toolkit version 23.0.0 or above
- Maximizing the Spread of Influence through a Social Network
- 27.iOS中最重要的视图UITableView表视图第二章
- IOS UITextView显示Hint提示文字
- UIEventListener 及其他
- The 11-Step Guide to BYOD Security. How to Avoid Getting Fired
- IOS--UI:按钮,文本框,标签,文本视图创建
- Easyui Form表单提交
- 爬爬爬之路:UI(八)UINavigationController 界面传值
- Java的GUI发展-AWT/SWT/Swing
- 26.iOS中最重要的视图UITableView表视图第一章