androidx.test.uiautomator.UiSelector Java Examples

The following examples show how to use androidx.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: URLExceptionTest.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void removeAllExceptionsTest() throws UiObjectNotFoundException {
    addException(site);

    OpenExceptionsFragment();

    mDevice.waitForIdle();
    onView(withId(R.id.removeAllExceptions))
            .perform(click());

    mDevice.waitForIdle();

    // Should be in main menu
    onView(withText("Privacy & Security"))
            .check(matches(isDisplayed()));

    /* change locale to non-english in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(exceptionsTitle);

    onView(withText("Exceptions"))
            .check(matches(isDisplayed()))
            .check(matches(not(isEnabled())));
}
 
Example #2
Source File: BrowserSignInTest.java    From samples-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testA_cancelSignIn() throws UiObjectNotFoundException {
    getProgressBar().waitUntilGone(NETWORK_TIMEOUT);
    onView(withId(R.id.clear_data_btn)).check(matches(isDisplayed()));
    onView(withId(R.id.clear_data_btn)).perform(click());
    onView(withId(R.id.browser_sign_in_btn)).check(matches(isDisplayed()));

    onView(withId(R.id.browser_sign_in_btn)).perform(click());
    mDevice.wait(Until.findObject(By.pkg(CHROME_STABLE)), TRANSITION_TIMEOUT);

    UiSelector selector = new UiSelector();
    UiObject closeBrowser = mDevice.findObject(selector.resourceId(ID_CLOSE_BROWSER));
    closeBrowser.click();

    mDevice.wait(Until.findObject(By.pkg(SAMPLE_APP)), TRANSITION_TIMEOUT);
    onView(withText(R.string.auth_canceled)).inRoot(new ToastMatcher()).check(matches(isDisplayed()));
}
 
Example #3
Source File: BrowserSignInTest.java    From samples-android with Apache License 2.0 6 votes vote down vote up
private void customTabInteraction(boolean enterUserName) throws UiObjectNotFoundException {
    mDevice.wait(Until.findObject(By.pkg(CHROME_STABLE)), TRANSITION_TIMEOUT);
    acceptChromePrivacyOption();
    UiSelector selector = new UiSelector();
    if (enterUserName) {
        UiObject username = mDevice.findObject(selector.resourceId(ID_USERNAME));
        username.setText(USERNAME);
    }
    UiObject password = mDevice.findObject(selector.resourceId(ID_PASSWORD));
    password.setText(PASSWORD);
    UiObject signIn = mDevice.findObject(selector.resourceId(ID_SUBMIT));
    signIn.click();
    mDevice.wait(Until.findObject(By.pkg(SAMPLE_APP)), TRANSITION_TIMEOUT);
    //wait for token exchange
    getProgressBar().waitUntilGone(NETWORK_TIMEOUT);
}
 
Example #4
Source File: AutomatorActionTest.java    From device-automator with MIT License 6 votes vote down vote up
@Test(timeout = 1000)
public void perform() throws InterruptedException {
    final UiSelector expectedSelector = mock(UiSelector.class);
    final UiObject expectedObject = mock(UiObject.class);
    final CountDownLatch latch = new CountDownLatch(1);
    AutomatorAction action = new AutomatorAction() {
        @Override
        public void wrappedPerform(UiSelector selector, UiObject object) throws UiObjectNotFoundException {
            assertEquals(expectedSelector, selector);
            assertEquals(expectedObject, object);
            latch.countDown();
        }
    };

    action.perform(expectedSelector, expectedObject);

    latch.await();
}
 
Example #5
Source File: BrowserScreenScreenshots.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
private void takeScreenshotOfFindDialog() throws Exception {
    UiObject findinpageMenuItem = device.findObject(new UiSelector()
            .resourceId(TestHelper.getAppName() + ":id/find_in_page")
            .enabled(true));
    UiObject findinpageCloseBtn = device.findObject(new UiSelector()
            .resourceId(TestHelper.getAppName() + ":id/close_find_in_page")
            .enabled(true));

    TestHelper.menuButton.perform(click());
    findinpageMenuItem.waitForExists(waitingTime);
    findinpageMenuItem.click();

    findinpageCloseBtn.waitForExists(waitingTime);
    Screengrab.screenshot("Find_In_Page_Dialog");
    findinpageCloseBtn.click();
}
 
Example #6
Source File: FindElement.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
@Nullable
private Object findElement(By by) throws UiAutomator2Exception, UiObjectNotFoundException {
    refreshAccessibilityCache();
    if (by instanceof ById) {
        String locator = rewriteIdLocator((ById) by);
        return CustomUiDevice.getInstance().findObject(androidx.test.uiautomator.By.res(locator));
    } else if (by instanceof By.ByAccessibilityId) {
        return CustomUiDevice.getInstance().findObject(androidx.test.uiautomator.By.desc(by.getElementLocator()));
    } else if (by instanceof ByClass) {
        return CustomUiDevice.getInstance().findObject(androidx.test.uiautomator.By.clazz(by.getElementLocator()));
    } else if (by instanceof By.ByXPath) {
        final NodeInfoList matchedNodes = getXPathNodeMatch(by.getElementLocator(), null, false);
        if (matchedNodes.isEmpty()) {
            throw new ElementNotFoundException();
        }
        return CustomUiDevice.getInstance().findObject(matchedNodes);
    } else if (by instanceof By.ByAndroidUiAutomator) {
        UiSelector selector = toSelector(by.getElementLocator());
        if (selector == null) {
            throw new UiSelectorSyntaxException(by.getElementLocator(), "");
        }
        return CustomUiDevice.getInstance().findObject(selector);
    }
    String msg = String.format("By locator %s is currently not supported!", by.getClass().getSimpleName());
    throw new UnsupportedOperationException(msg);
}
 
Example #7
Source File: UiObjectElement.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
@Override
public List<?> getChildren(final Object selector, final By by) throws UiObjectNotFoundException {
    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);
        if (uiObject2 == null) {
            throw new ElementNotFoundException();
        }
        return uiObject2.findObjects((BySelector) selector);
    }
    return this.getChildElements((UiSelector) selector);
}
 
Example #8
Source File: UiObjectElement.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getChild(final Object selector) throws UiObjectNotFoundException {
    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);
        Object uiObject2 = CustomUiDevice.getInstance().findObject(nodeInfo);
        return (uiObject2 instanceof UiObject2)
                ? ((UiObject2) uiObject2).findObject((BySelector) selector) : null;
    }
    return element.getChild((UiSelector) selector);
}
 
Example #9
Source File: UiObject2Element.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
@Override
public List<?> getChildren(final Object selector, final By by) throws UiObjectNotFoundException {
    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, true, by, getContextId());
        return androidElement.getChildren(selector, by);
    }
    return element.findObjects((BySelector) selector);
}
 
Example #10
Source File: UiObject2Element.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getChild(final Object selector) throws UiObjectNotFoundException {
    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);
        Object uiObject = CustomUiDevice.getInstance().findObject(uiSelector);
        if (uiObject instanceof UiObject) {
            AccessibilityNodeInfoGetter.fromUiObject(element);
            return ((UiObject) uiObject).getChild((UiSelector) selector);
        }
        return null;
    }
    return element.findObject((BySelector) selector);
}
 
Example #11
Source File: CustomUiSelector.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
/**
 * @param node
 * @return UiSelector object, based on UiAutomationElement attributes
 */
public UiSelector getUiSelector(AccessibilityNodeInfo node) {
    UiAutomationElement uiAutomationElement = UiAutomationElement.getCachedElement(node, getCachedWindowRoots());
    if (uiAutomationElement == null) {
        throw new IllegalArgumentException(String.format("The '%s' node is not found in the cache", node));
    }
    put(Attribute.PACKAGE, uiAutomationElement.getPackageName());
    put(Attribute.CLASS, uiAutomationElement.getClassName());
    // For proper selector matching it is important to not replace nulls with empty strings
    put(Attribute.TEXT, uiAutomationElement.getOriginalText());
    put(Attribute.CONTENT_DESC, uiAutomationElement.getContentDescription());
    put(Attribute.RESOURCE_ID, uiAutomationElement.getResourceId());
    put(Attribute.CHECKABLE, uiAutomationElement.isCheckable());
    put(Attribute.CHECKED, uiAutomationElement.isChecked());
    put(Attribute.CLICKABLE, uiAutomationElement.isClickable());
    put(Attribute.ENABLED, uiAutomationElement.isEnabled());
    put(Attribute.FOCUSABLE, uiAutomationElement.isFocusable());
    put(Attribute.FOCUSED, uiAutomationElement.isFocused());
    put(Attribute.LONG_CLICKABLE, uiAutomationElement.isLongClickable());
    put(Attribute.PASSWORD, uiAutomationElement.isPassword());
    put(Attribute.SCROLLABLE, uiAutomationElement.isScrollable());
    put(Attribute.SELECTED, uiAutomationElement.isSelected());
    put(Attribute.INDEX, uiAutomationElement.getIndex());

    return selector;
}
 
Example #12
Source File: UiSelectorParser.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
public UiSelector parse() throws UiSelectorSyntaxException, UiObjectNotFoundException {
    resetCurrentIndex();
    consumeConstructor();
    while (hasMoreDataToParse()) {
        consumePeriod();
        final Object result = consumeMethodCall();
        if (!(result instanceof UiSelector)) {
            throw new UiSelectorSyntaxException(expression.toString(),
                    String.format("Unsupported return value type:`%s`. " +
                                    "Only methods with return type `UiSelector` are supported.",
                            result.getClass().getSimpleName()));
        }
        setTarget((UiSelector) result);
    }
    return getTarget();
}
 
Example #13
Source File: ShareWebsiteTest.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void ShareWebsiteTest() throws UiObjectNotFoundException {

    UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector()
            .resourceId(TestHelper.getAppName() + ":id/share")
            .enabled(true));

    /* Go to a webpage */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString());
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));

    /* Select share */
    TestHelper.menuButton.perform(click());
    shareBtn.waitForExists(waitingTime);
    shareBtn.click();

    // For simulators, where apps are not installed, it'll take to message app
    TestHelper.shareMenuHeader.waitForExists(waitingTime);
    assertTrue(TestHelper.shareMenuHeader.exists());
    assertTrue(TestHelper.shareAppList.exists());
    TestHelper.pressBackKey();
}
 
Example #14
Source File: UiAutomatorParser.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
public List<UiSelector> parse(String textToParse) throws UiSelectorSyntaxException,
        UiObjectNotFoundException {
    selectors.clear();
    if (textToParse.isEmpty()) {
        throw new UiSelectorSyntaxException(textToParse, "Tried to parse an empty string. " +
                "Expected to see a string consisting of text to be interpreted as " +
                "UiAutomator java code.");
    }
    text = textToParse.trim();
    removeTailingSemicolon();

    while (text.length() > 0) {
        consumeStatement();
        consumeSemicolon();
    }

    return selectors;
}
 
Example #15
Source File: PlaybackControlTest.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
/**
 * Click on Closed Caption button and select language from the subtitles dialog
 * Verify the Closed Caption button is clickable
 * Verify the active track exists
 */
@Test
public void testCaptionControl() throws InterruptedException, UiObjectNotFoundException {
    mTestUtils.connectToCastDevice();
    mTestUtils.playCastContent(VIDEO_WITH_SUBTITLES);

    mTestUtils.assertCaption(false);

    // Click CC button and open SUBTITLES dialog
    mDevice.findObject(new UiSelector().description("Closed captions")).click();
    assertTrue(mDevice.findObject(new UiSelector().textMatches("SUBTITLES")).exists());

    // Select subtitle and close SUBTITLES dialog
    mDevice.findObject(new UiSelector().text("English Subtitle")
            .fromParent(new UiSelector().resourceId(resources.getResourceName(R.id.radio)))).click();
    mDevice.findObject(new UiSelector().text("OK")).click();
    assertFalse(mDevice.findObject(new UiSelector().textMatches("SUBTITLES")).exists());

    // Assert subtitle is activated
    mTestUtils.assertCaption(true);

    onView(isRoot()).perform(ViewActions.pressBack());

    mTestUtils.disconnectFromCastDevice();
}
 
Example #16
Source File: TestUtils.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
/**
 * Connecting to Cast device
 *  - Open Cast menu dialog when tapping the Cast icon
 *  - Select target Cast device and connect
 *  - Assert the Cast state is connected
 */
void connectToCastDevice() throws InterruptedException, UiObjectNotFoundException {
    // wait for cast button ready
    Thread.sleep(SHORT_TIMEOUT_MS);

    getCastInfo();
    if (isCastConnected) {
        disconnectFromCastDevice();
    }

    onView(isAssignableFrom(MediaRouteButton.class))
            .perform(click());

    onView(withId(R.id.action_bar_root))
            .check(matches(isDisplayed()));

    // wait for device chooser list
    Thread.sleep(SHORT_TIMEOUT_MS);

    mDevice.findObject(new UiSelector().text(TARGET_DEVICE)).click();

    assertCastStateIsConnected(MAX_TIMEOUT_MS);
}
 
Example #17
Source File: URLExceptionTest.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
private void OpenExceptionsFragment() throws UiObjectNotFoundException {
    mDevice.waitForIdle();
    openSettings();

    onView(withText("Privacy & Security"))
            .check(matches(isDisplayed()))
            .perform(click());

    /* change locale to non-english in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(exceptionsTitle);
    if (exceptionsTitle.isEnabled()) {
        exceptionsTitle.click();
    }

    mDevice.waitForIdle();
}
 
Example #18
Source File: URLExceptionTest.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void AddAndRemoveExceptionTest() throws UiObjectNotFoundException {
    addException(site);

    OpenExceptionsFragment();

    onView(allOf(withText(site), withId(R.id.domainView)))
            .check(matches(isDisplayed()));
    mDevice.waitForIdle();

    removeException();
    mDevice.waitForIdle();

    // Should be in main menu
    onView(withText("Privacy & Security"))
            .check(matches(isDisplayed()));

    /* change locale to non-english in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(exceptionsTitle);

    onView(withText("Exceptions"))
            .check(matches(isDisplayed()))
            .check(matches(not(isEnabled())));
}
 
Example #19
Source File: UiSelectorParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBeAbleToParseUiSelectorWithoutConstructor() throws UiSelectorSyntaxException,
        UiObjectNotFoundException {
    UiSelector expected = new UiSelector().text("test");
    UiSelector actual = new UiSelectorParser("text(\"test\")").parse();
    assertSame(expected, actual);
}
 
Example #20
Source File: UiObjectMatcher.java    From device-automator with MIT License 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 #21
Source File: UiSelectorParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBeAbleToParseUiSelectorWithoutNewKeyword() throws UiSelectorSyntaxException,
        UiObjectNotFoundException {
    UiSelector expected = new UiSelector().text("test");
    UiSelector actual = new UiSelectorParser("UiSelector().text(\"test\")").parse();
    assertSame(expected, actual);
}
 
Example #22
Source File: UiAutomatorParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBeAbleToParseStatements() throws UiSelectorSyntaxException,
        UiObjectNotFoundException {
    doReturn(uiScrollableParser).when(uiAutomatorParser).createUiScrollableParser(anyString());
    doReturn(uiSelectorParser).when(uiAutomatorParser).createUiSelectorParser(anyString());

    final String firstStatement = "new UiScrollable(new UiSelector().index(0))" +
            ".scrollTextIntoView(\"te;xt\")";
    final String secondStatement = "new UiSelector().text(\"te;st\")";
    List<UiSelector> selectors = uiAutomatorParser.parse("  " + firstStatement + " ; " +
             secondStatement + " ; ");
    verify(uiAutomatorParser).createUiScrollableParser(firstStatement);
    verify(uiAutomatorParser).createUiSelectorParser(secondStatement);
    assertEquals(Arrays.asList(scrollableSelector, selector), selectors);
}
 
Example #23
Source File: QueueingTest.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test adding content to the Queue
 * Verify Next and Previous buttons are enabled
 * Verify content is played in the order it was added to queue
 */
@Test
public void testQueuePlayback() throws UiObjectNotFoundException, InterruptedException, JSONException {
    mTestUtils.connectToCastDevice();

    createQueue();

    // Verify expanded controller with correct video title and skip to next button is enabled
    onView(withText(VIDEO_ITEM_3))
            .check(matches(isDisplayed()));
    onView(withContentDescription("Skip to next item"))
            .check(matches(isDisplayed()))
            .check(matches(isEnabled()));

    // Click to play next item
    mDevice.findObject(new UiSelector().description("Skip to next item")).click();
    mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

    // Verify expanded controller with correct video title and skip to previous button is enabled
    onView(withText(VIDEO_ITEM_1))
            .check(matches(isDisplayed()));
    onView(withContentDescription("Skip to previous item"))
            .check(matches(isDisplayed()))
            .check(matches(isEnabled()));

    // Verify queue items (media status) in correct order
    mDevice.pressBack();
    onView(withId(R.id.action_show_queue))
            .check(matches(isDisplayed())).perform(click());
    mTestUtils.assertQueueOrder(VIDEO_ITEM_3, VIDEO_ITEM_1, VIDEO_ITEM_2);

    mDevice.pressEnter();
    mTestUtils.disconnectFromCastDevice();
}
 
Example #24
Source File: AutomatorAction.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Scrolls a {@link UiScrollable} until the given text is displayed on the screen.
 *
 * @param text the text to scroll to.
 * @return
 */
public static AutomatorAction scrollTextIntoView(final String text) {
    return new AutomatorAction() {
        @Override
        public void wrappedPerform(UiSelector selector, UiObject object) throws UiObjectNotFoundException {
            new UiScrollable(selector).scrollTextIntoView(text);
        }
    };
}
 
Example #25
Source File: TestUtils.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
/**
 * Click and play a video
 * Assert player state is playing
 */
void playCastContent(String videoTitle) throws UiObjectNotFoundException, InterruptedException {
    mDevice.findObject(new UiSelector().text(videoTitle)).click();
    mDevice.findObject(
            new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
    mDevice.findObject(new UiSelector().text("Play Now")).click();
    assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);
}
 
Example #26
Source File: AutomatorAction.java    From device-automator with MIT License 5 votes vote down vote up
/**
 * Clears the text field on the ui element specified in
 * {@link DeviceAutomator#onDevice(UiObjectMatcher)}.
 *
 * @return
 */
public static AutomatorAction clearTextField() {
    return new AutomatorAction() {
        @Override
        public void wrappedPerform(UiSelector selector, UiObject object) throws UiObjectNotFoundException {
            object.clearTextField();
        }
    };
}
 
Example #27
Source File: UiScrollableParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotInvokeScrollDescriptionIntoViewIfDescriptionExists() throws
        UiObjectNotFoundException, UiSelectorSyntaxException {
    isUiObjectExist = true;
    final String locator = "new UiScrollable(new UiSelector()).scrollDescriptionIntoView(" +
            "\"test\")";
    UiSelector uiSelector = new UiScrollableParserSpy(locator).parse();
    verify(uiScrollableSpy, never()).scrollDescriptionIntoView(anyString());
    assertEquals(new UiSelector().description("test"), uiSelector);
}
 
Example #28
Source File: UiScrollableParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnUiSelectorFromUiObjectIfLastMethodReturnUiObject() throws
        UiObjectNotFoundException, UiSelectorSyntaxException {
    uiObject = new UiObject(new UiSelector().resourceId("testId"));
    final String locator = "new UiScrollable(new UiSelector()).getChildByText(" +
            "new UiSelector().resourceId(\"testId\"), \"text\", true)";
    UiScrollableParser uiScrollableParser = new UiScrollableParserSpy(locator);

    assertEquals(uiObject.getSelector(), uiScrollableParser.parse());
    verify(uiScrollableSpy).getChildByText(uiSelectorArgumentCaptor.capture(),
            stringArgumentCaptor.capture(), booleanArgumentCaptor.capture());
    assertEquals(uiObject.getSelector(), uiSelectorArgumentCaptor.getValue());
    Assert.assertEquals("text", stringArgumentCaptor.getValue());
    Assert.assertEquals(true, booleanArgumentCaptor.getValue());
}
 
Example #29
Source File: UiObjectMatcherTest.java    From device-automator with MIT License 5 votes vote down vote up
@Test
public void getUiObject() {
    UiObject uiObject = mock(UiObject.class);
    UiDevice device = mock(UiDevice.class);
    when(device.findObject(any(UiSelector.class))).thenReturn(uiObject);

    UiObjectMatcher matcher = UiObjectMatcher.withClass(TextView.class);
    UiObject object = matcher.getUiObject(device);

    verify(device).findObject(matcher.getUiSelector());
    assertEquals(uiObject, object);
}
 
Example #30
Source File: UiScrollableParserTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldToAbleToInvokeScrollDescriptionIntoView() throws UiObjectNotFoundException,
        UiSelectorSyntaxException {
    final String locator = "new UiScrollable(new UiSelector()).scrollDescriptionIntoView(" +
            "\"test\")";
    UiSelector uiSelector = new UiScrollableParserSpy(locator).parse();
    verify(uiScrollableSpy).scrollDescriptionIntoView("test");
    assertEquals(new UiSelector().description("test"), uiSelector);
}