androidx.test.uiautomator.UiObjectNotFoundException Java Examples
The following examples show how to use
androidx.test.uiautomator.UiObjectNotFoundException.
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: FindElements.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
private List<?> findElements(By by, String contextId) throws UiObjectNotFoundException { Session session = AppiumUIA2Driver.getInstance().getSessionOrThrow(); AndroidElement element = session.getKnownElements().getElementFromCache(contextId); if (element == null) { throw new ElementNotFoundException(); } if (by instanceof ById) { String locator = rewriteIdLocator((ById) by); return element.getChildren(androidx.test.uiautomator.By.res(locator), by); } else if (by instanceof By.ByAccessibilityId) { return element.getChildren(androidx.test.uiautomator.By.desc(by.getElementLocator()), by); } else if (by instanceof By.ByClass) { return element.getChildren(androidx.test.uiautomator.By.clazz(by.getElementLocator()), by); } else if (by instanceof By.ByXPath) { final NodeInfoList matchedNodes = getXPathNodeMatch(by.getElementLocator(), element, true); return matchedNodes.isEmpty() ? Collections.emptyList() : CustomUiDevice.getInstance().findObjects(matchedNodes); } else if (by instanceof By.ByAndroidUiAutomator) { return getUiObjectsUsingAutomator(toSelectors(by.getElementLocator()), contextId); } String msg = String.format("By locator %s is currently not supported!", by.getClass().getSimpleName()); throw new UnsupportedOperationException(msg); }
Example #2
Source File: BasicCastUITest.java From CastVideos-android with Apache License 2.0 | 6 votes |
/** * Verify the Mini Controller is displayed * Click the Mini Controller and verify the Expanded Controller is displayed */ @Test public void testMiniController() throws InterruptedException, UiObjectNotFoundException { mTestUtils.connectToCastDevice(); mTestUtils.playCastContent(VIDEO_TITLE); // click to close expanded controller onView(allOf( isAssignableFrom(AppCompatImageButton.class) , withParent(isAssignableFrom(Toolbar.class)) )) .check(matches(isDisplayed())) .perform(click()); mTestUtils.verifyMiniController(); mDevice.pressEnter(); onView(withId(R.id.cast_mini_controller)) .perform(click()); mTestUtils.verifyExpandedController(); mTestUtils.disconnectFromCastDevice(); }
Example #3
Source File: UiExpressionParser.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected T consumeConstructor() throws UiSelectorSyntaxException, UiObjectNotFoundException { skipLeadingSpaces(); final String constructorExpression = getConstructorExpression(); if (!expression.startsWith(constructorExpression, currentIndex)) { throw new UiSelectorSyntaxException(expression.toString(), String.format( "Was trying to parse as %1$s, but didn't start with an acceptable prefix. " + "Acceptable prefixes are: `new %1$s` or `%1$s`", clazz.getSimpleName())); } currentIndex += constructorExpression.length(); final List<String> params = consumeMethodParameters(); final Pair<Constructor, List<Object>> constructor = findConstructor(params); try { target = (T) constructor.first.newInstance(constructor.second.toArray()); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new UiAutomator2Exception("Can not create instance of " + clazz.getSimpleName(), e); } return target; }
Example #4
Source File: ScrollToElement.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
@Override public boolean scrollIntoView(UiObject obj) throws UiObjectNotFoundException { if (obj.exists()) { return true; } // we will need to reset the search from the beginning to start search flingToBeginning(getMaxSearchSwipes()); if (obj.exists()) { return true; } for (int x = 0; x < getMaxSearchSwipes(); x++) { if (!scrollForward()) { return false; } if (obj.exists()) { return true; } } return false; }
Example #5
Source File: URLAutocompleteTest.java From focus-android with Mozilla Public License 2.0 | 6 votes |
@Ignore @Test // Add custom autocomplete, and check to see it works public void CustomCompletionTest() throws UiObjectNotFoundException { OpenCustomCompleteDialog(); // Enable URL autocomplete, and add URL addAutoComplete(site); exitToTop(); // Check for custom autocompletion checkACOn(site); // Remove custom autocompletion site OpenCustomCompleteDialog(); removeACSite(); exitToTop(); // Check autocompletion checkACOff(site.substring(0, 3)); }
Example #6
Source File: UiObjectElement.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
@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 #7
Source File: LineLoginButtonTests.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testApp2AppLineLoginSuccess() throws UiObjectNotFoundException { // Given tapLineLoginButton(); if (isLineAppInstalled()) { // When lineAppLoginPage.tapAllowButton(); menuFragmentPage.tapApisButton(); apisFragmentPage.tapGetProfileButton(); // Then checkGetProfile(); } else { // Then assertTrue(checkTextExists(AndroidTestsConfig.LINE_WEB_URL)); checkReturnSdkSampleApp(); } }
Example #8
Source File: BrowserSignInTest.java From samples-android with Apache License 2.0 | 6 votes |
@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 #9
Source File: Device.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
public static void scrollToElement(@Nullable UiScrollable origin, UiSelector selector, @Nullable Integer maxSwipes) throws UiObjectNotFoundException { UiScrollable scrollableOrigin = origin == null ? new UiScrollable(new UiSelector().scrollable(true).instance(0)) : origin; Logger.debug(String.format("Using %s as scrolling origin", scrollableOrigin.getSelector())); String hScrollViewClassName = android.widget.HorizontalScrollView.class.getName(); if (Objects.equals(scrollableOrigin.getClassName(), hScrollViewClassName)) { scrollableOrigin.setAsHorizontalList(); } int originalMaxSwipes = scrollableOrigin.getMaxSearchSwipes(); if (maxSwipes != null && maxSwipes > 0) { scrollableOrigin.setMaxSearchSwipes(maxSwipes); } try { if (!scrollableOrigin.scrollIntoView(selector)) { throw new UiObjectNotFoundException(String.format("Cannot scroll to %s", selector)); } } finally { // The number of search swipes is held in a static property of the UiScrollable class. // Whenever a non-default number of search swipes is used during the scroll, we must // always restore the setting after the operation. scrollableOrigin.setMaxSearchSwipes(originalMaxSwipes); } }
Example #10
Source File: TouchLongClick.java From appium-uiautomator2-server with Apache License 2.0 | 6 votes |
@Override protected void executeEvent() throws UiObjectNotFoundException { int duration = params.duration != null ? params.duration : DEFAULT_DURATION_MS; printEventDebugLine(duration); if (performLongClick(clickX, clickY, duration)) { return; } if (element == null) { throw new InvalidElementStateException( String.format("Cannot perform %s action at (%s, %s)", getName(), clickX, clickY)); } // if correctLongClick failed and we have an element // then uiautomator's longClick is used as a fallback. Logger.debug("Falling back to broken longClick"); if (!element.longClick()) { throw new InvalidElementStateException( String.format("Cannot perform %s action at %s element", getName(), element.getBy())); } }
Example #11
Source File: TestUtils.java From CastVideos-android with Apache License 2.0 | 6 votes |
/** * 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 #12
Source File: BrowserSignInTest.java From samples-android with Apache License 2.0 | 6 votes |
public void testB_signInWithPayload() throws UiObjectNotFoundException { activityBrowserRule.getActivity().mPayload = new AuthenticationPayload.Builder() .setLoginHint("[email protected]") .addParameter("max_age", "5000") .build(); onView(withId(R.id.browser_sign_in_btn)).withFailureHandler((error, viewMatcher) -> { onView(withId(R.id.clear_data_btn)).check(matches(isDisplayed())); onView(withId(R.id.clear_data_btn)).perform(click()); }).check(matches(isDisplayed())); onView(withId(R.id.browser_sign_in_btn)).perform(click()); customTabInteraction(false); //wait for token exchange getProgressBar().waitUntilGone(NETWORK_TIMEOUT); //check if get profile is visible onView(withId(R.id.clear_data_btn)).check(matches(isDisplayed())); onView(withId(R.id.smartlock_enable)).check(matches(isNotChecked())); }
Example #13
Source File: UiTestActions.java From braintree-android-drop-in with MIT License | 6 votes |
public static void clickWebViewText(String text, Integer waitTimeout) { Configurator configurator = Configurator.getInstance(); long originalTimeout = configurator.getWaitForSelectorTimeout(); configurator.setWaitForSelectorTimeout(waitTimeout); try { onDevice(withContentDescription(text)).perform(click()); } catch (RuntimeException e) { if (e.getCause() instanceof UiObjectNotFoundException) { onDevice(withText(text)).perform(click()); } else { throw e; } } finally { configurator.setWaitForSelectorTimeout(originalTimeout); } }
Example #14
Source File: Location.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Override protected AppiumResponse safeHandle(IHttpRequest request) throws UiObjectNotFoundException { Session session = AppiumUIA2Driver.getInstance().getSessionOrThrow(); String id = getElementId(request); AndroidElement element = session.getKnownElements().getElementFromCache(id); if (element == null) { throw new ElementNotFoundException(); } final Rect bounds = element.getBounds(); Logger.info("Element found at location " + "(" + bounds.left + "," + bounds.top + ")"); return new AppiumResponse(getSessionId(request), new LocationModel(bounds.left, bounds.top)); }
Example #15
Source File: UiSelectorParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test() public void shouldThrowExceptionOnUnclosedParenthesis() throws UiSelectorSyntaxException, UiObjectNotFoundException { expectedException.expect(UiSelectorSyntaxException.class); expectedException.expectMessage("Unclosed paren in expression"); new UiSelectorParser("new UiSelector().text(\"test\"()").parse(); }
Example #16
Source File: BasicCastUITest.java From CastVideos-android with Apache License 2.0 | 5 votes |
/** * Navigate away from the sender app and open the notification * Media control should display on notification * Click the notification widget and verify the Expanded Controller is displayed */ @Test public void testNotification() throws UiObjectNotFoundException, InterruptedException { mTestUtils.connectToCastDevice(); mTestUtils.playCastContent(VIDEO_TITLE); mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS); mDevice.pressHome(); mDevice.openNotification(); mDevice.findObject(new UiSelector() .className("android.widget.ImageButton") .resourceId("android:id/action0").description("Pause")).click(); mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PAUSED, MAX_TIMEOUT_MS); mDevice.findObject(new UiSelector() .className("android.widget.ImageButton") .resourceId("android:id/action0").description("Play")).click(); mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS); mDevice.findObject(new UiSelector() .className("android.widget.TextView") .resourceId("android:id/title").text(VIDEO_TITLE)).click(); mTestUtils.verifyExpandedController(); mDevice.pressBack(); mDevice.pressEnter(); mTestUtils.disconnectFromCastDevice(); }
Example #17
Source File: UiSelectorParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@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 #18
Source File: URLAutocompleteTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void checkACOff(String url) throws UiObjectNotFoundException { TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.setText(url); TestHelper.hint.waitForExists(waitingTime); assertTrue (TestHelper.inlineAutocompleteEditText.getText().equals(url)); TestHelper.cleartextField.click(); }
Example #19
Source File: URLAutocompleteTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void checkACOn(String url) throws UiObjectNotFoundException { TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.setText(url.substring(0, 1)); TestHelper.hint.waitForExists(waitingTime); assertTrue (TestHelper.inlineAutocompleteEditText.getText().equals(url)); TestHelper.cleartextField.click(); }
Example #20
Source File: UiSelectorParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldBeAbleToParseLiteralsWithBrakes() throws UiSelectorSyntaxException, UiObjectNotFoundException { UiSelector expected = new UiSelector().text("te\nst"); UiSelector actual = new UiSelectorParser("new UiSelector().text(\"te\nst\")").parse(); assertSame(expected, actual); }
Example #21
Source File: UiScrollableParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@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 #22
Source File: UiScrollableParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldNotInvokeScrollTextIntoViewIfTextExists() throws UiObjectNotFoundException, UiSelectorSyntaxException { isUiObjectExist = true; final String locator = "new UiScrollable(new UiSelector()).scrollTextIntoView(" + "\"test\")"; UiSelector uiSelector = new UiScrollableParserSpy(locator).parse(); verify(uiScrollableSpy, never()).scrollTextIntoView(anyString()); assertEquals(new UiSelector().text("test"), uiSelector); }
Example #23
Source File: EraseAllUserDataTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void systemBarHomeViewTest() throws UiObjectNotFoundException { // Initialize UiDevice instance final int LAUNCH_TIMEOUT = 5000; // Open a webpage TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.waitForWebContent(); // Switch out of Focus, pull down system bar and select delete browsing history TestHelper.pressHomeKey(); TestHelper.openNotification(); TestHelper.notificationBarDeleteItem.waitForExists(waitingTime); TestHelper.notificationBarDeleteItem.click(); // Wait for launcher final String launcherPackage = TestHelper.mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); TestHelper.mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); // Launch the app mActivityTestRule.launchActivity(new Intent(Intent.ACTION_MAIN)); // Verify that it's on the main view, not showing the previous browsing session TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); assertTrue(TestHelper.inlineAutocompleteEditText.exists()); }
Example #24
Source File: GetRect.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Override protected AppiumResponse safeHandle(IHttpRequest request) throws UiObjectNotFoundException { String id = getElementId(request); Session session = AppiumUIA2Driver.getInstance().getSessionOrThrow(); AndroidElement element = session.getKnownElements().getElementFromCache(id); if (element == null) { throw new ElementNotFoundException(); } return new AppiumResponse(getSessionId(request), new ElementRectModel(element.getBounds())); }
Example #25
Source File: UiScrollableParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldNotInvokeScrollIntoViewWithUiSelectorParamIfObjectExists() throws UiObjectNotFoundException, UiSelectorSyntaxException { isUiObjectExist = true; final String locator = "new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().index(0).text(\"test\"))"; UiSelector uiSelector = new UiScrollableParserSpy(locator).parse(); verify(uiScrollableSpy, never()).scrollIntoView(any(UiSelector.class)); assertEquals(new UiSelector().index(0).text("test"), uiSelector); }
Example #26
Source File: AddToHomescreenTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void openAddtoHSDialog() throws UiObjectNotFoundException { TestHelper.menuButton.perform(click()); TestHelper.AddtoHSmenuItem.waitForExists(waitingTime); // If the menu item is not clickable, wait and retry while (!TestHelper.AddtoHSmenuItem.isClickable()) { TestHelper.pressBackKey(); TestHelper.menuButton.perform(click()); } TestHelper.AddtoHSmenuItem.click(); }
Example #27
Source File: UiSelectorParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldBeAbleToParseLiteralsWithParentheses() throws UiSelectorSyntaxException, UiObjectNotFoundException { UiSelector expected = new UiSelector().text(")test(test)("); UiSelector actual = new UiSelectorParser("new UiSelector().text(\")test(test)(\")").parse(); assertSame(expected, actual); }
Example #28
Source File: GetName.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Override protected AppiumResponse safeHandle(IHttpRequest request) throws UiObjectNotFoundException { String id = getElementId(request); Session session = AppiumUIA2Driver.getInstance().getSessionOrThrow(); AndroidElement element = session.getKnownElements().getElementFromCache(id); if (element == null) { throw new ElementNotFoundException(); } String elementName = element.getContentDesc(); Logger.info("Element Name ", elementName); return new AppiumResponse(getSessionId(request), elementName); }
Example #29
Source File: UiScrollableParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldReThrowUiObjectNotFoundException() throws UiSelectorSyntaxException, UiObjectNotFoundException { expectedException.expect(UiObjectNotFoundException.class); expectedException.expectMessage("not found"); final String locator = "new UiScrollable(new UiSelector()).getChildByText(" + "new UiSelector().resourceId(\"testId\"), \"text\")"; new UiScrollableParserSpy(locator).parse(); }
Example #30
Source File: UiSelectorParserTests.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Test public void shouldBeAbleToParseSimpleUiSelector() throws UiSelectorSyntaxException, UiObjectNotFoundException { UiSelector expected = new UiSelector().className(android.widget.TextView.class).text("test") .clickable(false).selected(true).index(1); UiSelector actual = new UiSelectorParser("new UiSelector().className(android.widget" + ".TextView).text(\"test\").clickable(false).selected(true).index(1)").parse(); assertSame(expected, actual); }