Java Code Examples for androidx.test.uiautomator.BySelector#clazz()
The following examples show how to use
androidx.test.uiautomator.BySelector#clazz() .
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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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: BaseElementHandler.java From za-Farmer with MIT License | 4 votes |
public BySelector getElementSelector() { BySelector bySelector = By.base(); if (this.elementId != null) { bySelector.res(this.elementId); } if (this.elementText != null) { bySelector.text(this.elementText); } if (this.elementDesc != null) { bySelector.desc(this.elementDesc); } if (this.elementClazz != null) { bySelector.clazz(this.elementClazz); } if (this.elementPackage != null) { bySelector.pkg(this.elementPackage); } if (this.elementTextDesc != null) { bySelector.setCustomCheckCriteria(new customCheckCriteria(this.elementTextDesc)); } //contains if (this.elementIdContains != null) { bySelector.res(containsPattern(this.elementIdContains)); } if (this.elementTextContains != null) { bySelector.textContains(this.elementTextContains); } if (this.elementDescContains != null) { bySelector.descContains(this.elementDescContains); } if (this.elementClazzContains != null) { bySelector.clazz(containsPattern(this.elementClazzContains)); } if (this.elementPackageContains != null) { bySelector.pkg(containsPattern(this.elementPackageContains)); } if (this.elementTextDescContains != null) { bySelector.setCustomCheckCriteria( new customCheckCriteria(containsPattern(this.elementTextDescContains)) ); } //pattern if (this.elementIdPattern != null) { bySelector.res(Pattern.compile(this.elementIdPattern)); } if (this.elementTextPattern != null) { bySelector.text(Pattern.compile(this.elementTextPattern)); } if (this.elementDescPattern != null) { bySelector.desc(Pattern.compile(this.elementDescPattern)); } if (this.elementClazzPattern != null) { bySelector.clazz(Pattern.compile(this.elementClazzPattern)); } if (this.elementPackagePattern != null) { bySelector.pkg(Pattern.compile(this.elementPackagePattern)); } if (this.elementTextDescPattern != null) { bySelector.setCustomCheckCriteria( new customCheckCriteria(Pattern.compile(this.elementTextDescPattern)) ); } return bySelector; }
Example 6
Source File: UiObjectMatcher.java From device-automator with MIT License | 3 votes |
/** * 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); }