android.support.test.uiautomator.UiSelector Java Examples

The following examples show how to use android.support.test.uiautomator.UiSelector. 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: UIUtil.java    From SweetBlue with GNU General Public License v3.0 6 votes vote down vote up
public static boolean viewExistsContains(UiDevice device, String... textToMatch) throws UiObjectNotFoundException
{
    if (textToMatch == null || textToMatch.length < 1)
    {
        return false;
    }
    UiObject view;
    boolean contains = false;
    for (int i = 0; i < textToMatch.length; i++)
    {
        view = device.findObject(new UiSelector().textContains(textToMatch[i]));
        contains = view.exists();
        if (contains) return true;
    }
    return false;
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: ItStandaloneModeDialog.java    From SmoothClicker with MIT License 6 votes vote down vote up
/**
 * Opens the standalone mode dialog
 */
private void openStandaloneModeDialog(){
    try {
        // Display the pop-up
        UiObject menu = mDevice.findObject(
                new UiSelector().className("android.widget.ImageView")
                        //.description("Plus d'options") // FIXME Raw french string
                        .description("Autres options") // WARNING FIXME French string used, use instead system R values
        );
        menu.click();
        UiObject menuItem = mDevice.findObject(
                new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_standalone))
        );
        menuItem.click();
    } catch ( UiObjectNotFoundException uinfe ){
        uinfe.printStackTrace();
        fail(uinfe.getMessage());
    }
}
 
Example #9
Source File: MainActivityTest.java    From android-testing-guide with MIT License 6 votes vote down vote up
@Ignore
@Test
public void testUiAutomatorAPI() throws UiObjectNotFoundException, InterruptedException {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    UiSelector editTextSelector = new UiSelector().className("android.widget.EditText").text("this is a test").focusable(true);
    UiObject editTextWidget = device.findObject(editTextSelector);
    editTextWidget.setText("this is new text");

    Thread.sleep(2000);

    UiSelector buttonSelector = new UiSelector().className("android.widget.Button").text("CLICK ME").clickable(true);
    UiObject buttonWidget = device.findObject(buttonSelector);
    buttonWidget.click();

    Thread.sleep(2000);
}
 
Example #10
Source File: UiHelper.java    From AppCrawler with Apache License 2.0 6 votes vote down vote up
public static void inputRandomTextToEditText() {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject edit = null;
    int i = 0;
    do {
        edit = null;
        edit = device.findObject(new UiSelector().className("android.widget.EditText").instance(i++));
        if (edit != null && edit.exists()) {
            try {
                Random rand = new Random();
                String text = Config.RANDOM_TEXT[rand.nextInt(Config.RANDOM_TEXT.length - 1)];
                edit.setText(text);
            } catch (UiObjectNotFoundException e) {
                // Don't worry
            }
        }
    } while (edit != null && edit.exists());
}
 
Example #11
Source File: AutomatorServiceImpl.java    From android-uiautomator-server with MIT License 6 votes vote down vote up
/**
 * Register a ClickUiObjectWatcher
 *
 * @param name       Watcher name
 * @param conditions If all UiObject in the conditions match, the watcher should be triggered.
 * @param target     The target UiObject should be clicked if all conditions match.
 */
@Override
public void registerClickUiObjectWatcher(String name, Selector[] conditions, Selector target) {
    synchronized (watchers) {
        if (watchers.contains(name)) {
            device.removeWatcher(name);
            watchers.remove(name);
        }

        UiSelector[] selectors = new UiSelector[conditions.length];
        for (int i = 0; i < conditions.length; i++) {
            selectors[i] = conditions[i].toUiSelector();
        }
        device.registerWatcher(name, new ClickUiObjectWatcher(selectors, target.toUiSelector()));
        watchers.add(name);
    }
}
 
Example #12
Source File: AutomatorServiceImpl.java    From android-uiautomator-server with MIT License 6 votes vote down vote up
/**
 * Register a PressKeysWatcher
 *
 * @param name       Watcher name
 * @param conditions If all UiObject in the conditions match, the watcher should be triggered.
 * @param keys       All keys will be pressed in sequence.
 */
@Override
public void registerPressKeyskWatcher(String name, Selector[] conditions, String[] keys) {
    synchronized (watchers) {
        if (watchers.contains(name)) {
            device.removeWatcher(name);
            watchers.remove(name);
        }

        UiSelector[] selectors = new UiSelector[conditions.length];
        for (int i = 0; i < conditions.length; i++) {
            selectors[i] = conditions[i].toUiSelector();
        }
        device.registerWatcher(name, new PressKeysWatcher(selectors, keys));
        watchers.add(name);
    }
}
 
Example #13
Source File: PermissionGranter.java    From mobile-android-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void allowPermissionsIfNeeded() {
    try {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector()
                    .clickable(true)
                    .checkable(false)
                    .index(GRANT_BUTTON_INDEX));

            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }

    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
 
Example #14
Source File: UIUtil.java    From SweetBlue with GNU General Public License v3.0 6 votes vote down vote up
public static boolean viewExistsContains(UiDevice device, String... textToMatch) throws UiObjectNotFoundException
{
    if (textToMatch == null || textToMatch.length < 1)
    {
        return false;
    }
    UiObject view;
    boolean contains = false;
    for (int i = 0; i < textToMatch.length; i++)
    {
        view = device.findObject(new UiSelector().textContains(textToMatch[i]));
        contains = view.exists();
        if (contains) return true;
    }
    return false;
}
 
Example #15
Source File: BasicUITests.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
private void allowPermissionsIfNeeded() {
    if (Build.VERSION.SDK_INT >= 23) {
        // Initialize UiDevice instance
        UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

        // notice that we typically receive 2-3 permission prompts, hence the loop
        while (true) {
            UiObject allowPermissions = uiDevice.findObject(new UiSelector().text("Allow"));
            if (allowPermissions.exists()) {
                try {
                    allowPermissions.click();
                } catch (UiObjectNotFoundException e) {
                    e.printStackTrace();
                    Log.e(TAG, "There is no permissions dialog to interact with ");
                }
            } else {
                break;
            }
        }
    }
}
 
Example #16
Source File: PermissionGranter.java    From mobile-android-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void allowPermissionsIfNeeded() {
    try {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiSelector selector = new UiSelector()
                    .clickable(true)
                    .checkable(false)
                    .index(GRANT_BUTTON_INDEX);
            UiObject allowPermissions = device.findObject(selector);

            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }

    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
 
Example #17
Source File: AutomatorServiceImpl.java    From android-uiautomator-server with MIT License 6 votes vote down vote up
/**
 * Get the count of the UiObject instances by the selector
 *
 * @param obj the selector of the ui object
 * @return the count of instances.
 */
@Override
public int count(Selector obj) {
    if ((obj.getMask() & Selector.MASK_INSTANCE) > 0) {
        if (device.findObject(obj.toUiSelector()).exists()) return 1;
        else return 0;
    } else {
        UiSelector sel = obj.toUiSelector();
        if (!device.findObject(sel).exists()) return 0;
        int low = 1;
        int high = 2;
        sel = sel.instance(high - 1);
        while (device.findObject(sel).exists()) {
            low = high;
            high = high * 2;
            sel = sel.instance(high - 1);
        }
        while (high > low + 1) {
            int mid = (low + high) / 2;
            sel = sel.instance(mid - 1);
            if (device.findObject(sel).exists()) low = mid;
            else high = mid;
        }
        return low;
    }
}
 
Example #18
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 #19
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 #20
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 #21
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 #22
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 #23
Source File: MainEndToEndTest.java    From Building-Professional-Android-Applications with MIT License 5 votes vote down vote up
@Test
public void it_should_be_possible_to_open_add_new_item_window() throws UiObjectNotFoundException {
    mDevice.findObject(
            new UiSelector()
                    .descriptionContains("Add New Stock Button")
    ).click();

    UiObject2 result = mDevice.findObject(
            By.res(TARGET_PACKAGE, "portfolio_addnew_symbol")
    );

    assertThat(result.getText(), is("GOOG"));
}
 
Example #24
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 #25
Source File: PermissionGranter.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 5 votes vote down vote up
public static void allowPermissionsIfNeeded(Activity activity, String permissionNeeded) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(activity, permissionNeeded)) {
            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector().clickable(true).index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }
    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
 
Example #26
Source File: LoginActivityTest.java    From twittererer with Apache License 2.0 5 votes vote down vote up
@Test
public void loginCancelled() throws UiObjectNotFoundException {
    UiObject loginButton = device.findObject(new UiSelector().text(LOGIN_BUTTON_TEXT));
    loginButton.clickAndWaitForNewWindow(TIMEOUT);

    // TODO: this fails to find the text on API 24+ (Android 7+) for some reason
    UiObject allowButton = device.findObject(new UiSelector().text("Cancel"));
    allowButton.clickAndWaitForNewWindow(TIMEOUT);

    loginButton = device.findObject(new UiSelector().text(LOGIN_BUTTON_TEXT));
    assertThat(loginButton, notNullValue());
}
 
Example #27
Source File: ComprehensionTest.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void allowPermissionsIfNeeded() {
    if (Build.VERSION.SDK_INT >= 23) {
        UiDevice device = UiDevice.getInstance(getInstrumentation());
        UiObject allowPermissions = device.findObject(new UiSelector().text("Allow"));
        if (allowPermissions.exists()) {
            try {
                allowPermissions.click();
            } catch (UiObjectNotFoundException e) {
            }
        }
    }
}
 
Example #28
Source File: LoginActivityTest.java    From twittererer with Apache License 2.0 5 votes vote down vote up
@Test
public void loginSuccessful() throws UiObjectNotFoundException {
    UiObject loginButton = device.findObject(new UiSelector().text(LOGIN_BUTTON_TEXT));
    loginButton.clickAndWaitForNewWindow(TIMEOUT);

    // TODO: this fails to find the text on API 24+ (Android 7+) for some reason
    UiObject allowButton = device.findObject(new UiSelector().text("Allow"));
    allowButton.clickAndWaitForNewWindow(TIMEOUT);

    UiObject activityTitle = device.findObject(new UiSelector()
            .text(getInstrumentation().getTargetContext().getString(R.string.title_activity_twitter_feed)));
    assertThat(activityTitle, notNullValue());
}
 
Example #29
Source File: SignInActivityTest.java    From ribot-app-android with Apache License 2.0 5 votes vote down vote up
private void allowPermissionsIfNeeded()  {
    if (Build.VERSION.SDK_INT >= 23) {
        UiObject allowPermissions = mDevice.findObject(new UiSelector().text("Allow"));
        if (allowPermissions.exists()) {
            try {
                allowPermissions.click();
            } catch (UiObjectNotFoundException e) {
                Timber.w(e, "There is no permissions dialog to interact with ");
            }
        }
    }
}
 
Example #30
Source File: UIUtil.java    From SweetBlue with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clicks a button with the given text. This will try to find the widget exactly as the text is given, and
 * will try upper casing the text if it is not found.
 */
public static void clickButton(UiDevice device, String buttonText) throws UiObjectNotFoundException
{
    UiObject accept = device.findObject(new UiSelector().text(buttonText));
    if (accept.exists())
    {
        accept.click();
        return;
    }
    accept = device.findObject(new UiSelector().text(buttonText.toUpperCase()));
    accept.click();
}