zoukankan      html  css  js  c++  java
  • Android Studio + uiautomator 配置运行

    1.在build.gradle中添加依赖:

    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    implementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    implementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'

    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    2.新建实例:在androidTest文件下新建测试类方法(例:test1.java)

    package com.example.myapplication;
    
    import android.os.Bundle;
    import android.support.test.InstrumentationRegistry;
    import android.support.test.uiautomator.UiDevice;
    import android.support.test.uiautomator.UiObject;
    import android.support.test.uiautomator.UiObjectNotFoundException;
    import android.support.test.uiautomator.UiSelector;
    import android.util.Log;
    
    import org.junit.Test;
    
    import static android.support.test.InstrumentationRegistry.getArguments;
    
    public class test1{
    
        private UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        //获取参数
        Bundle bundle = getArguments();
        private int displayWidth = uiDevice.getDisplayWidth();
        private int displayHeight = uiDevice.getDisplayHeight();
    
        @Test
        public void test() throws InterruptedException, UiObjectNotFoundException {
            uiDevice.pressHome();
            Log.i("test1", "在等待1111111111111");
            uiDevice.swipe(displayWidth / 2, displayHeight / 2, 0, displayHeight / 2, 10);
            while (true) {
                UiObject objectA = uiDevice.findObject(new UiSelector().text("华为钱包"));
                Thread.sleep(1000);
                if (objectA.exists()) {
                    Thread.sleep(1000);
    //                objectA.click();
    //                Thread.sleep(1000);
                    uiDevice.pressHome();
                    ShellRunner.shell("curl -d "123" http://192.168.51.225:8000/ud");
                    Thread.sleep(1000);
                }
            }
        }
    }

    启动uiautomator测试方法

    shell命令启动

    am instrument -w -r -e debug false -e class com.example.myapplication.test1#test com.example.myapplication.test/android.support.test.runner.AndroidJUnitRunner
    com.example.myapplication.test1#test com.example.myapplication.test
    格式为:报名.测试类名#测试方法 报名.test/android.support.test.runner.AndroidJUnitRunner
    报名.test/android.support.test.runner.AndroidJUnitRunner为固定格式
  • 相关阅读:
    poj 3590 The shuffle Problem——DP+置换
    poj 3128 Leonardo's Notebook——思路(置换)
    bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
    bzoj 1119 [POI2009]SLO && bzoj 1697 [Usaco2007 Feb]Cow Sorting牛排序——思路(置换)
    bzoj 3944 Sum —— 杜教筛
    bzoj 1367 [ Baltic 2004 ] sequence —— 左偏树
    bzoj 2093 [ Poi 2010 ] Frog —— 滑动窗口 + 倍增
    bzoj 2276 [ Poi 2011 ] Temperature —— 单调队列
    bzoj 2069 [ POI 2004 ] ZAW —— 多起点最短路 + 二进制划分
    NOIP2007普及 守望者的逃离
  • 原文地址:https://www.cnblogs.com/liuliu-word/p/10494321.html
Copyright © 2011-2022 走看看