Uiautomator环境搭建

下载依赖库
  • 进入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"

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值