Java Code Examples for android.support.test.uiautomator.BySelector

The following are top voted examples for showing how to use android.support.test.uiautomator.BySelector. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ChimpCheck   File: WildCardManager.java   View source code 6 votes vote down vote up
public ArrayList<UiObject2> retrieveUiObject2s(BySelector topLevelSelector, BySelector childSelector, int depth) throws UiObjectNotFoundException {
    if (depth == 0) { return new ArrayList<>(); }
    ArrayList<UiObject2> currUiObjects = retrieveTopLevelUiObjects(topLevelSelector);
    ArrayList<UiObject2> baseUiObjects = new ArrayList<>();
    while (depth > 0 && currUiObjects.size() > 0) {
        ArrayList<UiObject2> tempUiObjects = new ArrayList<>();
        for(UiObject2 currUiObject: currUiObjects) {
            if (currUiObject.getChildCount() != 0) {
                tempUiObjects.addAll( retrieveChildUiObjects(currUiObject, childSelector) );
            } else {
                baseUiObjects.add( currUiObject );
            }
        }
        currUiObjects = tempUiObjects;
        depth--;
    }

    String str = "/***** Inferred Actionable UI Objects *****/\n";
    for(UiObject2 candidate: new HashSet<UiObject2>(baseUiObjects)) {
        str += "Found candidate: " + candidate.getClassName() + " " + candidate.getText() + " " + candidate.getContentDescription() + "\n";
    }
    str += "/******************************************/";
    Log.i("Chimp-wildCardManager",str);

    return baseUiObjects;
}
 
Example 2
Project: UIAutomatorWD   File: ElementController.java   View source code 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;
    }
    return selector;
}
 
Example 3
Project: android_packages_apps_tv   File: ParentalControlsTest.java   View source code 6 votes vote down vote up
/**
 * Prepare the need for testRatingDependentSelect.
 * 1. Turn on parental control if it's off.
 * 2. Make sure Japan rating system is selected.
 */
private void prepareParentalControl() {
    showParentalControl();
    switchParentalControl(R.string.option_toggle_parental_controls_off);
    // Show all rating systems.
    mSidePanelHelper.assertNavigateToItem(R.string.option_program_restrictions);
    mDevice.pressDPadCenter();
    BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
            R.string.option_program_restrictions);
    assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
    mSidePanelHelper.assertNavigateToItem(R.string.option_country_rating_systems);
    mDevice.pressDPadCenter();
    bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.option_country_rating_systems);
    assertWaitForCondition(mDevice,Until.hasObject(bySidePanel));
    mSidePanelHelper.assertNavigateToItem(R.string.option_see_all_rating_systems);
    mDevice.pressDPadCenter();
    // Make sure Japan rating system is selected.
    UiObject2 ratingSystemCheckBox = mSidePanelHelper.assertNavigateToItem("Japan")
            .findObject(ByResource.id(mTargetResources, R.id.check_box));
    if (!ratingSystemCheckBox.isChecked()) {
        mDevice.pressDPadCenter();
        getInstrumentation().waitForIdleSync();
    }
    mDevice.pressBack();
}
 
Example 4
Project: android_packages_apps_tv   File: ParentalControlsTest.java   View source code 6 votes vote down vote up
private void showParentalControl() {
    // Show menu and select parental controls.
    mMenuHelper.showMenu();
    mMenuHelper.assertPressOptionsSettings();
    assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
    mSidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls);
    mDevice.pressDPadCenter();
    // Enter pin code.
    DialogHelper dialogHelper = new DialogHelper(mDevice, mTargetResources);
    dialogHelper.assertWaitForPinDialogOpen();
    dialogHelper.enterPinCodes();
    dialogHelper.assertWaitForPinDialogClose();
    BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
            R.string.menu_parental_controls);
    assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
}
 
Example 5
Project: android_packages_apps_tv   File: PlayControlsRowViewTest.java   View source code 6 votes vote down vote up
public void testKeepPausedWhileParentalControlChange() {
    // Pause the playback.
    mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE);
    mMenuHelper.assertWaitForMenu();
    assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE);
    // Show parental controls fragment.
    mMenuHelper.assertPressOptionsSettings();
    assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
    mSidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls);
    mDevice.pressDPadCenter();
    DialogHelper dialogHelper = new DialogHelper(mDevice, mTargetResources);
    dialogHelper.assertWaitForPinDialogOpen();
    dialogHelper.enterPinCodes();
    dialogHelper.assertWaitForPinDialogClose();
    BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
            R.string.menu_parental_controls);
    assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
    mDevice.pressEnter();
    mDevice.pressEnter();
    mDevice.pressBack();
    mDevice.pressBack();
    // Return to the main menu.
    mMenuHelper.assertWaitForMenu();
    assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE);
}
 
Example 6
Project: android_packages_apps_tv   File: LiveChannelsUiDeviceHelper.java   View source code 6 votes vote down vote up
public void assertAppStarted() {
    Intent intent = mContext.getPackageManager()
            .getLaunchIntentForPackage(Constants.TV_APP_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);    // Clear out any previous instances
    mContext.startActivity(intent);
    // Wait for idle state before checking the channel banner because waitForCondition() has
    // timeout.
    mUiDevice.waitForIdle();
    // Make sure that the activity is resumed.
    waitForCondition(mUiDevice, Until.hasObject(Constants.TV_VIEW));

    Assert.assertTrue(Constants.TV_APP_PACKAGE + " did not start", mUiDevice
            .wait(Until.hasObject(By.pkg(Constants.TV_APP_PACKAGE).depth(0)),
                    APPLICATION_START_TIMEOUT_MSEC));
    BySelector welcome = ByResource.id(mTargetResources, com.android.tv.R.id.intro);
    if (mUiDevice.hasObject(welcome)) {
        Log.i(TAG, "Welcome screen shown. Clearing dialog by pressing back");
        mUiDevice.pressBack();
    }
}
 
Example 7
Project: appium-uiautomator2-server   File: UiObject2Element.java   View source code 6 votes vote down vote up
public Object getChild(final Object selector) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof UiSelector) {
        /**
         * We can't find the child element with UiSelector on UiObject2,
         * as an alternative creating UiObject with UiObject2's AccessibilityNodeInfo
         * and finding the child element on UiObject.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);

        UiSelector uiSelector = new UiSelector();
        CustomUiSelector customUiSelector = new CustomUiSelector(uiSelector);
        uiSelector = customUiSelector.getUiSelector(nodeInfo);
        UiObject uiObject = (UiObject)  CustomUiDevice.getInstance().findObject(uiSelector);
        AccessibilityNodeInfo uiObject_nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
        return uiObject.getChild((UiSelector) selector);
    }
    return element.findObject((BySelector) selector);
}
 
Example 8
Project: appium-uiautomator2-server   File: UiObject2Element.java   View source code 6 votes vote down vote up
public List<Object> getChildren(final Object selector, final By by) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof UiSelector) {
        /**
         * We can't find the child elements with UiSelector on UiObject2,
         * as an alternative creating UiObject with UiObject2's AccessibilityNodeInfo
         * and finding the child elements on UiObject.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);

        UiSelector uiSelector = new UiSelector();
        CustomUiSelector customUiSelector = new CustomUiSelector(uiSelector);
        uiSelector = customUiSelector.getUiSelector(nodeInfo);
        UiObject uiObject = (UiObject)  CustomUiDevice.getInstance().findObject(uiSelector);
        String id = UUID.randomUUID().toString();
        AndroidElement androidElement = getAndroidElement(id, uiObject, by);
        return androidElement.getChildren(selector, by);
    }
    return (List)element.findObjects((BySelector) selector);
}
 
Example 9
Project: ChimpCheck   File: Performer.java   View source code 5 votes vote down vote up
public Performer(String displayAction, ChimpDriver chimpDriver, ViewManager viewManager,
                 WildCardManager wildCardManager, BySelector wildCardSelector, BySelector wildCardChildSelector,
                 Matcher<View> userDefinedMatcher){
    this.displayAction = displayAction;
    this.chimpDriver = chimpDriver;
    this.viewManager = viewManager;
    this.wildCardManager = wildCardManager;
    this.wildCardSelector = wildCardSelector;
    this.wildCardChildSelector = wildCardChildSelector;
    this.userDefinedMatcher = userDefinedMatcher;
}
 
Example 10
Project: FlickLauncher   File: LauncherInstrumentationTestCase.java   View source code 5 votes vote down vote up
/**
 * Scrolls the {@param container} until it finds an object matching {@param condition}.
 * @return the matching object.
 */
protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) {
    do {
        UiObject2 widget = container.findObject(condition);
        if (widget != null) {
            return widget;
        }
    } while (container.scroll(Direction.DOWN, 1f));
    return container.findObject(condition);
}
 
Example 11
Project: UIAutomatorWD   File: ElementController.java   View source code 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 12
Project: UIAutomatorWD   File: Elements.java   View source code 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 13
Project: UIAutomatorWD   File: Elements.java   View source code 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 14
Project: SimpleUILauncher   File: LauncherInstrumentationTestCase.java   View source code 5 votes vote down vote up
/**
 * Scrolls the {@param container} until it finds an object matching {@param condition}.
 * @return the matching object.
 */
protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) {
    do {
        UiObject2 widget = container.findObject(condition);
        if (widget != null) {
            return widget;
        }
    } while (container.scroll(Direction.DOWN, 1f));
    return container.findObject(condition);
}
 
Example 15
Project: quickstart-android   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
@Test
public void testLaunchDialog() {
    // Floating action button
    BySelector fabSelector = By.res(APP_PACKAGE, "invite_button");

    // Click floating action button
    Assert.assertTrue(mDevice.wait(Until.hasObject(fabSelector), UI_TIMEOUT));
    mDevice.findObject(fabSelector).click();

    // Radio button in the account picker dialog
    BySelector firstAccountSelector = By.clazz(CLASS_CHECKED_TEXT_VIEW);

    // Wait for account picker (may not appear)
    if (mDevice.wait(Until.hasObject(firstAccountSelector), UI_TIMEOUT)) {
        // Click first account
        mDevice.findObjects(firstAccountSelector).get(0).click();

        // Button with the text "OK" (enabled)
        BySelector okButtonSelector = By.clazz(CLASS_BUTTON).text("OK").enabled(true);

        // Click OK on account picker
        Assert.assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }

    // Check that we can see the title and message
    String titleText = mContext.getString(R.string.invitation_title);
    String messageText = mContext.getString(R.string.invitation_message);

    BySelector titleTextSelector = By.text(titleText);
    BySelector messageTextSelector = By.text(messageText);

    assertTrue(mDevice.wait(Until.hasObject(titleTextSelector), UI_TIMEOUT));
    assertTrue(mDevice.wait(Until.hasObject(messageTextSelector), UI_TIMEOUT));

    // Back out of the dialog
    mDevice.pressBack();
}
 
Example 16
Project: android_packages_apps_tv   File: LiveChannelsAppTest.java   View source code 5 votes vote down vote up
public void testSettingsCancel() {
    mMenuHelper.assertPressOptionsSettings();
    BySelector byChannelSourcesSidePanel = mSidePanelHelper
            .bySidePanelTitled(R.string.settings_channel_source_item_customize_channels);
    assertWaitForCondition(mDevice, Until.hasObject(byChannelSourcesSidePanel));
    mDevice.pressBack();
    assertWaitForCondition(mDevice, Until.gone(byChannelSourcesSidePanel));
    assertHas(mDevice, Constants.MENU, false);
}
 
Example 17
Project: android_packages_apps_tv   File: LiveChannelsAppTest.java   View source code 5 votes vote down vote up
public void testClosedCaptionsCancel() {
    mMenuHelper.assertPressOptionsClosedCaptions();
    BySelector byClosedCaptionSidePanel = mSidePanelHelper
            .bySidePanelTitled(R.string.side_panel_title_closed_caption);
    assertWaitForCondition(mDevice, Until.hasObject(byClosedCaptionSidePanel));
    mDevice.pressBack();
    assertWaitForCondition(mDevice, Until.gone(byClosedCaptionSidePanel));
    assertHas(mDevice, Constants.MENU, false);
}
 
Example 18
Project: android_packages_apps_tv   File: LiveChannelsAppTest.java   View source code 5 votes vote down vote up
public void testDisplayModeCancel() {
    ChannelStateData data = new ChannelStateData();
    data.mTvTrackInfos.add(com.android.tv.testing.Constants.SVGA_VIDEO_TRACK);
    data.mSelectedVideoTrackId = com.android.tv.testing.Constants.SVGA_VIDEO_TRACK
            .getId();
    updateThenTune(data, TvTestInputConstants.CH_2);

    mMenuHelper.assertPressOptionsDisplayMode();
    BySelector byDisplayModeSidePanel = mSidePanelHelper
            .bySidePanelTitled(R.string.side_panel_title_display_mode);
    assertWaitForCondition(mDevice, Until.hasObject(byDisplayModeSidePanel));
    mDevice.pressBack();
    assertWaitForCondition(mDevice, Until.gone(byDisplayModeSidePanel));
    assertHas(mDevice, Constants.MENU, false);
}
 
Example 19
Project: android_packages_apps_tv   File: LiveChannelsAppTest.java   View source code 5 votes vote down vote up
public void testMultiAudioCancel() {
    ChannelStateData data = new ChannelStateData();
    data.mTvTrackInfos.add(com.android.tv.testing.Constants.GENERIC_AUDIO_TRACK);
    updateThenTune(data, TvTestInputConstants.CH_2);

    mMenuHelper.assertPressOptionsMultiAudio();
    BySelector byMultiAudioSidePanel = mSidePanelHelper
            .bySidePanelTitled(R.string.side_panel_title_multi_audio);
    assertWaitForCondition(mDevice, Until.hasObject(byMultiAudioSidePanel));
    mDevice.pressBack();
    assertWaitForCondition(mDevice, Until.gone(byMultiAudioSidePanel));
    assertHas(mDevice, Constants.MENU, false);
}
 
Example 20
Project: android_packages_apps_tv   File: ParentalControlsTest.java   View source code 5 votes vote down vote up
public void testRatingDependentSelect() {
    // Show ratings fragment.
    BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
            R.string.option_program_restrictions);
    assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
    mSidePanelHelper.assertNavigateToItem(R.string.option_ratings);
    mDevice.pressDPadCenter();
    // Block rating 6 and rating 12. Check if dependent select works well.
    bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.option_ratings);
    assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
    // Test on blocking and unblocking Japanese rating.
    int blockAge = 6;
    int unBlockAge = 12;
    int maxAge = 20;
    int minAge = 4;
    for (int age = minAge; age <= maxAge; age++) {
        UiObject2 ratingCheckBox = mSidePanelHelper.assertNavigateToItem(String.valueOf(age))
                .findObject(ByResource.id(mTargetResources, R.id.check_box));
        if (ratingCheckBox.isChecked()) {
            mDevice.pressDPadCenter();
        }
    }
    mSidePanelHelper.assertNavigateToItem(String.valueOf(blockAge));
    mDevice.pressDPadCenter();
    assertRatingViewIsChecked(minAge, maxAge, blockAge, true);
    mSidePanelHelper.assertNavigateToItem(String.valueOf(unBlockAge));
    mDevice.pressDPadCenter();
    assertRatingViewIsChecked(minAge, maxAge, unBlockAge, false);
    mDevice.pressBack();
    mDevice.pressBack();
    getInstrumentation().waitForIdleSync();
}
 
Example 21
Project: android_packages_apps_tv   File: ParentalControlsTest.java   View source code 5 votes vote down vote up
private void switchParentalControl(int oppositeStateResId) {
    BySelector bySidePanel = mSidePanelHelper.byViewText(oppositeStateResId);
    if (mDevice.hasObject(bySidePanel)) {
        mSidePanelHelper.assertNavigateToItem(oppositeStateResId);
        mDevice.pressDPadCenter();
        getInstrumentation().waitForIdleSync();
    }
}
 
Example 22
Project: android_packages_apps_tv   File: SidePanelHelper.java   View source code 5 votes vote down vote up
public UiObject2 assertNavigateToItem(String title) {
    BySelector sidePanelSelector = ByResource.id(mTargetResources, R.id.side_panel_list);
    UiObject2 sidePanelList = mUiDevice.findObject(sidePanelSelector);
    Assert.assertNotNull(sidePanelSelector + " not found", sidePanelList);

    return UiDeviceAsserts
            .assertNavigateTo(mUiDevice, sidePanelList, By.hasDescendant(By.text(title)),
                    Direction.DOWN);
}
 
Example 23
Project: android_packages_apps_tv   File: UiDeviceAsserts.java   View source code 5 votes vote down vote up
/**
 * Navigates through the focus items in a container returning the container child that has a
 * descendant matching the {@code selector}.
 * <p>
 * The navigation starts in the {@code direction} specified and
 * {@link Direction#reverse(Direction) reverses} once if needed. Fails if there is not a
 * focused
 * descendant, or if after completing both directions no focused child has a descendant
 * matching
 * {@code selector}.
 * <p>
 * Fails if the menu item can not be navigated to.
 *
 * @param uiDevice  the device under test.
 * @param container contains children to navigate over.
 * @param selector  the selector for the object to navigate to.
 * @param direction the direction to start navigating.
 * @return the object navigated to.
 */
public static UiObject2 assertNavigateTo(UiDevice uiDevice, UiObject2 container,
        BySelector selector, Direction direction) {
    int count = 0;
    while (count < 2) {
        BySelector hasFocusedDescendant = By.hasDescendant(FOCUSED_VIEW);
        UiObject2 focusedChild = null;
        SearchCondition<Boolean> untilHasFocusedDescendant = Until
                .hasObject(hasFocusedDescendant);

        boolean result = container.wait(untilHasFocusedDescendant,
                UiObject2Asserts.getAdjustedTimeout(Constants.MAX_SHOW_DELAY_MILLIS));
        if (!result) {
            // HACK: Try direction anyways because play control does not always have a
            // focused item.
            UiDeviceUtils.pressDpad(uiDevice, direction);
            UiObject2Asserts.assertWaitForCondition(container, untilHasFocusedDescendant);
        }

        for (UiObject2 c : container.getChildren()) {
            if (c.isFocused() || c.hasObject(hasFocusedDescendant)) {
                focusedChild = c;
                break;
            }
        }
        if (focusedChild == null) {
            Assert.fail("No focused item found in container " + container);
        }
        if (focusedChild.hasObject(selector)) {
            return focusedChild;
        }
        if (!UiObject2Utils.hasSiblingInDirection(focusedChild, direction)) {
            direction = Direction.reverse(direction);
            count++;
        }
        UiDeviceUtils.pressDpad(uiDevice, direction);
    }
    Assert.fail("Could not find item with  " + selector);
    return null;
}
 
Example 24
Project: appium-uiautomator2-server   File: ClassInstancePair.java   View source code 5 votes vote down vote up
public BySelector getSelector() {
    String androidClass = getAndroidClass();

    //TODO: remove below comments once code get reviewed
    //below commented line related to UiAutomator V1(bootstrap) version, as we don't have possibility
    // in V2 version to use instance, so directly returning By.clazz
    // new UiSelector().className(androidClass).instance(Integer.parseInt(instance));
    return By.clazz(androidClass);
}
 
Example 25
Project: appium-uiautomator2-server   File: KnownElements.java   View source code 5 votes vote down vote up
/**
 *
 * @param ui2BySelector, for finding {@link android.support.test.uiautomator.UiObject2} element derived using {@link By}
 * @param by, user provided selector criteria from appium client.
 * @return
 */
public static AndroidElement geElement(final BySelector ui2BySelector, By by) throws ElementNotFoundException, InvalidSelectorException, UiAutomator2Exception, ClassNotFoundException {
    Object ui2Object = getInstance().findObject(ui2BySelector);
    if (ui2Object == null) {
        throw new ElementNotFoundException();
    }
    String id = UUID.randomUUID().toString();
    AndroidElement androidElement = getAndroidElement(id, ui2Object, by);
    cache.put(androidElement.getId(), androidElement);
    return androidElement;
}
 
Example 26
Project: appium-uiautomator2-server   File: UiObjectElement.java   View source code 5 votes vote down vote up
public Object getChild(final Object selector) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof BySelector) {
        /**
         * We can't find the child element with BySelector on UiObject,
         * as an alternative creating UiObject2 with UiObject's AccessibilityNodeInfo
         * and finding the child element on UiObject2.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
        UiObject2 uiObject2 = (UiObject2) CustomUiDevice.getInstance().findObject(nodeInfo);
        return uiObject2.findObject((BySelector) selector);
    }
    return element.getChild((UiSelector) selector);
}
 
Example 27
Project: appium-uiautomator2-server   File: UiObjectElement.java   View source code 5 votes vote down vote up
public List<Object> getChildren(final Object selector, final By by) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof BySelector) {
        /**
         * We can't find the child elements with BySelector on UiObject,
         * as an alternative creating UiObject2 with UiObject's AccessibilityNodeInfo
         * and finding the child elements on UiObject2.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
        UiObject2 uiObject2 = (UiObject2) CustomUiDevice.getInstance().findObject(nodeInfo);
        return (List)uiObject2.findObjects((BySelector) selector);
    }
    return (List)this.getChildElements((UiSelector) selector);
}
 
Example 28
Project: GCM-Sample   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Click sign-in button, select account at account selector, accept consent screen, and
 * check that in the end the app is in the signed-in state.
 */
private void signInTest() {
    // Sign-in button (enabled)
    BySelector signInButtonSelector = By.clazz(CLASS_BUTTON).textContains("Sign in").enabled(true);

    // Click Sign-in button (must be enabled)
    assertTrue(mDevice.wait(Until.hasObject(signInButtonSelector), UI_TIMEOUT));
    mDevice.findObject(signInButtonSelector).click();

    // Radio button in the account picker dialog
    BySelector firstAccountSelector = By.clazz(CLASS_CHECKED_TEXT_VIEW);

    // Wait for account picker (may not appear)
    if (mDevice.wait(Until.hasObject(firstAccountSelector), UI_TIMEOUT)) {
        // Click first account
        mDevice.findObjects(firstAccountSelector).get(0).click();

        // Button with the text "OK" (enabled)
        BySelector okButtonSelector = By.clazz(CLASS_BUTTON).text("OK").enabled(true);

        // Click OK on account picker
        assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }

    // The Google Play Services consent screen accept button
    BySelector acceptButtonSelector = By.res(GMS_PACKAGE, "accept_button");

    // Accept consent screen and click OK button (this also may not appear)
    if (mDevice.wait(Until.hasObject(acceptButtonSelector), UI_TIMEOUT)) {
        mDevice.findObject(acceptButtonSelector).click();
    }

    // Check that the UI shows signed-in state
    assertTrue(isSignedIn());
}
 
Example 29
Project: GCM-Sample   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Click the disconnect button, check the app is in the signed-out state.
 */
private void disconnectTest() {
    // Disconnect button (enabled)
    String disconnectText = mContext.getString(R.string.disconnect);
    BySelector disconnectSelector = By.clazz(CLASS_BUTTON).text(disconnectText).enabled(true);

    // Click disconnect button
    assertTrue(mDevice.wait(Until.hasObject(disconnectSelector), UI_TIMEOUT));
    mDevice.findObject(disconnectSelector).click();

    // Check that we get to signed-out state
    String signedOutText = mContext.getString(R.string.signed_out);
    BySelector signedOutTextSelector = By.text(signedOutText);
    assertTrue(mDevice.wait(Until.hasObject(signedOutTextSelector), UI_TIMEOUT));
}
 
Example 30
Project: GCM-Sample   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Checks the UI for text containing "Signed in" to determine if the user is signed in.
 */
private boolean isSignedIn() {
    // Wait until we have an enabled button on screen
    mDevice.wait(Until.hasObject(By.clazz(CLASS_BUTTON).enabled(true)), UI_TIMEOUT);

    String signedInText = mContext.getString(R.string.signed_in_fmt, "");
    BySelector signedInTextSelector = By.textContains(signedInText);
    return mDevice.wait(Until.hasObject(signedInTextSelector), UI_TIMEOUT);
}
 
Example 31
Project: GCM-Sample   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
@Test
public void testLaunchDialog() {
    // Floating action button
    BySelector fabSelector = By.res(APP_PACKAGE, "invite_button");

    // Click floating action button
    Assert.assertTrue(mDevice.wait(Until.hasObject(fabSelector), UI_TIMEOUT));
    mDevice.findObject(fabSelector).click();

    // Radio button in the account picker dialog
    BySelector firstAccountSelector = By.clazz(CLASS_CHECKED_TEXT_VIEW);

    // Wait for account picker (may not appear)
    if (mDevice.wait(Until.hasObject(firstAccountSelector), UI_TIMEOUT)) {
        // Click first account
        mDevice.findObjects(firstAccountSelector).get(0).click();

        // Button with the text "OK" (enabled)
        BySelector okButtonSelector = By.clazz(CLASS_BUTTON).text("OK").enabled(true);

        // Click OK on account picker
        Assert.assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }

    // Check that we can see the title and message
    String titleText = mContext.getString(R.string.invitation_title);
    String messageText = mContext.getString(R.string.invitation_message);

    BySelector titleTextSelector = By.text(titleText);
    BySelector messageTextSelector = By.text(messageText);

    assertTrue(mDevice.wait(Until.hasObject(titleTextSelector), UI_TIMEOUT));
    assertTrue(mDevice.wait(Until.hasObject(messageTextSelector), UI_TIMEOUT));

    // Back out of the dialog
    mDevice.pressBack();
}
 
Example 32
Project: google-services   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Click sign-in button, select account at account selector, accept consent screen, and
 * check that in the end the app is in the signed-in state.
 */
private void signInTest() {
    // Sign-in button (enabled)
    BySelector signInButtonSelector = By.clazz(CLASS_BUTTON).textContains("Sign in").enabled(true);

    // Click Sign-in button (must be enabled)
    assertTrue(mDevice.wait(Until.hasObject(signInButtonSelector), UI_TIMEOUT));
    mDevice.findObject(signInButtonSelector).click();

    // Radio button in the account picker dialog
    BySelector firstAccountSelector = By.clazz(CLASS_CHECKED_TEXT_VIEW);

    // Wait for account picker (may not appear)
    if (mDevice.wait(Until.hasObject(firstAccountSelector), UI_TIMEOUT)) {
        // Click first account
        mDevice.findObjects(firstAccountSelector).get(0).click();

        // Button with the text "OK" (enabled)
        BySelector okButtonSelector = By.clazz(CLASS_BUTTON).text("OK").enabled(true);

        // Click OK on account picker
        assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }

    // The Google Play Services consent screen accept button
    BySelector acceptButtonSelector = By.res(GMS_PACKAGE, "accept_button");

    // Accept consent screen and click OK button (this also may not appear)
    if (mDevice.wait(Until.hasObject(acceptButtonSelector), UI_TIMEOUT)) {
        mDevice.findObject(acceptButtonSelector).click();
    }

    // Check that the UI shows signed-in state
    assertTrue(isSignedIn());
}
 
Example 33
Project: google-services   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Click the disconnect button, check the app is in the signed-out state.
 */
private void disconnectTest() {
    // Disconnect button (enabled)
    String disconnectText = mContext.getString(R.string.disconnect);
    BySelector disconnectSelector = By.clazz(CLASS_BUTTON).text(disconnectText).enabled(true);

    // Click disconnect button
    assertTrue(mDevice.wait(Until.hasObject(disconnectSelector), UI_TIMEOUT));
    mDevice.findObject(disconnectSelector).click();

    // Check that we get to signed-out state
    String signedOutText = mContext.getString(R.string.signed_out);
    BySelector signedOutTextSelector = By.text(signedOutText);
    assertTrue(mDevice.wait(Until.hasObject(signedOutTextSelector), UI_TIMEOUT));
}
 
Example 34
Project: google-services   File: UiAutomatorTest.java   View source code 5 votes vote down vote up
/**
 * Checks the UI for text containing "Signed in" to determine if the user is signed in.
 */
private boolean isSignedIn() {
    // Wait until we have an enabled button on screen
    mDevice.wait(Until.hasObject(By.clazz(CLASS_BUTTON).enabled(true)), UI_TIMEOUT);

    String signedInText = mContext.getString(R.string.signed_in_fmt, "");
    BySelector signedInTextSelector = By.textContains(signedInText);
    return mDevice.wait(Until.hasObject(signedInTextSelector), UI_TIMEOUT);
}
 
Example 35
Project: device-automator   File: UiObjectMatcher.java   View source code 5 votes vote down vote up
/**
 * Find a view based on the prefixed text in the view. The matching is case-insensitive.
 *
 * @param text Prefix to search for.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withTextStartingWith(String text, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .textStartsWith(text);
    BySelector bySelector = By.textStartsWith(text);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 36
Project: device-automator   File: UiObjectMatcher.java   View source code 5 votes vote down vote up
/**
 * Find a view based on the text contained within the view. The matching is case-sensitive.
 *
 * @param text Text to search for inside a view.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withTextContaining(String text, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .textContains(text);
    BySelector bySelector = By.textContains(text);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 37
Project: device-automator   File: UiObjectMatcher.java   View source code 5 votes vote down vote up
/**
 * Find a view based on the exact text contained within the view. Matching is case-insensitive.
 *
 * @param text Exact text in the view.
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withText(String text, Class klass) {
    Pattern pattern = Pattern.compile("(?i)" + Pattern.quote(text));

    UiSelector uiSelector = new UiSelector()
            .textMatches(pattern.pattern());
    BySelector bySelector = By.text(pattern);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 38
Project: device-automator   File: UiObjectMatcher.java   View source code 5 votes vote down vote up
/**
 * Find a view based on the resource id. Resource ids should be the fully qualified id,
 * ex: com.android.browser:id/url
 *
 * @param id The fully qualified id of the view, ex: com.android.browser:id/url
 * @param klass Expected class of the view.
 * @return
 */
public static UiObjectMatcher withResourceId(String id, Class klass) {
    UiSelector uiSelector = new UiSelector()
            .resourceId(id);
    BySelector bySelector = By.res(id);

    if (klass != null) {
        uiSelector = uiSelector.className(klass);
        bySelector.clazz(klass);
    }

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 39
Project: device-automator   File: UiObjectMatcher.java   View source code 5 votes vote down vote up
/**
 * Find a view based on it's class.
 *
 * @param klass The class of the view to find.
 * @return
 */
public static UiObjectMatcher withClass(Class klass) {
    UiSelector uiSelector = new UiSelector()
            .className(klass);
    BySelector bySelector = By.clazz(klass);

    return new UiObjectMatcher(uiSelector, bySelector);
}
 
Example 40
Project: ChimpCheck   File: SwipePerformer.java   View source code 4 votes vote down vote up
public SwipePerformer(ChimpDriver chimpDriver, ViewManager viewManager,
                     WildCardManager wildCardManager, BySelector wildCardSelector, BySelector wildCardChildSelector,
                     Matcher<View> userDefinedMatcher) {
    super("Swipe", chimpDriver, viewManager, wildCardManager, wildCardSelector, wildCardChildSelector,userDefinedMatcher);
}