Java Code Examples for androidx.test.uiautomator.UiObject#click()
The following examples show how to use
androidx.test.uiautomator.UiObject#click() .
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: BrowserSignInTest.java From samples-android with Apache License 2.0 | 6 votes |
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 2
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 3
Source File: BrowserScreenScreenshots.java From focus-android with Mozilla Public License 2.0 | 6 votes |
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 4
Source File: ShareWebsiteTest.java From focus-android with Mozilla Public License 2.0 | 6 votes |
@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 5
Source File: BadURLTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void BadURLcheckTest() throws UiObjectNotFoundException { UiObject cancelOpenAppBtn = TestHelper.mDevice.findObject(new UiSelector() .resourceId("android:id/button2")); UiObject openAppalert = TestHelper.mDevice.findObject(new UiSelector() .text("Open link in another app")); // provide an invalid URL TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText("htps://www.mozilla.org"); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); // Check for error message onWebView(withText(R.string.error_malformedURI_title)); onWebView(withText(R.string.error_malformedURI_message)); onWebView(withText("Try Again")); TestHelper.floatingEraseButton.perform(click()); /* provide market URL that is handled by Google Play app */ TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText("market://details?id=org.mozilla.firefox&referrer=" + "utm_source%3Dmozilla%26utm_medium%3DReferral%26utm_campaign%3Dmozilla-org"); TestHelper.pressEnterKey(); // Wait for the dialog cancelOpenAppBtn.waitForExists(waitingTime); assertTrue(openAppalert.exists()); assertTrue(cancelOpenAppBtn.exists()); cancelOpenAppBtn.click(); TestHelper.floatingEraseButton.perform(click()); TestHelper.erasedMsg.waitForExists(waitingTime); }
Example 6
Source File: AutomatorAction.java From device-automator with MIT License | 5 votes |
/** * Performs a click on the ui element specified in * {@link DeviceAutomator#onDevice(UiObjectMatcher)}. * * @return */ public static AutomatorAction click() { return new AutomatorAction() { @Override public void wrappedPerform(UiSelector selector, UiObject object) throws UiObjectNotFoundException { object.click(); } }; }
Example 7
Source File: DeviceAutomator.java From device-automator with MIT License | 5 votes |
private void clickPermissionDialogButton(String permission, int buttonIndex) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(getTargetContext(), permission) != PackageManager.PERMISSION_GRANTED) { try { UiObject allowPermissions = mDevice.findObject(new UiSelector() .clickable(true) .checkable(false) .index(buttonIndex)); if (allowPermissions.exists()) { allowPermissions.click(); } } catch (UiObjectNotFoundException ignored) {} } }
Example 8
Source File: SwitchLocaleTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void FrenchLocaleTest() throws UiObjectNotFoundException { UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .text("Valeur par défaut du système")); UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .text("English (United States)")); UiObject englishLocaleinFr = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.CheckedTextView") .text("English (United States)")); /* Go to Settings */ TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); openSettings(); frenchGeneralHeading.waitForExists(waitingTime); frenchGeneralHeading.click(); languageHeading.waitForExists(waitingTime); /* system locale is in French, check it is now set to system locale */ frenchHeading.waitForExists(waitingTime); Assert.assertTrue(frenchHeading.exists()); Assert.assertTrue(frenchMenuItem.exists()); languageHeading.click(); Assert.assertTrue(sysDefaultLocale.isChecked()); /* change locale to English in the setting, verify the locale is changed */ UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true)); appViews.scrollIntoView(englishLocaleinFr); Assert.assertTrue(englishLocaleinFr.isClickable()); englishLocaleinFr.click(); englishHeading.waitForExists(waitingTime); Assert.assertTrue(englishHeading.exists()); Assert.assertTrue(englishMenuItem.exists()); mDevice.pressBack(); }
Example 9
Source File: OpenInExternalBrowserDialogueTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void OpenInExternalBrowserDialogueTest() throws UiObjectNotFoundException { UiObject openWithBtn = TestHelper.mDevice.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/open_select_browser") .enabled(true)); UiObject openWithTitle = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .text("Open in…") .enabled(true)); UiObject openWithList = TestHelper.mDevice.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/apps") .enabled(true)); /* Go to mozilla page */ TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.waitForWebContent(); /* Select Open with from menu, check appearance */ TestHelper.menuButton.perform(click()); openWithBtn.waitForExists(waitingTime); openWithBtn.click(); openWithTitle.waitForExists(waitingTime); assertTrue(openWithTitle.exists()); assertTrue(openWithList.exists()); TestHelper.pressBackKey(); }
Example 10
Source File: DownloadFileTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void DownloadTest() throws UiObjectNotFoundException { UiObject downloadIcon; downloadIcon = TestHelper.mDevice.findObject(new UiSelector() .resourceId("download") .enabled(true)); // Load website with service worker TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.waitForWebContent(); TestHelper.progressBar.waitUntilGone(waitingTime); downloadIcon.click(); // If permission dialog appears, grant it if (TestHelper.permAllowBtn.waitForExists(waitingTime)) { TestHelper.permAllowBtn.click(); } TestHelper.downloadTitle.waitForExists(waitingTime); Assert.assertTrue(TestHelper.downloadTitle.isEnabled()); Assert.assertTrue(TestHelper.downloadCancelBtn.isEnabled()); Assert.assertTrue(TestHelper.downloadBtn.isEnabled()); Assert.assertEquals(TestHelper.downloadFileName.getText(), "download.jpg"); Assert.assertEquals(TestHelper.downloadWarning.getText(), "Downloaded files will not be deleted when you erase Firefox Focus history."); TestHelper.downloadBtn.click(); TestHelper.completedMsg.waitForExists(waitingTime); Assert.assertTrue(TestHelper.completedMsg.isEnabled()); Assert.assertTrue(TestHelper.completedMsg.getText().contains("finished")); TestHelper.mDevice.openNotification(); TestHelper.mDevice.waitForIdle(); TestHelper.savedNotification.waitForExists(waitingTime); TestHelper.savedNotification.swipeRight(50); }
Example 11
Source File: BrowserScreenScreenshots.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void takeScreenshotsOfOpenWithAndShare() throws Exception { /* Open_With View */ TestHelper.menuButton.perform(click()); UiObject openWithBtn = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/open_select_browser") .enabled(true)); assertTrue(openWithBtn.waitForExists(waitingTime)); openWithBtn.click(); UiObject shareList = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/apps") .enabled(true)); assertTrue(shareList.waitForExists(waitingTime)); Screengrab.screenshot("OpenWith_Dialog"); /* Share View */ UiObject shareBtn = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/share") .enabled(true)); device.pressBack(); TestHelper.menuButton.perform(click()); assertTrue(shareBtn.waitForExists(waitingTime)); shareBtn.click(); TestHelper.shareAppList.waitForExists(waitingTime); Screengrab.screenshot("Share_Dialog"); device.pressBack(); }
Example 12
Source File: BrowserSignInTest.java From samples-android with Apache License 2.0 | 5 votes |
private void acceptChromePrivacyOption() throws UiObjectNotFoundException { UiSelector selector = new UiSelector(); UiObject accept = mDevice.findObject(selector.resourceId(ID_ACCEPT)); accept.waitForExists(TRANSITION_TIMEOUT); if (accept.exists()) { accept.click(); } UiObject noThanks = mDevice.findObject(selector.resourceId(ID_NO_THANKS)); noThanks.waitForExists(TRANSITION_TIMEOUT); if (noThanks.exists()) { noThanks.click(); } }
Example 13
Source File: PinnedTileTests.java From firefox-echo-show with Mozilla Public License 2.0 | 4 votes |
@Test public void testCustomPinnedTile() throws InterruptedException, UiObjectNotFoundException { // onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus())) // .perform(typeTextIntoFocusedView("example.com")) // .perform(pressImeActionButton()); onView(ViewMatchers.withId(R.id.webview)) .check(matches(isDisplayed())); mDevice.pressMenu(); // final ViewInteraction pinButton = onView(ViewMatchers.withId(R.id.pinButton)) // .check(matches(isNotChecked())); // pinButton.perform(click()); onView(withText(R.string.notification_pinned_site)) .inRoot(withDecorView(not(is(mActivityTestRule.getActivity().getWindow().getDecorView())))) .check(matches(isDisplayed())); // final ViewInteraction goHome = onView(ViewMatchers.withId(R.id.navButtonHome)) // .check(matches(isDisplayed())); // goHome.perform(click()); // UIAutomator work-around waiting for tile existence UiObject newTile = mDevice.findObject(new UiSelector() .resourceId("org.mozilla.tv.firefox.debug:id/tile_title") .text("example") .enabled(true)); newTile.waitForExists(5000); newTile.click(); mDevice.pressMenu(); // pinButton.perform(click()); onView(withText(R.string.notification_unpinned_site)) .inRoot(withDecorView(not(is(mActivityTestRule.getActivity().getWindow().getDecorView())))) .check(matches(isDisplayed())); // goHome.perform(click()); // UIAutomator work-around waiting for tile non-existence newTile.waitUntilGone(5000); assertFalse(newTile.exists()); }
Example 14
Source File: ChangeSearchEngineTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void SearchTest() throws UiObjectNotFoundException { UiObject searchMenu = TestHelper.settingsMenu.getChild(new UiSelector() .className("android.widget.LinearLayout") .instance(2)); UiObject searchEngineSelectorLabel = searchMenu.getChild(new UiSelector() .resourceId("android:id/title") .text("Search") .enabled(true)); String searchString = String.format("mozilla focus - %s Search", mSearchEngine); UiObject googleWebView = TestHelper.mDevice.findObject(new UiSelector() .description(searchString) .className("android.webkit.WebView")); // Open [settings menu] and select Search assertTrue(TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime)); openSettings(); TestHelper.settingsHeading.waitForExists(waitingTime); searchEngineSelectorLabel.waitForExists(waitingTime); searchEngineSelectorLabel.click(); // Open [settings menu] > [search engine menu] and click "Search engine" label UiObject defaultSearchEngineLabel = TestHelper.settingsMenu.getChild(new UiSelector() .className("android.widget.LinearLayout") .instance(0)); defaultSearchEngineLabel.waitForExists(waitingTime); defaultSearchEngineLabel.click(); // Open [settings menu] > [search engine menu] > [search engine list menu] // then select desired search engine UiScrollable searchEngineList = new UiScrollable(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/search_engine_group").enabled(true)); UiObject defaultEngineSelection = searchEngineList.getChildByText(new UiSelector() .className(RadioButton.class), mSearchEngine); defaultEngineSelection.waitForExists(waitingTime); assertTrue(defaultEngineSelection.getText().equals(mSearchEngine)); defaultEngineSelection.click(); TestHelper.pressBackKey(); TestHelper.settingsHeading.waitForExists(waitingTime); UiObject defaultSearchEngine = TestHelper.mDevice.findObject(new UiSelector() .text(mSearchEngine) .resourceId("android:id/summary")); assertTrue(defaultSearchEngine.getText().equals(mSearchEngine)); TestHelper.pressBackKey(); TestHelper.pressBackKey(); // Do search on blank spaces and press enter for search (should not do anything) TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(" "); TestHelper.pressEnterKey(); assertTrue(TestHelper.inlineAutocompleteEditText.exists()); // Do search on text string TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText("mozilla "); // Would you like to turn on search suggestions? Yes No // fresh install only) if (TestHelper.searchSuggestionsTitle.exists()) { TestHelper.searchSuggestionsButtonYes.waitForExists(waitingTime); TestHelper.searchSuggestionsButtonYes.click(); } // verify search hints... "mozilla firefox", "mozilla careers", etc.TestHelper.suggestionList.waitForExists(waitingTime); TestHelper.mDevice.pressKeyCode(KEYCODE_SPACE); TestHelper.suggestionList.waitForExists(waitingTime); assertTrue(TestHelper.suggestionList.getChildCount() >= 1); onView(allOf(withText(containsString("mozilla")), withId(R.id.searchView))) .check(matches(isDisplayed())); // we expect min=1, max=5 int count = 0; int maxCount = 3; //while (count <= maxCount) { while (count < maxCount) { onView(allOf(withText(containsString("mozilla")), withId(R.id.suggestion), isDescendantOfA(childAtPosition(withId(R.id.suggestionList), count)))) .check(matches(isDisplayed())); count++; } // Tap URL bar, check it displays search term (instead of URL) TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.click(); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText("mozilla focus"); TestHelper.pressEnterKey(); googleWebView.waitForExists(waitingTime); TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime); // Search for words: <Google|DuckDuckGo|etc.>, mozilla, focus assertTrue(TestHelper.browserURLbar.getText().contains(mSearchEngine.toLowerCase())); assertTrue(TestHelper.browserURLbar.getText().contains("mozilla")); assertTrue(TestHelper.browserURLbar.getText().contains("focus")); }
Example 15
Source File: AddToHomescreenTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void AddToHomeScreenTest() throws UiObjectNotFoundException { UiObject shortcutIcon = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .description(webServerBookmarkName) .enabled(true)); // Open website, and click 'Add to homescreen' TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.progressBar.waitForExists(waitingTime); Assert.assertTrue(TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime)); if (!AppConstants.INSTANCE.isGeckoBuild()) { TestHelper.waitForWebSiteTitleLoad(); } openAddtoHSDialog(); // Add to Home screen dialog is now shown TestHelper.shortcutTitle.waitForExists(waitingTime); Assert.assertTrue(TestHelper.shortcutTitle.isEnabled()); Assert.assertEquals(TestHelper.shortcutTitle.getText(), "gigantic experience"); Assert.assertTrue(TestHelper.AddtoHSOKBtn.isEnabled()); Assert.assertTrue(TestHelper.AddtoHSCancelBtn.isEnabled()); //Edit shortcut text TestHelper.shortcutTitle.click(); TestHelper.shortcutTitle.setText(webServerBookmarkName); TestHelper.AddtoHSOKBtn.click(); // For Android O, we need additional steps if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { handleShortcutLayoutDialog(); } //App is sent to background, in launcher now if (welcomeBtn.exists()) { welcomeBtn.click(); } shortcutIcon.waitForExists(waitingTime); Assert.assertTrue(shortcutIcon.isEnabled()); shortcutIcon.click(); TestHelper.browserURLbar.waitForExists(waitingTime); Assert.assertTrue( TestHelper.browserURLbar.getText() .equals(webServer.url(TEST_PATH).toString())); }
Example 16
Source File: AddToHomescreenTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void NonameTest() throws UiObjectNotFoundException { UiObject shortcutIcon = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .description(webServerBookmarkName) .enabled(true)); // Open website, and click 'Add to homescreen' TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.progressBar.waitForExists(waitingTime); Assert.assertTrue(TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime)); if (!AppConstants.INSTANCE.isGeckoBuild()) { TestHelper.waitForWebSiteTitleLoad(); } openAddtoHSDialog(); // "Add to Home screen" dialog is now shown TestHelper.shortcutTitle.waitForExists(waitingTime); Assert.assertTrue(TestHelper.shortcutTitle.isEnabled()); Assert.assertEquals(TestHelper.shortcutTitle.getText(), "gigantic experience"); Assert.assertTrue(TestHelper.AddtoHSOKBtn.isEnabled()); Assert.assertTrue(TestHelper.AddtoHSCancelBtn.isEnabled()); //replace shortcut text TestHelper.shortcutTitle.click(); TestHelper.shortcutTitle.setText(webServerBookmarkName); TestHelper.AddtoHSOKBtn.click(); // For Android O, we need additional steps if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { handleShortcutLayoutDialog(); } if (welcomeBtn.exists()) { welcomeBtn.click(); } //App is sent to background, in launcher now //Start from home and then swipe, to ensure we land where we want to search for shortcut TestHelper.mDevice.pressHome(); TestHelper.swipeScreenLeft(); shortcutIcon.waitForExists(waitingTime); Assert.assertTrue(shortcutIcon.isEnabled()); shortcutIcon.click(); TestHelper.browserURLbar.waitForExists(waitingTime); Assert.assertTrue( TestHelper.browserURLbar.getText() .equals(webServer.url(TEST_PATH).toString())); }
Example 17
Source File: AddToHomescreenTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void SearchTermShortcutTest() throws UiObjectNotFoundException { UiObject shortcutIcon = TestHelper.mDevice.findObject(new UiSelector() .className("android.widget.TextView") .descriptionContains("helloworld") .enabled(true)); // Open website, and click 'Add to homescreen' TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText("helloworld"); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); // In certain cases, where progressBar disappears immediately, below will return false // since it busy waits, it will unblock when the bar isn't visible, regardless of the // return value TestHelper.progressBar.waitForExists(waitingTime); TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime); openAddtoHSDialog(); // "Add to Home screen" dialog is now shown TestHelper.shortcutTitle.waitForExists(waitingTime); TestHelper.AddtoHSOKBtn.click(); // For Android O, we need additional steps if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { handleShortcutLayoutDialog(); } if (welcomeBtn.exists()) { welcomeBtn.click(); } //App is sent to background, in launcher now //Start from home and then swipe, to ensure we land where we want to search for shortcut TestHelper.mDevice.pressHome(); TestHelper.swipeScreenLeft(); shortcutIcon.waitForExists(waitingTime); Assert.assertTrue(shortcutIcon.isEnabled()); shortcutIcon.click(); TestHelper.waitForIdle(); TestHelper.waitForWebContent(); //Tap URL bar and check the search term is still shown TestHelper.browserURLbar.waitForExists(waitingTime); Assert.assertTrue(TestHelper.browserURLbar.getText().contains("helloworld")); }
Example 18
Source File: SettingsBlockToggleTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void SettingsToggleTest() throws UiObjectNotFoundException { UiObject privacyHeading = TestHelper.mDevice.findObject(new UiSelector() .text("Privacy & Security") .resourceId("android:id/title")); UiObject blockAdTrackerEntry = TestHelper.settingsMenu.getChild(new UiSelector() .className("android.widget.LinearLayout") .instance(1)); UiObject blockAdTrackerSwitch = blockAdTrackerEntry.getChild(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/switchWidget")); UiObject blockAnalyticTrackerEntry = TestHelper.settingsMenu.getChild(new UiSelector() .className("android.widget.LinearLayout") .instance(2)); UiObject blockAnalyticTrackerSwitch = blockAnalyticTrackerEntry.getChild(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/switchWidget")); UiObject blockSocialTrackerEntry = TestHelper.settingsMenu.getChild(new UiSelector() .className("android.widget.LinearLayout") .instance(4)); UiObject blockSocialTrackerSwitch = blockSocialTrackerEntry.getChild(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/switchWidget")); // Let's go to an actual URL which is http:// TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime); TestHelper.inlineAutocompleteEditText.clearTextField(); TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString()); TestHelper.hint.waitForExists(waitingTime); TestHelper.pressEnterKey(); TestHelper.waitForWebContent(); assertTrue (TestHelper.browserURLbar.getText().contains(webServer.url(TEST_PATH).toString())); assertTrue (!TestHelper.lockIcon.exists()); /* Go to settings and disable everything */ openSettings(); privacyHeading.waitForExists(waitingTime); privacyHeading.click(); String blockAdTrackerValue = blockAdTrackerSwitch.getText(); String blockAnalyticTrackerValue = blockAnalyticTrackerSwitch.getText(); String blockSocialTrackerValue = blockSocialTrackerSwitch.getText(); // Turn off and back on blockAdTrackerEntry.click(); blockAnalyticTrackerEntry.click(); blockSocialTrackerEntry.click(); assertFalse(blockAdTrackerSwitch.getText().equals(blockAdTrackerValue)); assertFalse(blockAnalyticTrackerSwitch.getText().equals(blockAnalyticTrackerValue)); assertFalse(blockSocialTrackerSwitch.getText().equals(blockSocialTrackerValue)); blockAdTrackerEntry.click(); blockAnalyticTrackerEntry.click(); blockSocialTrackerEntry.click(); assertTrue(blockAdTrackerSwitch.getText().equals(blockAdTrackerValue)); assertTrue(blockAnalyticTrackerSwitch.getText().equals(blockAnalyticTrackerValue)); assertTrue(blockSocialTrackerSwitch.getText().equals(blockSocialTrackerValue)); //Back to the webpage TestHelper.pressBackKey(); TestHelper.pressBackKey(); TestHelper.waitForWebContent(); assertTrue (TestHelper.browserURLbar.getText().contains(webServer.url(TEST_PATH).toString())); assertTrue (!TestHelper.lockIcon.exists()); }
Example 19
Source File: BrowserScreenScreenshots.java From focus-android with Mozilla Public License 2.0 | 4 votes |
private void takeScreenshotOfTabsTrayAndErase() throws Exception { final UiObject mozillaImage = device.findObject(new UiSelector() .resourceId("download") .enabled(true)); UiObject imageMenuTitle = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/topPanel") .enabled(true)); UiObject openNewTabTitle = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/design_menu_item_text") .text(getString(R.string.contextmenu_open_in_new_tab)) .enabled(true)); UiObject multiTabBtn = device.findObject(new UiSelector() .resourceId(TestHelper.getAppName() + ":id/tabs") .enabled(true)); UiObject eraseHistoryBtn = device.findObject(new UiSelector() .text(getString(R.string.tabs_tray_action_erase)) .enabled(true)); assertTrue(mozillaImage.waitForExists(waitingTime)); mozillaImage.dragTo(mozillaImage, 7); assertTrue(imageMenuTitle.waitForExists(waitingTime)); assertTrue(imageMenuTitle.exists()); Screengrab.screenshot("Image_Context_Menu"); //Open a new tab openNewTabTitle.click(); TestHelper.mDevice.wait(Until.findObject( By.res(TestHelper.getAppName(), "snackbar_text")), 5000); Screengrab.screenshot("New_Tab_Popup"); TestHelper.mDevice.wait(Until.gone( By.res(TestHelper.getAppName(), "snackbar_text")), 5000); assertTrue(multiTabBtn.waitForExists(waitingTime)); multiTabBtn.click(); assertTrue(eraseHistoryBtn.waitForExists(waitingTime)); Screengrab.screenshot("Multi_Tab_Menu"); eraseHistoryBtn.click(); device.wait(Until.findObject( By.res(TestHelper.getAppName(), "snackbar_text")), waitingTime); Screengrab.screenshot("YourBrowsingHistoryHasBeenErased"); }