Java Code Examples for android.support.test.uiautomator.UiObjectNotFoundException#printStackTrace()

The following examples show how to use android.support.test.uiautomator.UiObjectNotFoundException#printStackTrace() . 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: UIAnimatorTest.java    From Expert-Android-Programming with MIT License 7 votes vote down vote up
@Test
public void testChangeText_sameActivity() {


    UiObject skipButton = mDevice.findObject(new UiSelector()
            .text("SKIP").className("android.widget.TextView"));

    // Simulate a user-click on the OK button, if found.
    try {
        if (skipButton.exists() && skipButton.isEnabled()) {
                skipButton.click();
        }
    } catch (UiObjectNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test the stop button without having started the process
 *
 * <i>If the button to stop the click process is clicked, and no process was working, a snackbar with an error message ahs to be displayed/i>
 */
@Test
public void stopButtonWithoutStartedProcess(){

    l(this, "@Test stopButtonWithoutStartedProcess");

    try {

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

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

        // Check the snackbar
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.error_message_was_not_working);
        assertEquals(expectedString, snack.getText());

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

}
 
Example 3
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test the start button without having defined clicks
 *
 * <i>If the button to start the click process is clicked, and no point has been defined, a snackbar with an error message has to be displayed</i>
 */
@Test
public void startButtonWithoutDefinedPoints(){

    l(this, "@Test startButtonWithoutDefinedPoints");

    try {

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

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

        // Check the snackbar
        UiObject snack = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );

        String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.error_message_no_click_defined);
        assertEquals(expectedString, snack.getText());

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

}
 
Example 4
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
     * Test the click on the button for the "clean points" feature
     *
     * <i>If the button to clean points is clicked, the list of points has to be cleaned</i>
     * <i>If the button to clean points is clicked and no values has been changed, the values still remain the default ones</i>
     */
    @Test
    public void clickCleanPoints() {

        l(this, "@Test clickCleanPoints");

        try {

            // Get the menu item
            UiObject mi = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/action_clean_all")
            );

            w(5000); // If there is no wait, Espresso fails to get the floating action button

            // Bind the list
            fillSpinnerAsUser();

            // Click on the menu item
            mi.click();

            // Check if the values have been made empty
//            onView(withId(R.id.clickerActivityMainLayout)).perform(swipeUp());
//            onView(withId(R.id.sPointsToClick)).perform(click());
//            onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1)));

            // Test again to check if the default values remain
            mi.click();
            //           onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1)));

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

    }
 
Example 5
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test if the endless repeat checkbox changes modifies well the repeat field
 *
 * <i>If the check box for the endless repeat is checked, the repeat field is disabled</i>
 * <i>If the check box for the endless repeat is unchecked, the repeat field is enabled</i>
 */
@Test
public void changeRepeatOnCheckboxChanges(){

    l(this, "@Test changeRepeatOnCheckboxChanges");

    try {

        UiObject endlessCheckbox = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scEndlessRepeat")
        );

        UiObject repeatField = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etRepeat")
        );

        // Check and uncheck the switch
        for ( int i = 1; i <= 2; i++ ) {
            endlessCheckbox.click();
            if (endlessCheckbox.isChecked()) {
                assertFalse(repeatField.isEnabled());
            } else {
                assertTrue(repeatField.isEnabled());
            }
        }

    } 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 import feature with its snackbar
 *
 * <i>If the configuration is imported in the JSON files, a snackbar with a good message is displayed</i>
 */
@Test
public void importConfig(){

    l(this, "@Test importConfig");

    try {

        // Display the pop-up
        UiObject menu = mDevice.findObject(
                new UiSelector().className("android.widget.ImageView").description("Autres options") // FIXME Raw french string
        );
        menu.click();
        UiObject submenu = mDevice.findObject(
                new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_configuration))
        );
        submenu.click();
        UiObject menuItem = mDevice.findObject(
                new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_import))
        );
        menuItem.click();

        // Check the snackbar
        UiObject snackbar = mDevice.findObject(
                new UiSelector().className("android.widget.TextView")
                        .resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );
        assertTrue(snackbar.exists());
        assertEquals(InstrumentationRegistry.getTargetContext().getString(R.string.info_import_success), snackbar.getText());

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

}
 
Example 7
Source File: ItSettingsActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Opens the settings screen from the menu
 */
private void openSettingsScreenFromMenu(){

    try {

        // Clicks the three-points-icon
        UiObject menu = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.ImageView")
                        .packageName(PACKAGE_APP_PATH)
                                //.descriptionContains("Plus d'options") // WARNING FIXME French string used, use instead system R values
                        .descriptionContains("Autres options") // WARNING FIXME French string used, use instead system R values
        );
        menu.click();

        // Clicks on the settings item
        String s = InstrumentationRegistry.getTargetContext().getString(R.string.action_settings);
        UiObject itemParams = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.TextView")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId(PACKAGE_APP_PATH + ":id/title")
                        .text(s)
        );
        itemParams.click();
        w(1000);

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

}
 
Example 8
Source File: ItStandaloneModeDialog.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test the click on the cursor's right arrow
 *
 * <i>If the user clicks on then cursor's right arrow, the next item in the swipe cursor must be displayed</i>
 */
@Test
public void clickRightArrow(){

    l(this, "@Test clickRightArrow");

    try {

        // Click on the (not) green arrow
        for ( int i = 1; i <= steps; i++ ){
            // Get the selector
            UiObject rightArrow = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_layout_rightButton")
            );
            rightArrow.click();
        }

        // Check the last item
        String[] titles = InstrumentationRegistry.getTargetContext().getResources().getStringArray(R.array.standalone_mode_titles);
        String[] descs = InstrumentationRegistry.getTargetContext().getResources().getStringArray(R.array.standalone_mode_descriptions);
        String expectedLastItemTitle = titles[steps];
        String expectedLastItemDesc = descs[steps];

        UiObject lastItemTitle = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_content_title")
        );
        assertEquals(expectedLastItemTitle, lastItemTitle.getText());

        UiObject lastItemDesc = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_content_description")
        );
        assertEquals(expectedLastItemDesc, lastItemDesc.getText());

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

}
 
Example 9
Source File: ItSettingsActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * @param text - The text of the field to get
 * @param newValue - The new value
 */
private void resetFieldWithText( String text, String newValue ){

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

    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")
        );
        field.setText(newValue);
        // Confirm
        UiObject button = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.Button")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/button1")
        );
        button.click();
    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail(uonfe.getMessage());
    }

}
 
Example 10
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test the button for selecting points
 *
 * <i>If the button to select points is clicked, the activity to select points have to be launched</i>
 * <i>If in this activity we click on back, the main activity  must be displayed and the previous activity finished</i>
 */
@Test
public void selectPointsButton(){

    l(this, "@Test selectPointsButton");

    try {

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

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

        // UIAutomator seems to be useless about getting the current activity (deprecated methods)
        // so check if the enw activity's layout is displayed
        UiObject newActivityMainLayout = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/translucentMainView")
        );
        w(2000);
        assertTrue(newActivityMainLayout.exists());

        // Press back and check if we are in the previous activity (i.e. arc menu displayed)
        mDevice.pressBack();
        w(2000);
        assertTrue(arcMenu.exists());

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

}
 
Example 11
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 12
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 13
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 14
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 15
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 5 votes vote down vote up
/**
 * Test if the switch changes (for the start type) modifies well the delay field
 *
 * <i>If the switch for the start type is ON, the delay field is enabled.</i>
 * <i>If the switch for the start type is OFF, the delay field is disabled.</i>
 */
@Test
public void changeDelayOnSwitchChanges(){

    l(this, "@Test changeDelayOnSwitchChanges");

    try {

        UiObject startSwitch = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/sTypeOfStartDelayed")
        );

        UiObject delayField = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etDelay")
        );

        // Check and uncheck the switch
        for ( int i = 1; i <= 2; i++ ) {
            startSwitch.click();
            if (startSwitch.isChecked()) {
                assertTrue(delayField.isEnabled());
            } else {
                assertFalse(delayField.isEnabled());
            }
        }

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

}
 
Example 16
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() );
    }

}
 
Example 17
Source File: ItSettingsActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Test if the item about help in the Settings activity starts the intro screens activity
 */
@Test
public void help(){

    l(this, "@Test help");

    try {

        // Swipe to the bottom of the view to get the credits field in an inner preference screen
        UiObject list = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.ListView")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/list")
        );

        list.swipeUp(100);
        list.swipeUp(100);

        String innerPreferenceScreenTitle = InstrumentationRegistry.getTargetContext().getString(R.string.pref_about_subtitle);
        UiObject aboutRow = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.TextView")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/title")
                        .text(innerPreferenceScreenTitle)
        );
        aboutRow.click();

        // Clicks on the credits row
        String s = InstrumentationRegistry.getTargetContext().getString(R.string.pref_key_help_title);
        UiObject helpRow = mDevice.findObject(
                new UiSelector()
                        .className("android.widget.TextView")
                        .packageName(PACKAGE_APP_PATH)
                        .resourceId("android:id/title")
                        .text(s)
        );
        helpRow.click();
        w(1000);

        assertEquals(IntroScreensActivity.class.getSimpleName(), getActivityInstance().getClass().getSimpleName());

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

}
 
Example 18
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Tests the export feature with its snackbar and its dedicated action button
 *
 * <i>If the configuration is exported in the JSON files, a snackbar with a good message is displayed with an action button</i>
 */
@Test
public void exportConfig(){

    l(this, "@Test exportConfig");

    try {

        // Display the pop-up
        UiObject menu = mDevice.findObject(
                new UiSelector().className("android.widget.ImageView").description("Autres options") // FIXME Raw french string
        );
        menu.click();
        UiObject submenu = mDevice.findObject(
                new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_configuration))
        );
        submenu.click();
        UiObject menuItem = mDevice.findObject(
                new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_export))
        );
        menuItem.click();

        // Check the snackbar
        UiObject snackbar = mDevice.findObject(
                new UiSelector().className("android.widget.TextView")
                        .resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
        );
        assertTrue(snackbar.exists());
        assertEquals(InstrumentationRegistry.getTargetContext().getString(R.string.info_export_success), snackbar.getText());

        // Check the action button
        UiObject actionButton = mDevice.findObject(
                new UiSelector().className("android.widget.Button")
                        .resourceId(PACKAGE_APP_PATH + ":id/snackbar_action")
        );
        assertTrue(actionButton.exists());
        assertEquals(InstrumentationRegistry.getTargetContext().getString(R.string.snackbar_see_config_file), actionButton.getText());

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

}
 
Example 19
Source File: ItSettingsActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
     * Tests the seekbar for the threshold sued in the picture recognition system
     */
    @Test
    public void thresholdSeekBar(){

        l(this, "@Test thresholdSeekBar");

        try {

            // Swipe to the bottom of the view to get the seekbar
            UiObject list = mDevice.findObject(
                    new UiSelector()
                            .className("android.widget.ListView")
                            .packageName(PACKAGE_APP_PATH)
                            .resourceId("android:id/list")
            );
            list.swipeUp(100);
            list.swipeUp(100);

            // Get the seek bar
            UiObject seekBar = mDevice.findObject(
                    new UiSelector()
                            .className("android.widget.SeekBar")
                            .packageName(PACKAGE_APP_PATH)
            );

            // Swipe to the very right and check if we are at 100%
            seekBar.swipeRight(100);

            UiObject seekBarValue = mDevice.findObject(
                    new UiSelector()
                            .className("android.widget.TextView")
                            .packageName(PACKAGE_APP_PATH)
                            .resourceId(PACKAGE_APP_PATH + ":id/seekbar_value")
            );
            assertEquals( "10", seekBarValue.getText() );

            // Swipe to the very left and check if we are at 100%
            seekBar.swipeLeft(100);

            seekBarValue = mDevice.findObject(
                    new UiSelector()
                            .className("android.widget.TextView")
                            .packageName(PACKAGE_APP_PATH)
                            .resourceId(PACKAGE_APP_PATH+":id/seekbar_value")
            );
            assertEquals("1", seekBarValue.getText());
            w(1000);

//            // Click on the item to get the dialog to fill the seekbar: change the value but cancel
//            seekBarValue.click();
//            UiObject customValue = mDevice.findObject(
//                    new UiSelector()
//                            .className("android.widget.EditText")
//                            .packageName(PACKAGE_APP_PATH)
//                            .resourceId(PACKAGE_APP_PATH + ":id/customValue")
//            );
//            customValue.setText("42");
//            UiObject button = mDevice.findObject(
//                    new UiSelector()
//                            .className("android.widget.Button")
//                            .packageName(PACKAGE_APP_PATH)
//                            .resourceId(PACKAGE_APP_PATH + ":id/btn_cancel")
//            );
//            button.click();
//            assertEquals("1", seekBarValue.getText());
//            w(1000);
//
//            // Click on the item to get the dialog to fill the seekbar: change the value but apply
//            seekBarValue.click();
//            customValue = mDevice.findObject(
//                    new UiSelector()
//                            .className("android.widget.EditText")
//                            .packageName(PACKAGE_APP_PATH)
//                            .resourceId(PACKAGE_APP_PATH + ":id/customValue")
//            );
//            customValue.setText("23");
//            button = mDevice.findObject(
//                    new UiSelector()
//                            .className("android.widget.Button")
//                            .packageName(PACKAGE_APP_PATH)
//                            .resourceId(PACKAGE_APP_PATH + ":id/btn_apply")
//            );
//            button.click();
//            assertEquals("23", seekBarValue.getText());
//            w(1000);

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

    }
 
Example 20
Source File: ItStandaloneModeDialog.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Test the click on the cursor's left arrow
 *
 * <i>If the user clicks on then cursor's left arrow, the previous item in the swipe cursor must be displayed</i>
 */
@Test
public void clickLeftArrow(){

    l(this, "@Test clickLeftArrow");

    try {

        // Click on the arrow to be at the end of the cursor
        for ( int i = 1; i <= steps; i++ ){
            // Get the selector
            UiObject rightArrow = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_layout_rightButton")
            );
            rightArrow.click();
        }
        // Go backward
        for ( int i = 1; i <= steps; i++ ){
            // Get the selector
            UiObject leftArrow = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_layout_leftButton")
            );
            leftArrow.click();
        }

        // Check the first item
        String[] titles = InstrumentationRegistry.getTargetContext().getResources().getStringArray(R.array.standalone_mode_titles);
        String[] descs = InstrumentationRegistry.getTargetContext().getResources().getStringArray(R.array.standalone_mode_descriptions);
        String expectedFirstItemTitle = titles[0];
        String expectedFirstItemDesc = descs[0];

        UiObject lastItemTitle = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_content_title")
        );
        assertEquals(expectedFirstItemTitle, lastItemTitle.getText());

        UiObject lastItemDesc = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_content_description")
        );
        assertEquals(expectedFirstItemDesc, lastItemDesc.getText());

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

}