Android无线测试之—UiAutomator UiSelector API介绍之四

四种匹配关系介绍

一、四种匹配关系介绍:

二、举例:

匹配字符串   0123456789

1、完全匹配: 0123456789

2、包含匹配: 45678、456、678

3、正则匹配: d{10}

4、起始匹配: 012、01234、01234567

三、程序举例:

package com.testuiselector;

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="testMatch";
        androidId="1";
        new UiAutomatorHelper(jarName, testClass, testName, androidId);
    }
        
    public void testSelector() throws UiObjectNotFoundException{
        //UiSelector l=new UiSelector().text("People"); //完全匹配
        //UiSelector l=new UiSelector().textContains("ople");
        //UiSelector l=new UiSelector().textMatches(".*opl.*");
        UiSelector l=new UiSelector().textStartsWith("peo");
        UiObject people=new UiObject(l);
        people.click();
    }

}
Demo1.java
原文地址:https://www.cnblogs.com/fsw-blog/p/4556179.html