zoukankan      html  css  js  c++  java
  • UiAutoMator一些常用的方法

    常用查找UiObject方法

    // 通过ID查找
    public static UiObject findById(String text)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(text));
    return appBtn;

    }

    例如:UiObject search_src_text =findById("com.android.contacts:id/search_view")



    // 通过resource和description查找
    public static UiObject findByResourceIdAndDesc(String className, String text)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
    .description(text));
    return appBtn;

    }

    例如:UiObject back_camera = findByResourceIdAndDesc(
    "com.android.camera2:id/camera_toggle_button","Play video");



    // 按Text Contains定位
    public static UiObject findByTextContains(String text) {
    UiObject getItem = new UiObject(new UiSelector().textContains(text));
    return getItem;

    }

    例如:UiObject notice = findByTextContains("Remember photo locations");



    // 通过resource和index查找
    public static UiObject findByResourceIdAndIndex(String className, int index)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(className)
    .index(index));
    return appBtn;

    }

    例如:UiObject back_camera = findByResourceIdAndIndex(
    "com.android.camera2:id/camera_toggle_button",0);



    // 通过ID,instance查找
    public static UiObject findByIdInStance(String text, int index)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(text)
    .instance(index));
    return appBtn;

    }

    例如:UiObject back_camera = findByIdInStance(
    "com.android.camera2:id/camera_toggle_button",1);



    // 按照className查找UiScrollable;
    public static UiScrollable findUiScrollableByClassName(String className)
    throws UiObjectNotFoundException {
    UiScrollable scrItem = new UiScrollable(
    new UiSelector().className(className));
    return scrItem;
    }


    // 通过source和text查找
    public static UiObject findByResourceIdAndText(String text1, String text2)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(text1).text(
    text2));
    return appBtn;

    }

    例如:UiObject mode = findByResourceIdAndText(
    "com.android.camera2:id/selector_text", "text");


    // 通过source和text查找
    public static UiObject findByResourceIdAndTextContains(String resourceId, String textContains)
    throws UiObjectNotFoundException {
    UiObject appBtn = new UiObject(new UiSelector().resourceId(resourceId).textContains(
    textContains));
    return appBtn;

    }

    例如:UiObject mode = findByResourceIdAndTextContains(
    "com.android.camera2:id/selector_text", "text");



    // 按照className和index在UiScrollable中查找
    public static UiScrollable findUiScrollableByClassNameAndInstance(
    UiScrollable uiScrollable, String className, int index)
    throws UiObjectNotFoundException {
    UiScrollable scrItem = new UiScrollable(new UiSelector().className(
    className).instance(index));
    return scrItem;

    }



    // 获取UiCollection中的子对象的个数
    public static int findChildCountFromUiCollectionByClassName(
    UiCollection uiCollection, String className)
    throws UiObjectNotFoundException {
    return uiCollection
    .getChildCount(new UiSelector().className(className));
    }


    // 在UiScrollable中通过className和instance查找
    public static UiObject findFromUiScrollableByClassNameAndInstance(
    UiScrollable uiScrollable, String className, int index)
    throws UiObjectNotFoundException {
    return uiScrollable.getChild(new UiSelector().className(className)
    .index(index));
    }


    // 按className定位Scrollable
    public static UiScrollable findScrollableByClass(String className) {
    return new UiScrollable(new UiSelector().className(className));
    }

  • 相关阅读:
    Linux之Ubuntu添加/移除个人软件包存档的源[PPA,Personal Package Archives]
    [C++]Linux之头文件sys/types.h[/usr/include/sys]
    [C++]Linux之文件拷贝在系统调用和C库函数下的效率比较
    Linux之Ubuntu下安装屏幕录像软件(SimpleScreenRecorder)【摘抄】
    [C++]基于Curses库的实时系统监测可视化系统-2017-12-09 15-07-42
    [C++]Linux之虚拟文件系统[/proc]中关于CPU/内存/网络/内核等的一些概要性说明
    [C++]Linux之计算内存利用率与辨析
    [C++]Linux之网络实时检测功能
    [C++]Linux之C编程异常[true未定义解决方案]
    [C++]Linux之读取计算机网络数据[/proc/net/dev]
  • 原文地址:https://www.cnblogs.com/decode1234/p/9160808.html
Copyright © 2011-2022 走看看