android.support.test.uiautomator.BySelector Java Examples

The following examples show how to use android.support.test.uiautomator.BySelector. 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: ElementController.java    From UIAutomatorWD with MIT License 6 votes vote down vote up
private static BySelector getSelector(String strategy, String text) throws Exception {
    BySelector selector = null;
    switch (strategy) {
        case "CLASS_NAME":
            selector = By.clazz(text);
            break;
        case "NAME":
            selector = By.desc(text);
            if(selector == null || elements.getmDevice().findObject(selector) == null){
                selector = By.text(text);
            }
            break;
        case "ID":
            selector = By.res(text);
            break;
        case "TEXT_CONTAINS":
            selector = By.textContains(text);
            break;
        case "DESC_CONTAINS":
            selector = By.descContains(text);
            break;
    }
    return selector;
}
 
Example #2
Source File: ElementController.java    From UIAutomatorWD with MIT License 5 votes vote down vote up
private static JSONArray getMultiElements(final BySelector sel) throws Exception {
    JSONArray res;
    List<Element> foundElements = new ArrayList<Element>();
    final List<Element> elementsFromSelector = getElements().getMultiElement(sel);
    foundElements.addAll(elementsFromSelector);
    res = elementsToJSONArray(foundElements);
    return res;
}
 
Example #3
Source File: Elements.java    From UIAutomatorWD with MIT License 5 votes vote down vote up
public Element getElement(BySelector sel) throws Exception {
	UiObject2 el = mDevice.findObject(sel);
	Element result = addElement(el);
	if (el != null) {
		return result;
	} else {
		throw new Exception("not found");
	}
}
 
Example #4
Source File: Elements.java    From UIAutomatorWD with MIT License 5 votes vote down vote up
public List<Element> getMultiElement(BySelector sel) throws Exception {
	List<UiObject2> el = mDevice.findObjects(sel);
	List<Element> result = addElements(el);
	if (result != null) {
		return result;
	} else {
		throw new Exception("not found");
	}
}
 
Example #5
Source File: ElementController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
private static JSONObject getOneElement(final BySelector sel) throws Exception {
    final JSONObject res = new JSONObject();
    final Element element = getElements().getElement(sel);
    res.put("ELEMENT", element.getId());
    return res;
}
 
Example #6
Source File: ItSettingsActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * @param index - The idnex of the field in the list (start at 0)
 * @param text - The text of the field to get
 */
private void testFieldWithName( int index, String text ){

    if ( text == null || text.length() <= 0 || index < 0){
        fail("Wrong test");
    }

    final String DUMMY_TEXT = "Hello world";

    try {
        // Display the dialog
        UiObject field = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.TextView")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/title")
                        .text(text)
        );
        field.click();
        // Change the value
        field = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.EditText")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/edit")
        );
        final String BACKUP_TEXT = field.getText();
        field.setText(DUMMY_TEXT);
        // Confirm
        UiObject button = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.Button")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/button1")
        );
        button.click();
        w(1000);
        // Check the summary
        BySelector checkboxSettingsSelector = By.clazz("android.widget.TextView");
        List<UiObject2> summaries = mDevice.findObjects(checkboxSettingsSelector);
        UiObject2 field2 = summaries.get( index * 4 + 2 );
        assertEquals(DUMMY_TEXT, field2.getText());
        // Reset the value
        resetFieldWithText( DUMMY_TEXT, BACKUP_TEXT );
    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail(uonfe.getMessage());
    }

}