Search in sources :

Example 51 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class BrowserScreenScreenshots method takeScreenshotOfTabsTrayAndErase.

private void takeScreenshotOfTabsTrayAndErase() throws Exception {
    final UiObject mozillaImage = device.findObject(new UiSelector().resourceId("download").enabled(true));
    UiObject imageMenuTitle = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/topPanel").enabled(true));
    UiObject openNewTabTitle = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/design_menu_item_text").index(0).enabled(true));
    UiObject multiTabBtn = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/tabs").enabled(true));
    UiObject eraseHistoryBtn = device.findObject(new UiSelector().text(getString(R.string.tabs_tray_action_erase)).enabled(true));
    Assert.assertTrue(mozillaImage.waitForExists(waitingTime));
    mozillaImage.dragTo(mozillaImage, 7);
    assertTrue(imageMenuTitle.waitForExists(waitingTime));
    Assert.assertTrue(imageMenuTitle.exists());
    Screengrab.screenshot("Image_Context_Menu");
    // Open a new tab
    openNewTabTitle.click();
    assertTrue(multiTabBtn.waitForExists(waitingTime));
    multiTabBtn.click();
    assertTrue(eraseHistoryBtn.waitForExists(waitingTime));
    Screengrab.screenshot("Multi_Tab_Menu");
    eraseHistoryBtn.click();
    device.wait(Until.findObject(By.res("org.mozilla.focus.debug", "snackbar_text")), waitingTime);
    Screengrab.screenshot("YourBrowsingHistoryHasBeenErased");
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector)

Example 52 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class BrowserScreenScreenshots method takeScreenshotsOfOpenWithAndShare.

private void takeScreenshotsOfOpenWithAndShare() throws Exception {
    /* Open_With View */
    UiObject openWithBtn = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/open_select_browser").enabled(true));
    assertTrue(openWithBtn.waitForExists(waitingTime));
    openWithBtn.click();
    UiObject shareList = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/apps").enabled(true));
    assertTrue(shareList.waitForExists(waitingTime));
    Screengrab.screenshot("OpenWith_Dialog");
    /* Share View */
    UiObject shareBtn = device.findObject(new UiSelector().resourceId("org.mozilla.focus.debug: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();
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector)

Example 53 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class BadURLTest method BadURLcheckTest.

@Test
public void BadURLcheckTest() throws InterruptedException, 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();
    TestHelper.tryAgainBtn.waitForExists(waitingTime);
    /* Check for error message */
    assertTrue(TestHelper.notFoundMsg.exists());
    assertTrue(TestHelper.notFounddetailedMsg.exists());
    assertTrue(TestHelper.tryAgainBtn.exists());
    /* provide market URL that is handled by Google Play app */
    TestHelper.floatingEraseButton.perform(click());
    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);
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 54 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class SearchEngineSelectionTest method SearchTest.

@Test
public void SearchTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject SearchEngineSelection = TestHelper.settingsList.getChild(new UiSelector().className("android.widget.LinearLayout").instance(1));
    UiObject searchName = SearchEngineSelection.getChild(new UiSelector().resourceId("android:id/title").enabled(true));
    UiObject googleWebView = TestHelper.mDevice.findObject(new UiSelector().description("mozilla focus - Google Search").className("android.webkit.WebView"));
    /* Go to Settings and select the Search Engine */
    assertTrue(TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime));
    openSettings();
    /* Set the search engine to Google */
    SearchEngineSelection.click();
    /* Get the dynamically generated search engine list from this settings page */
    UiScrollable SearchEngineList = new UiScrollable(new UiSelector().resourceId("org.mozilla.focus.debug:id/search_engine_group").enabled(true));
    UiObject GoogleSelection = SearchEngineList.getChildByText(new UiSelector().className(RadioButton.class), "Google");
    GoogleSelection.waitForExists(waitingTime);
    GoogleSelection.click();
    TestHelper.pressBackKey();
    // Now it's changed to Google
    assertTrue(searchName.getText().equals("Google"));
    TestHelper.settingsHeading.waitForExists(waitingTime);
    TestHelper.pressBackKey();
    /* load blank spaces and press enter key for search, it should not do anything */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("   ");
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.inlineAutocompleteEditText.exists());
    /* Now do some search */
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla focus");
    TestHelper.hint.waitForExists(waitingTime);
    // Check the search hint bar is correctly displayed
    assertTrue(TestHelper.hint.getText().equals("Search for mozilla focus"));
    TestHelper.hint.click();
    /* Browser shows google search webview*/
    googleWebView.waitForExists(waitingTime);
    assertTrue(TestHelper.browserURLbar.getText().contains("google"));
    assertTrue(TestHelper.browserURLbar.getText().contains("mozilla"));
    assertTrue(TestHelper.browserURLbar.getText().contains("focus"));
    /* tap url bar, and check it displays search term instead of URL */
    TestHelper.browserURLbar.click();
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    assertEquals(TestHelper.inlineAutocompleteEditText.getText(), "mozilla focus");
    TestHelper.pressEnterKey();
    googleWebView.waitForExists(waitingTime);
    assertTrue(TestHelper.browserURLbar.getText().contains("google"));
    assertTrue(TestHelper.browserURLbar.getText().contains("mozilla"));
    assertTrue(TestHelper.browserURLbar.getText().contains("focus"));
    /* Now do another search */
    TestHelper.browserURLbar.click();
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla focus");
    TestHelper.hint.waitForExists(waitingTime);
    // Check the search hint bar is correctly displayed
    assertTrue(TestHelper.hint.getText().equals("Search for mozilla focus"));
    TestHelper.hint.click();
    /* Browser shows google search webview*/
    assertTrue(TestHelper.browserURLbar.getText().contains("mozilla"));
    assertTrue(TestHelper.browserURLbar.getText().contains("focus"));
    /* tap url bar, and check it displays search term instead of URL */
    TestHelper.browserURLbar.click();
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    assertEquals(TestHelper.inlineAutocompleteEditText.getText(), "mozilla focus");
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) RadioButton(android.widget.RadioButton) UiScrollable(android.support.test.uiautomator.UiScrollable) Test(org.junit.Test)

Example 55 with UiSelector

use of android.support.test.uiautomator.UiSelector in project chefly_android by chef-ly.

the class PermissionGranter method allowPermissionsIfNeeded.

public static void allowPermissionsIfNeeded(String permissionNeeded) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(permissionNeeded)) {
            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector().clickable(true).checkable(false).index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }
    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) UiDevice(android.support.test.uiautomator.UiDevice) UiObjectNotFoundException(android.support.test.uiautomator.UiObjectNotFoundException)

Aggregations

UiSelector (android.support.test.uiautomator.UiSelector)125 UiObject (android.support.test.uiautomator.UiObject)103 Test (org.junit.Test)46 UiScrollable (android.support.test.uiautomator.UiScrollable)29 Intent (android.content.Intent)26 SmallTest (android.support.test.filters.SmallTest)18 KeyguardManager (android.app.KeyguardManager)14 UiObjectNotFoundException (android.support.test.uiautomator.UiObjectNotFoundException)9 UiDevice (android.support.test.uiautomator.UiDevice)3 SmallTest (androidx.test.filters.SmallTest)3 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 BySelector (android.support.test.uiautomator.BySelector)2 UiObject2 (android.support.test.uiautomator.UiObject2)2 Activity (android.app.Activity)1 Preference (android.preference.Preference)1 ViewInteraction (android.support.test.espresso.ViewInteraction)1 MediumTest (android.support.test.filters.MediumTest)1 RadioButton (android.widget.RadioButton)1