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
  • 相关阅读:
    firefox远程调试
    PHP使用unset销毁变量并释放内存(转)
    去掉超级链接的虚线框
    如何减少 reflow(回流)和 repaint(重绘)
    Chrome远程调试
    3大mobile浏览器远程调试
    IE6下使用滤镜后链接无法点击的BUG
    让IE6区块元素具备display:inlineblock属性
    Call to undefined function curl_init()解决方法(转)
    CSS3 Gradient
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4556497.html
Copyright © 2011-2022 走看看