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

The following examples show how to use android.support.test.uiautomator.UiObject#waitForExists() . 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: ItNotificationsManager.java    From SmoothClicker with MIT License 6 votes vote down vote up
/**
 * Inner method to get a dedicated notification and test it
 * @param textContent - The text to use to get the notification
 */
private void testIfNotificationExists( String textContent ) {

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                    .resourceId("android:id/text")
                    .className("android.widget.TextView")
                    .packageName("pylapp.smoothclicker.android")
                    .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(2000);
    assertTrue(n.exists());

}
 
Example 2
Source File: ItServiceClicker.java    From SmoothClicker with MIT License 6 votes vote down vote up
/**
 * Inner method to get a dedicated notification and test it
 * @param textContent - The text to use to get the notification
 */
private void testNotification( String textContent ){

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("pylapp.smoothclicker.android")
                        .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(60000);
    assertTrue(n.exists());

}
 
Example 3
Source File: UiHelper.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public static boolean handleCommonDialog() {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject button = null;
    for (String keyword : Config.COMMON_BUTTONS) {
        button = device.findObject(new UiSelector().text(keyword).enabled(true));
        if (button != null && button.exists()) {
            break;
        }
    }
    try {
        // sometimes it takes a while for the OK button to become enabled
        if (button != null && button.exists()) {
            button.waitForExists(5000);
            button.click();
            Log.i("AppCrawlerAction", "{Click} " + button.getText() + " Button succeeded");
            return true; // triggered
        }
    } catch (UiObjectNotFoundException e) {
        Log.w(TAG, "UiObject disappear");
    }
    return false; // no trigger
}
 
Example 4
Source File: EspPermissionDialog.java    From espresso-macchiato with MIT License 5 votes vote down vote up
protected void click(String targetId) {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject button = device.findObject(new UiSelector().resourceId(targetId));

    try {
        button.waitForExists(3000);
        button.click();
    } catch (UiObjectNotFoundException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 5
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Tests the long clicks on the floating action button for start in the arc menu
 *
 * <i>A long click on the button to use to start the process should display a snackbar with an explain message</i>
 */
@Test
public void longClickOnArcMenuStartItem(){

    l(this, "@Test longClickOnArcMenuStartItem");

    String expectedText = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_start);

    try {

        /*
         * Display the floating action buttons in the arc menu
         */
        UiObject arcMenu = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
        );
        arcMenu.click();
        arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);

        /*
         * The floating action button
         */
        UiObject fab = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabStart")
        );
        fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
        assertTrue(fab.isLongClickable());
        fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        assertEquals(expectedText, snack.getText());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}
 
Example 6
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Tests the long clicks on the floating action button for stop in the arc menu
 *
 * <i>A long click on the button to use to stop the process should display a snackbar with an explain message</i>
 */
@Test
public void longClickOnArcMenuStopItem(){

    l(this, "@Test longClickOnArcMenuStopItem");

    String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_stop);

    try {

        /*
         * Display the floating action buttons in the arc menu
         */
        UiObject arcMenu = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
        );
        arcMenu.click();
        arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);

        /*
         * The floating action button
         */
        UiObject fab = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabStop")
        );
        fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
        assertTrue(fab.isLongClickable());
        fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        assertEquals(expectedString, snack.getText());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}
 
Example 7
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Tests the long clicks on the floating action button for SU grant in the arc menu
 *
 * <i>A long click on the button to use to get the SU grant should display a snackbar with an explain message</i>
 */
@Test
public void longClickOnArcMenuSuGrantItem(){

    l(this, "@Test longClickOnArcMenuSuGrantItem");

    String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_request_su);

    try {

        /*
         * Display the floating action buttons in the arc menu
         */
        UiObject arcMenu = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
        );
        arcMenu.click();
        arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);

        /*
         * The floating action button
         */
        UiObject fab = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabRequestSuGrant")
        );
        fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
        assertTrue(fab.isLongClickable());
        fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        assertEquals(expectedString, snack.getText());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}
 
Example 8
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Tests the long clicks on the floating action button for new point in the arc menu
 *
 * <i>A long click on the button to use to add points to click on should display a snackbar with an explain message</i>
 */
@Test
public void longClickOnArcMenuNewPointItem(){

    l(this, "@Test longClickOnArcMenuNewPointItem");

    String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_new_point);
    try {

        /*
         * Display the floating action buttons in the arc menu
         */
        UiObject arcMenu = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
        );
        arcMenu.click();
        arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);

        /*
         * The floating action button
         */
        UiObject fab = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabSelectPoint")
        );
        fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
        assertTrue(fab.isLongClickable());
        fab.swipeUp(100); //fab.longClick() makes clicks sometimes, so swipeUp() is a trick to make always a longclick
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        assertEquals(expectedString, snack.getText());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}
 
Example 9
Source File: ItStatusBarNotifier.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Inner method to get a dedicated notification and test it
 * @param textContent - The text to use to get the notification
 */
private void testNotification( String textContent ){

    if ( textContent == null ) textContent = "";

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("pylapp.smoothclicker.android")
                        .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(2000);
    assertTrue(n.exists());

}
 
Example 10
Source File: ItNotificationsManager.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Inner method to get a dedicated notification and test if this notification is clicakble and display the good activity on click
 * @param textContent - The text to use to get the notification
 */
private void testNotificationClick( String textContent ){

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("pylapp.smoothclicker.android")
                        .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(2000);

    try {
        n.click();
        w(5000);
        assertEquals(ClickerActivity.class.getSimpleName(), getActivityInstance().getClass().getSimpleName());
    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail();
    }

}
 
Example 11
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Test the click on the SU grant button
 *
 * <i>If the button to get the SU grant is clicked, a notification about the good access to SU grant is displayed</i>
 */
//@Test
@Deprecated
public void clickOnSuGrantButton(){

    l(this, "@Test clickOnSuGrantButton");

    try {

        // Open the arc menu
        UiObject arcMenu = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
        );
        arcMenu.click();

        // Request the SU grant
        UiObject suGrantFab = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabRequestSuGrant")
        );
        suGrantFab.click();

        // Check the notifications panel
        UiObject n = null;

        if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
            n = mDevice.findObject(
                    new UiSelector()
                            .resourceId("android:id/text")
                            .className("android.widget.TextView")
                            .packageName("pylapp.smoothclicker.android")
                            .textContains("Droits Super-utilisateur accordés à Smooth Clicker")); // WARNING FIXME French language, get the string in system R
        } else {
            n = mDevice.findObject(
                    new UiSelector()
                            .resourceId("android:id/text")
                            .className("android.widget.TextView")
                            .packageName("com.android.systemui")
                            .textContains("Droits Super-utilisateur accordés à Smooth Clicker")); // WARNING FIXME French language, get the string in system R
        }

        mDevice.openNotification();
        n.waitForExists(2000);
        assertTrue(n.exists());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}
 
Example 12
Source File: ItStandaloneModeDialog.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Tests if the notification is displayed when the standalone mode is running
 *
 * <i>If the standalone mode is running, a dedicated notification is displayed</i>
 */
@Test
public void notificationOnGoing(){

    l(this, "@Test notificationOnGoing");

    prepareNeededFiles();

    // Start a standalone mode
    try {

        // Choose the OCR-like standalone mode (the alst of the list)
        for ( int i = 1; i <= steps; i++ ){
            UiObject rightArrow = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_layout_rightButton")
            );
            rightArrow.click();
        }

        // Click on the OK button
        UiObject btOk = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/btCreate")
        );
        btOk.click();

        // Check the notification
        String notificationText = InstrumentationRegistry.getTargetContext().getString(R.string.notif_content_text_clicks_on_going_standalone);
        UiObject notification = null;
        if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
            notification = mDevice.findObject(
                    new UiSelector()
                            .resourceId("android:id/text")
                            .className("android.widget.TextView")
                            .packageName("pylapp.smoothclicker.android")
                            .textContains(notificationText));
        } else {
            notification = mDevice.findObject(
                    new UiSelector()
                            .resourceId("android:id/text")
                            .className("android.widget.TextView")
                            .packageName("com.android.systemui")
                            .textContains(notificationText));
        }

        mDevice.openNotification();
        notification.waitForExists(2000);
        w(10000);
        assertTrue(notification.exists());

    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail( uonfe.getMessage() );
    }

}