Java Code Examples for androidx.test.espresso.ViewInteraction#perform()

The following examples show how to use androidx.test.espresso.ViewInteraction#perform() . 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: TutorialsActivityTest.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
@Test
public void tutorialsActivityTest() {
    mActivityTestRule.launchActivity(new Intent());
    sleep();
    ViewInteraction baldImageButton = onView(withId(R.id.right_arrow));
    baldImageButton.perform(longClick());
    sleep();
    ViewInteraction appCompatTextView = onView(withId(R.id.short_presses));
    appCompatTextView.perform(click());
    sleep();
    ViewInteraction appCompatTextView2 = onView(withId(R.id.long_presses));
    appCompatTextView2.perform(longClick());
    sleep();
    ViewInteraction baldImageButton2 = onView(withId(R.id.right_arrow));
    baldImageButton2.perform(longClick());
    sleep();
    ViewInteraction baldImageButton3 = onView(withId(R.id.left_arrow));
    baldImageButton3.perform(longClick());
    sleep();
    ViewInteraction baldImageButton4 = onView(withId(R.id.right_arrow));
    baldImageButton4.perform(longClick());
    sleep();
    ViewInteraction baldImageButton5 = onView(withId(R.id.right_arrow));
    baldImageButton5.perform(longClick());
}
 
Example 2
Source File: InterstitialAdTest.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Test
public void interstitialAdTest() {
    // Wait for ad to load
    mAdResource.setIsLoadingAd(true);

    // Confirm that banner ad appears
    onView(withId(R.id.adView))
            .check(matches(isDisplayed()));

    // Click show interstitial button
    ViewInteraction showInterstitialButton = onView(
            allOf(withId(R.id.loadInterstitialButton),
                    withText(R.string.interstitial_button_text),
                    isDisplayed()));
    showInterstitialButton.perform(click());

    // Click close interstitial button
    ViewInteraction closeInterstitialButton = onView(
            allOf(withContentDescription("Interstitial close button"), isDisplayed()));
    closeInterstitialButton.perform(click());

    // Confirm that we're on the second activity
    onView(withText(R.string.second_activity_content))
            .check(matches(isDisplayed()));
}
 
Example 3
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Test
public void mainActivityTest() {
    // Select favorite food if the dialog appears
    selectFavoriteFoodIfPossible("Hot Dogs");

    // Initial title
    checkTitleText(R.string.pattern1_title);

    // Swipe, make sure we see the right titles
    ViewInteraction viewPager = onView(withId(R.id.viewPager));
    viewPager.check(matches(isDisplayed()));

    // Swipe left
    viewPager.perform(swipeLeft());
    checkTitleText(R.string.pattern2_title);

    // Swipe left
    viewPager.perform(swipeLeft());
    checkTitleText(R.string.pattern3_title);

    // Swipe back right
    viewPager.perform(swipeRight());
    checkTitleText(R.string.pattern2_title);
}
 
Example 4
Source File: SimpleLightActivityTest.java    From under-the-hood with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleLightActivityTest() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_start_light), withText("Start Light Debugview")));
    appCompatButton.perform(scrollTo(), click());

    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.recycler_view), isDisplayed()));
    recyclerView.perform(actionOnItemAtPosition(1, click()));

    ViewInteraction appCompatButton2 = onView(
            allOf(withId(R.id.btn_log), withText("Log")));
    appCompatButton2.perform(scrollTo(), click());

    ViewInteraction appCompatButton3 = onView(
            allOf(withId(R.id.btn_copy_clipboard), withText("Copy to Clipboard")));
    appCompatButton3.perform(scrollTo(), click());
}
 
Example 5
Source File: TestAddNumber.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddNumber() {
  ViewInteraction firstNumber = onView(withId(R.id.fieldFirstNumber));
  ViewInteraction secondNumber = onView(withId(R.id.fieldSecondNumber));
  ViewInteraction addButton = onView(withId(R.id.buttonCalculate));

  firstNumber.perform(replaceText("32"));
  secondNumber.perform(replaceText("16"));

  addButton.perform(scrollTo(), click());

  Assert.assertTrue(
      new UiObject(new UiSelector()
        .resourceId("com.google.samples.quickstart.functions:id/fieldAddResult").text("48"))
      .waitForExists(60000));
}
 
Example 6
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Test
public void caughtExceptionTest() {
    // Make sure the checkbox is on screen
    ViewInteraction al = onView(
            allOf(withId(R.id.catchCrashCheckBox),
                    withText(R.string.catch_crash_checkbox_label),
                    isDisplayed()));

    // Click the checkbox if it's not already checked
    CheckBox checkBox = (CheckBox) mActivityTestRule.getActivity()
            .findViewById(R.id.catchCrashCheckBox);
    if (!checkBox.isChecked()) {
        al.perform(click());
    }

    // Cause a crash
    ViewInteraction ak = onView(
            allOf(withId(R.id.crashButton),
                    withText(R.string.crash_button_label),
                    isDisplayed()));
    ak.perform(click());
}
 
Example 7
Source File: Navigation.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
private void selectMenuItem(int menuItem) {
    pauseShort();
    ViewInteraction appCompatImageButton = onView(
        allOf(withContentDescription(NAVIGATION_DRAWER_TAG),
            new ChildAtPosition(allOf(withId(R.id.toolbar),
                new ChildAtPosition(
                    withClassName(is("com.google.android.material.appbar.AppBarLayout")),
                    NAVIGATION_DRAWER_BUTTON)),
                NAVIGATION_DRAWER_ACTION),
            isDisplayed()));
    appCompatImageButton.perform(click());

    pauseShort();
    ViewInteraction navigationMenuItemView = onView(
        allOf(new ChildAtPosition(allOf(withId(R.id.design_navigation_view),
            new ChildAtPosition(withId(R.id.nav_drawer), NAVIGATION_DRAWER_BUTTON)), menuItem),
            isDisplayed()));
    navigationMenuItemView.perform(click());
}
 
Example 8
Source File: DrawerActivityTest.java    From under-the-hood with Apache License 2.0 6 votes vote down vote up
@Test
public void drawerActivityTest() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_start_drawer), withText("Start Drawer Debugview")));
    appCompatButton.perform(scrollTo(), click());

    ViewInteraction appCompatButton2 = onView(
            allOf(withId(R.id.toggle_drawer), withText("Toggle Drawer"),
                    withParent(allOf(withId(R.id.content_frame),
                            withParent(withId(R.id.drawer_layout)))),
                    isDisplayed()));
    appCompatButton2.perform(click());

    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.recycler_view), isDisplayed()));
    recyclerView.perform(actionOnItemAtPosition(1, click()));

    ViewInteraction appCompatButton3 = onView(
            allOf(withId(R.id.btn_log), withText("Log")));
    appCompatButton3.perform(scrollTo(), click());

}
 
Example 9
Source File: WayTodayStartStopTest.java    From itag with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void activity_shouldStopWayToday() {
    try (ActivityScenario<MainActivity> ignored = ActivityScenario.launch(MainActivity.class)) {
        Application application = ApplicationProvider.getApplicationContext();
        SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(application);

        assertThat(LocationsTracker.isUpdating, is(false));

        ViewInteraction vi = onView(withId(R.id.btn_waytoday));
        vi.perform(click());
        onView(withText(R.string.freq_hour_1))
                .perform(click());
        ArgumentCaptor<LocationsTracker.TrackingState> state =
                ArgumentCaptor.forClass(LocationsTracker.TrackingState.class);

        verify(mockTrackingStateListener, timeout(5000).atLeast(1)).onStateChange(state.capture());
        List<LocationsTracker.TrackingState> states =
                state.getAllValues();
        assertThat(states.size(), greaterThan(0));
        assertThat(states.get(0).isUpdating, is(true));
        assertThat(LocationsTracker.isUpdating, is(true));
        assertThat(p.getInt("freq", -1), equalTo(60 * 60 * 1000));
        assertThat(p.getBoolean("wt", false), is(true));

        reset(mockTrackingStateListener);

        vi.perform(click());
        onView(withText(R.string.off))
                .perform(click());
        verify(mockTrackingStateListener, timeout(5000).atLeast(1)).onStateChange(state.capture());
        states =
                state.getAllValues();
        assertThat(states.size(), greaterThan(0));
        assertThat(LocationsTracker.isUpdating, is(false));
        assertThat(p.getInt("freq", -1), equalTo(60 * 60 * 1000));
        assertThat(p.getBoolean("wt", true), is(false));

    }
}
 
Example 10
Source File: WayTodayFirstSessionTest.java    From itag with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void activity_shouldHaveWayTodayMenu() {

    try (ActivityScenario<MainActivity> ignored = ActivityScenario.launch(MainActivity.class)) {

        ViewInteraction vi = onView(withId(R.id.btn_waytoday));
        vi.perform(click());
        onView(withText(R.string.off))
                .perform(click());
    }
}
 
Example 11
Source File: WayTodayChangeTrackIDTest.java    From itag with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void activity_shouldHaveWayTodayMenu() {

    try (ActivityScenario<MainActivity> ignored = ActivityScenario.launch(MainActivity.class)) {

        ViewInteraction vi = onView(withId(R.id.btn_waytoday));
        vi.perform(click());
        onView(withText(R.string.off))
                .perform(click());
    }
}
 
Example 12
Source File: EspressoTests.java    From mongol-library with MIT License 5 votes vote down vote up
@Test
public void mongolFontTest() {
    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.rvApiDemoList),
                    childAtPosition(
                            withId(R.id.activity_main),
                            0)));
    recyclerView.perform(actionOnItemAtPosition(4, click()));

}
 
Example 13
Source File: MultiTapActivityTest.java    From under-the-hood with Apache License 2.0 5 votes vote down vote up
@Test
public void multiTapActivityTEst() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_more), withText("More")));
    appCompatButton.perform(scrollTo(), click());

    ViewInteraction appCompatTextView = onView(
            allOf(withId(R.id.tv_doubletap), withText("Double Tap Me"), isDisplayed()));
    appCompatTextView.perform(click());

    ViewInteraction appCompatTextView2 = onView(
            allOf(withId(R.id.tv_doubletap), withText("Double Tap Me"), isDisplayed()));
    appCompatTextView2.perform(click());

    SystemClock.sleep(300);

    pressBack();

    SystemClock.sleep(300);

    ViewInteraction appCompatTextView5 = onView(
            allOf(withId(R.id.tv_tripletap), withText("Triple Tap Me"), isDisplayed()));
    appCompatTextView5.perform(click());

    ViewInteraction appCompatTextView6 = onView(
            allOf(withId(R.id.tv_tripletap), withText("Triple Tap Me"), isDisplayed()));
    appCompatTextView6.perform(click());

    ViewInteraction appCompatTextView7 = onView(
            allOf(withId(R.id.tv_tripletap), withText("Triple Tap Me"), isDisplayed()));
    appCompatTextView7.perform(click());

    SystemClock.sleep(300);

    pressBack();
}
 
Example 14
Source File: EmailPasswordTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void enterEmail(String email) {
    ViewInteraction emailField = onView(
            allOf(withId(R.id.fieldEmail),
                    withParent(withId(R.id.emailPasswordFields)),
                    isDisplayed()));
    emailField.perform(replaceText(email));
}
 
Example 15
Source File: EspressoTestUtils.java    From Kore with Apache License 2.0 5 votes vote down vote up
public static void clickRecyclerViewItem(String text, int resourceId) {
    ViewInteraction viewInteraction = onView(allOf(withId(resourceId),
                                                   hasDescendant(withText(containsString(text))),
                                                   isDisplayed()));
    viewInteraction.perform(RecyclerViewActions.scrollTo(hasDescendant(withText(containsString(text)))));
    viewInteraction.perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(containsString(text))),
                                                             click()));
}
 
Example 16
Source File: SOSActivityTest.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
@Test
public void sOSActivityTest() {
    mActivityTestRule.launchActivity(new Intent());
    ViewInteraction baldImageButton2 = onView(allOf(withId(R.id.sos), childAtPosition(allOf(withId(R.id.top_bar), childAtPosition(withId(R.id.container), 0)), 0), isDisplayed()));
    sleep();
    baldImageButton2.perform(longClick());
    ViewInteraction baldLinearLayoutButton = onView(allOf(withId(R.id.ec1), childAtPosition(childAtPosition(withId(android.R.id.content), 0), 2), isDisplayed()));
    sleep();
    baldLinearLayoutButton.perform(longClick());
    pressBack();
    pressBack();
    sleep();
}
 
Example 17
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void selectFavoriteFoodIfPossible(String food) {
    try{
        ViewInteraction appCompatTextView = onView(
                allOf(withId(android.R.id.text1), withText(food),
                        withParent(allOf(withId(R.id.select_dialog_listview),
                                withParent(withId(R.id.contentPanel)))),
                        isDisplayed()));
        appCompatTextView.perform(click());
    } catch (NoMatchingViewException e) {
        // This is ok
    }
}
 
Example 18
Source File: Scanner.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
private void scannerAction(String tag) {
    pauseShort();
    ViewInteraction actionMenuItemView = onView(
        allOf(withId(R.id.action_scanner), withContentDescription(tag),
            new ChildAtPosition(new ChildAtPosition(withId(R.id.toolbar), SCANNER_BUTTON),
                SCANNER_ACTION),
            isDisplayed()));
    actionMenuItemView.perform(click());
}
 
Example 19
Source File: EspressoTests.java    From mongol-library with MIT License 4 votes vote down vote up
@Test
public void mongolToastTest() {
    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.rvApiDemoList),
                    childAtPosition(
                            withId(R.id.activity_main),
                            0)));
    recyclerView.perform(actionOnItemAtPosition(7, click()));

    ViewInteraction appCompatButton = onView(
            allOf(withText("Toast"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            0),
                    isDisplayed()));
    appCompatButton.perform(click());

    ViewInteraction appCompatButton2 = onView(
            allOf(withText("Mongol Toast"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            1),
                    isDisplayed()));
    appCompatButton2.perform(click());

    ViewInteraction appCompatButton3 = onView(
            allOf(withText("Mongol Toast (xml string)"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            2),
                    isDisplayed()));
    appCompatButton3.perform(click());

    pressBack();

}
 
Example 20
Source File: AddUserTest.java    From openScale with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void addUserTest() {
    mActivityTestRule.launchActivity(null);

    ViewInteraction editText = onView(
            allOf(withId(R.id.txtUserName),
                    childAtPosition(
                            allOf(withId(R.id.rowUserName),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            0)),
                            1)));
    editText.perform(scrollTo(), click());

    ViewInteraction editText2 = onView(
            allOf(withId(R.id.txtUserName),
                    childAtPosition(
                            allOf(withId(R.id.rowUserName),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            0)),
                            1)));
    editText2.perform(scrollTo(), replaceText("test"), closeSoftKeyboard());

    ViewInteraction editText3 = onView(
            allOf(withId(R.id.txtBodyHeight),
                    childAtPosition(
                            allOf(withId(R.id.rowBodyHeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            6)),
                            1)));
    editText3.perform(scrollTo(), replaceText("180"), closeSoftKeyboard());

    onView(withId(R.id.txtBirthday)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).perform(PickerActions.setDate(1990,  1, 19));
    onView(withId(android.R.id.button1)).perform(click());

    ViewInteraction editText5 = onView(
            allOf(withId(R.id.txtInitialWeight),
                    childAtPosition(
                            allOf(withId(R.id.tableRowInitialWeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            7)),
                            1)));
    editText5.perform(scrollTo(), replaceText("80"), closeSoftKeyboard());

    ViewInteraction editText6 = onView(
            allOf(withId(R.id.txtGoalWeight),
                    childAtPosition(
                            allOf(withId(R.id.rowGoalWeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            8)),
                            1)));
    editText6.perform(scrollTo(), replaceText("60"), closeSoftKeyboard());

    onView(withId(R.id.txtGoalDate)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).perform(PickerActions.setDate(2018,  1, 31));
    onView(withId(android.R.id.button1)).perform(click());

    onView(withId(R.id.saveButton)).perform(click());
}