Java Code Examples for androidx.test.uiautomator.UiObject#waitForExists()

The following examples show how to use androidx.test.uiautomator.UiObject#waitForExists() . 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: 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 2
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 3
Source File: BrowserSignInTest.java    From samples-android with Apache License 2.0 5 votes vote down vote up
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 4
Source File: OpenInExternalBrowserDialogueTest.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@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 5
Source File: AccessSettingsTest.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void AccessSettingsTest() {

    UiObject generalHeading = TestHelper.mDevice.findObject(new UiSelector()
            .text("General")
            .resourceId("android:id/title"));

    UiObject privacyHeading = TestHelper.mDevice.findObject(new UiSelector()
            .text("Privacy & Security")
            .resourceId("android:id/title"));

    UiObject searchHeading = TestHelper.mDevice.findObject(new UiSelector()
            .text("Search")
            .resourceId("android:id/title"));

    UiObject mozHeading = TestHelper.mDevice.findObject(new UiSelector()
            .text("Mozilla")
            .resourceId("android:id/title"));

    /* Go to Settings */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    openSettings();
    generalHeading.waitForExists(waitingTime);

    /* Check the first element and other headings are present */
    assertTrue(generalHeading.exists());
    assertTrue(searchHeading.exists());
    assertTrue(privacyHeading.exists());
    assertTrue(mozHeading.exists());
}
 
Example 6
Source File: BadURLTest.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@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 7
Source File: NotificationScreenshots.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void takeScreenshotOfNotification() throws Exception {
    onView(withId(R.id.urlView))
            .check(matches(isDisplayed()))
            .check(matches(hasFocus()))
            .perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton());

    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString(webServer.getHostName()))));

    final UiObject openAction = device.findObject(new UiSelector()
            .descriptionContains(getString(R.string.notification_action_open))
            .resourceId("android:id/action0")
            .enabled(true));

    device.openNotification();

    try {
        if (!openAction.waitForExists(waitingTime)) {
            // The notification is not expanded. Let's expand it now.
            device.findObject(new UiSelector()
                    .text(getString(R.string.app_name)))
                    .swipeDown(20);

            assertTrue(openAction.waitForExists(waitingTime));
        }

        Screengrab.screenshot("DeleteHistory_NotificationBar");
    } finally {
        // Close notification tray again
        device.pressBack();
    }
}
 
Example 8
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private UiObject getActionBarItem(UiSelector selector, long timeout) throws InterruptedException {
  final long STEP_TIMEOUT = 5000;
  UiObject item = device.findObject(selector);

  for (long i = 0; i < timeout; i += STEP_TIMEOUT) {
    openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

    if (item.waitForExists(STEP_TIMEOUT)) {
      break;
    }
  }

  return item;
}
 
Example 9
Source File: ChangeSearchEngineTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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 10
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
private UiObject getById(String id) {
  UiObject obj = device.findObject(getIdSelector(id));
  obj.waitForExists(TIMEOUT);
  return obj;
}
 
Example 11
Source File: PinnedTileTests.java    From firefox-echo-show with Mozilla Public License 2.0 4 votes vote down vote up
@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 12
Source File: SwitchContextTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void settingsToFocus() throws UiObjectNotFoundException {

    // Initialize UiDevice instance
    final int LAUNCH_TIMEOUT = 5000;
    final String SETTINGS_APP = "com.android.settings";
    final UiObject settings = TestHelper.mDevice.findObject(new UiSelector()
            .packageName(SETTINGS_APP)
            .enabled(true));

    // Open a webpage
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString());
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();

    // Assert website is loaded
    TestHelper.waitForWebSiteTitleLoad();

    // Switch out of Focus, open settings app
    TestHelper.pressHomeKey();

    // 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
    Context context = InstrumentationRegistry.getInstrumentation()
            .getTargetContext()
            .getApplicationContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(SETTINGS_APP);
    context.startActivity(intent);

    // switch to Focus
    settings.waitForExists(waitingTime);
    assertTrue(settings.exists());
    TestHelper.openNotification();

    // If simulator has more recent message, the options need to be expanded
    TestHelper.expandNotification();
    TestHelper.notificationOpenItem.click();

    // Verify that it's on the main view, showing the previous browsing session
    TestHelper.browserURLbar.waitForExists(waitingTime);
    assertTrue(TestHelper.browserURLbar.exists());
    TestHelper.waitForWebSiteTitleLoad();
}
 
Example 13
Source File: AddToHomescreenTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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 14
Source File: AddToHomescreenTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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 15
Source File: AddToHomescreenTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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 16
Source File: SettingsBlockToggleTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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 17
Source File: URLMismatchTest.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void MismatchTest() throws UiObjectNotFoundException {
    String searchString = String.format("mozilla focus - %s Search", "google");
    UiObject googleWebView = TestHelper.mDevice.findObject(new UiSelector()
            .description(searchString)
            .className("android.webkit.WebView"));

    // 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 that at least 1 search hint is displayed and click it.
    TestHelper.mDevice.pressKeyCode(KEYCODE_SPACE);
    TestHelper.suggestionList.waitForExists(waitingTime);
    assertTrue(TestHelper.suggestionList.getChildCount() >= 1);

    onView(allOf(withText(containsString("mozilla")),
            withId(R.id.suggestion),
            isDescendantOfA(childAtPosition(withId(R.id.suggestionList), 1))))
            .check(matches(isDisplayed()));

    // WebView is displayed
    TestHelper.pressEnterKey();
    googleWebView.waitForExists(waitingTime);
    TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime);

    // The displayed URL contains mozilla. Click on it to edit it again.
    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString("mozilla"))))
            .perform(click());

    // Type "moz" - Verify that it auto-completes to "mozilla.org" and then load the website
    onView(withId(R.id.urlView))
            .perform(click(), replaceText("mozilla"))
            .check(matches(withText("mozilla.org")))
            .perform(pressImeActionButton());

    // Wait until site is loaded
    onView(withId(R.id.webview))
            .check(matches(isDisplayed()));
    TestHelper.progressBar.waitUntilGone(webPageLoadwaitingTime);

    // The displayed URL contains www.mozilla.org
    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString("www.mozilla.org"))));
}