Java Code Examples for android.support.test.uiautomator.UiObject#getText()

The following examples show how to use android.support.test.uiautomator.UiObject#getText() . 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: UiWatchers.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public boolean handleAnr() {
    UiObject window = sDevice.findObject(new UiSelector()
            .className("com.android.server.am.AppNotRespondingDialog"));
    String errorText = null;
    if (window.exists()) {
        try {
            errorText = window.getText();
        } catch (UiObjectNotFoundException e) {
            Log.e(TAG, "dialog gone?", e);
        }
        onAnrDetected(errorText);
        postHandler();
        return true; // triggered
    }
    return false; // no trigger
}
 
Example 2
Source File: UiWatchers.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public boolean handleAnr2() {
    UiObject window = sDevice.findObject(new UiSelector().packageName("android")
            .textContains("isn't responding."));
    if (!window.exists()) {
        window = sDevice.findObject(new UiSelector().packageName("android")
                .textContains("沒有回應"));
    }
    if (window.exists()) {
        String errorText = null;
        try {
            errorText = window.getText();
        } catch (UiObjectNotFoundException e) {
            Log.e(TAG, "dialog gone?", e);
        }
        onAnrDetected(errorText);
        postHandler();
        return true; // triggered
    }
    return false; // no trigger
}
 
Example 3
Source File: UiWatchers.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public boolean handleCrash() {
    UiObject window = sDevice.findObject(new UiSelector()
            .className("com.android.server.am.AppErrorDialog"));
    if (window.exists()) {
        String errorText = null;
        try {
            errorText = window.getText();
        } catch (UiObjectNotFoundException e) {
            Log.e(TAG, "dialog gone?", e);
        }
        onCrashDetected(errorText);
        postHandler();
        return true; // triggered
    }
    return false; // no trigger
}
 
Example 4
Source File: UiWatchers.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public boolean handleCrash2() {
    UiObject window = sDevice.findObject(new UiSelector().packageName("android")
            .textContains("has stopped"));
    if (!window.exists()) {
        window = sDevice.findObject(new UiSelector().packageName("android")
                .textContains("已停止運作"));
    }
    if (window.exists()) {
        String errorText = null;
        try {
            errorText = window.getText();
        } catch (UiObjectNotFoundException e) {
            Log.e(TAG, "dialog gone?", e);
        }
        UiHelper.takeScreenshots("[CRASH]");
        onCrashDetected(errorText);
        postHandler();
        return true; // triggered
    }
    return false; // no trigger
}
 
Example 5
Source File: ObjInfo.java    From android-uiautomator-server with MIT License 6 votes vote down vote up
private ObjInfo(UiObject obj) throws UiObjectNotFoundException {
	this._bounds = Rect.from(obj.getBounds());
	this._checkable = obj.isCheckable();
	this._checked = obj.isChecked();
	this._childCount = obj.getChildCount();
	this._clickable = obj.isClickable();
	this._contentDescription = obj.getContentDescription();
	this._enabled = obj.isEnabled();
	this._focusable = obj.isFocusable();
	this._focused = obj.isFocused();
	this._longClickable = obj.isLongClickable();
	this._packageName = obj.getPackageName();
	this._scrollable = obj.isScrollable();
	this._selected = obj.isSelected();
	this._text = obj.getText();
       this._visibleBounds = Rect.from(obj.getVisibleBounds());
       this._className = obj.getClassName();
}
 
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());
    }

}