zoukankan      html  css  js  c++  java
  • Android无线测试之—UiAutomator UiSelector API介绍之七

    对象搜索—索引与实例

    一、索引与实例说明:

    1)index:在同一级中的编号,在兄弟类中组件的编号,index从0开始

    2)instance:同一个布局中同一类组件的编号,instance从0开始

    二、索引与实例属性定位对象

     
    返回值 API 描述
    UiSelector index(int index) 索引
    UiSelector instance(int instance) 实例

    三、API应用举例

    package com.testuiselector;
    
    import android.view.View;
    
    import com.android.uiautomator.core.UiDevice;
    import com.android.uiautomator.core.UiObject;
    import com.android.uiautomator.core.UiObjectNotFoundException;
    import com.android.uiautomator.core.UiSelector;
    import com.android.uiautomator.testrunner.UiAutomatorTestCase;
    
    public class Demo1 extends UiAutomatorTestCase {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String jarName, testClass, testName, androidId;
            jarName="demo1";
            testClass="com.testuiselector.Demo1";
            testName="testPackage";
            androidId="1";
            new UiAutomatorHelper(jarName, testClass, testName, androidId);
        }
        
        public void testClass() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(1000);
            
            //完全匹配
            UiSelector l1=new UiSelector().className("android.view.View").instance(3);
            UiObject clock1=new UiObject(l1);
            clock1.click();
            sleep(1000);
            
            UiDevice.getInstance().pressBack();
            sleep(1000);
            
            //正则匹配
            UiSelector l2=new UiSelector().classNameMatches(".*View").instance(4);
            UiObject clock2=new UiObject(l2);
            clock2.click();
            sleep(1000);
            
            UiDevice.getInstance().pressBack();
            sleep(1000);
            
            //class.getName()
            UiSelector l3=new UiSelector().className(View.class.getName()).instance(3);
            UiObject clock3=new UiObject(l3);
            clock3.click();
            sleep(1000);
            
            UiDevice.getInstance().pressBack();
            
        }
        
        public void testPackage() throws UiObjectNotFoundException{
        
            UiDevice.getInstance().pressHome();
            sleep(1000);
            
            UiSelector dl1=new UiSelector().packageName("com.android.deskclock");
            UiObject deskclock1=new UiObject(dl1);
            deskclock1.click();
            sleep(1000);
            
            UiDevice.getInstance().pressBack();
            sleep(1000);
            
            UiSelector dl2=new UiSelector().packageNameMatches(".*deskclock");
            UiObject deskclock2=new UiObject(dl2);
            deskclock2.click();
            
            
        }
    
    }
    Demo1.java
  • 相关阅读:
    vue项目在IE中使用的一些坑(未完待续)
    Vue在IE下显示空白问题
    nginx 解决AJAX 跨域问题。
    node.js+express+jade 国际化
    Angular 2 HTTP Requests with Promise
    Windows x64编译 Qt5.7 Mysql驱动
    mysql [Err] 1215
    VS Code 调试Node.js express网站
    Node.js express 入门示例1
    build qt4.8.5 on centos7 or suse11.1
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4556497.html
Copyright © 2011-2022 走看看