Java Code Examples for androidx.test.uiautomator.UiSelector#className()

The following examples show how to use androidx.test.uiautomator.UiSelector#className() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiObjectMatcher.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Find a view based on the prefixed text in the view. The matching is case-insensitive.
 *
 * @param text Prefix to search for.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withTextStartingWith(String text, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .textStartsWith(text);
    BySelector bySelector = By.textStartsWith(text);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 2
Source File: UiObjectMatcher.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Find a view based on the text contained within the view. The matching is case-sensitive.
 *
 * @param text Text to search for inside a view.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withTextContaining(String text, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .textContains(text);
    BySelector bySelector = By.textContains(text);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 3
Source File: UiObjectMatcher.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Find a view based on the exact text contained within the view. Matching is case-insensitive.
 *
 * @param text Exact text in the view.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withText(String text, Class klass) {
    Pattern pattern = Pattern.compile("(?i)" + Pattern.quote(text));

    UiSelector uiSelector = new UiSelector()
            .textMatches(pattern.pattern());
    BySelector bySelector = By.text(pattern);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 4
Source File: UiObjectMatcher.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Find a view based on the resource id. Resource ids should be the fully qualified id,
 * ex: com.android.browser:id/url
 *
 * @param id The fully qualified id of the view, ex: com.android.browser:id/url
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withResourceId(String id, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .resourceId(id);
    BySelector bySelector = By.res(id);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 5
Source File: UiObjectMatcher.java    From device-automator with MIT License 3 votes vote down vote up
/**
 * Find a view based on the content description of the view. The content-description is typically used by the
 * Android Accessibility framework to provide an audio prompt for the widget when the widget is selected.
 * The content-description for the widget must match exactly with the string in your input argument.
 * Matching is case-sensitive.
 *
 * On {@link android.os.Build.VERSION_CODES#LOLLIPOP} devices and higher than matcher can be
 * used to match views in {@link android.webkit.WebView}s and browsers.
 *
 * @param text Content description of the view.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withContentDescription(String text, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .description(text);
    BySelector bySelector = By.desc(text);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}