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

    对象搜索—文本与描述

    一、文本属性定位对象:

    返回值 API 描述
    UiSelector test(String text) 文本完全匹配
    UiSelector testContains(String text) 文本包含匹配
    UiSelector textMatches(String regex) 文本正则匹配
    UiSelector textStartsWith(String text) 文本起始匹配

    二、描述属性定位对象:

    返回值 API 描述
    UiSelector description(String desc) 描述完全匹配
    UiSelector descriptionContains(String desc) 描述包含匹配
    UiSelector descriptionMatches(String regex) 描述正则匹配
    UiSelector descriptionStartsWith(String desc) 描述开始字符匹配

    三、API应用举例:

    package com.testuiselector;
    
    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="testText";
            androidId="1";
            new UiAutomatorHelper(jarName, testClass, testName, androidId);
        }
        
        public void testText() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(2000);
            
            UiSelector l1=new UiSelector().text("People");
            UiObject people1=new UiObject(l1);
            people1.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l2=new UiSelector().textContains("ople");
            UiObject people2=new UiObject(l2);
            people2.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l3=new UiSelector().textMatches(".*opl.*");
            UiObject people3=new UiObject(l3);
            people3.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l4=new UiSelector().textStartsWith("peo");
            UiObject people4=new UiObject(l4);
            people4.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
    
        }
        
        public void testDescription() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(2000);
            
            UiSelector l1=new UiSelector().description("Apps");
            UiObject desc1=new UiObject(l1);
            desc1.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l2=new UiSelector().descriptionContains("pp");
            UiObject desc2=new UiObject(l2);
            desc2.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l3=new UiSelector().descriptionMatches(".*pp.*");
            UiObject desc3=new UiObject(l3);
            desc3.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            sleep(2000);
            
            UiSelector l4=new UiSelector().descriptionStartsWith("Ap");
            UiObject desc4=new UiObject(l4);
            desc4.click();
            sleep(2000);
            
            UiDevice.getInstance().pressBack();
            
        }
    
    }
    Demo1.java
  • 相关阅读:
    电话号码的字母组合(力扣第17题)
    太平洋大西洋水流问题(力扣第417题)
    被围绕的区域(力扣第130题)
    ZooKeeper的本地安装和分布式安装
    朋友圈(力扣第547题)
    岛屿数量(力扣第200题)
    岛屿的最大面积(力扣第695题)
    再论力扣第279题--完全平方数
    .net core使用CSRedisCore连接哨兵集群,并用作redis使用分布式缓存。
    使用docker搭建reids主从,哨兵。
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4556422.html
Copyright © 2011-2022 走看看