androidx.test.espresso.ViewInteraction Java Examples

The following examples show how to use androidx.test.espresso.ViewInteraction. 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: 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 #2
Source File: EmailPasswordTest.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Test
public void failedSignInTest() {
    String email = "[email protected]";
    String password = "123456";

    // Make sure we're signed out
    signOutIfPossible();

    // Enter email
    enterEmail(email);

    // Enter password
    enterPassword(password);

    // Click sign in
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.emailSignInButton), withText(R.string.sign_in),
                    withParent(withId(R.id.emailPasswordButtons)),
                    isDisplayed()));
    appCompatButton.perform(click());

    // Check that auth failed
    onView(withText(R.string.auth_failed))
            .check(matches(isDisplayed()));
}
 
Example #3
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 #4
Source File: Filter.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    pauseShort();
    ViewInteraction actionMenuItemView = onView(
        allOf(withId(R.id.action_filter), withContentDescription(FILTER_BUTTON_TAG),
            new ChildAtPosition(
                new ChildAtPosition(withId(R.id.toolbar), FILTER_BUTTON_OPEN),
                FILTER_ACTION),
            isDisplayed()));
    actionMenuItemView.perform(click());

    pauseLong();
    ViewInteraction appCompatButton = onView(
        allOf(withId(android.R.id.button3), withText(FILTER_CLOSE_TAG),
            new ChildAtPosition(
                new ChildAtPosition(withClassName(is("android.widget.ScrollView")),
                    FILTER_BUTTON_CLOSE),
                FILTER_ACTION)));
    appCompatButton.perform(scrollTo(), click());
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: WayTodayStartStopTest.java    From itag with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void activity_shouldStartWayToday1h() {
    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));

    }
}
 
Example #10
Source File: WayTodayStartStopTest.java    From itag with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void activity_shouldStartWayToday5min() {
    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_min_5))
                .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(5 * 60 * 1000));
        assertThat(p.getBoolean("wt", false), is(true));
    }
}
 
Example #11
Source File: WayTodayStartStopTest.java    From itag with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void activity_shouldStartWayTodayContiniously() {
    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_continuously))
                .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(1));
    }
}
 
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: EmailPasswordTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void enterPassword(String password) {
    ViewInteraction passwordField = onView(
            allOf(withId(R.id.fieldPassword),
                    withParent(withId(R.id.emailPasswordFields)),
                    isDisplayed()));
    passwordField.perform(replaceText(password));
}
 
Example #18
Source File: MultiTabsActivityTest.java    From under-the-hood with Apache License 2.0 5 votes vote down vote up
@Test
public void multiTabsActivityTest() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_start_dark_multi_page), withText("Start Multi Page")));
    appCompatButton.perform(scrollTo(), click());

    ViewInteraction switchableViewpager = onView(
            allOf(withId(R.id.view_pager), isDisplayed()));
    switchableViewpager.perform(swipeLeft());

    ViewInteraction switchableViewpager2 = onView(
            allOf(withId(R.id.view_pager), isDisplayed()));
    switchableViewpager2.perform(swipeLeft());

    ViewInteraction textView = onView(
            allOf(withText("Details"),
                    withParent(allOf(withId(R.id.tabs),
                            withParent(withId(R.id.view_pager)))),
                    isDisplayed()));
    textView.perform(click());

    ViewInteraction switchableViewpager3 = onView(
            allOf(withId(R.id.view_pager), isDisplayed()));
    switchableViewpager3.perform(swipeRight());

    ViewInteraction textView2 = onView(
            allOf(withText("General"),
                    withParent(allOf(withId(R.id.tabs),
                            withParent(withId(R.id.view_pager)))),
                    isDisplayed()));
    textView2.perform(click());

    ViewInteraction switchableViewpager4 = onView(
            allOf(withId(R.id.view_pager), isDisplayed()));
    switchableViewpager4.perform(swipeRight());

}
 
Example #19
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 #20
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 #21
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 #22
Source File: PollingTimeoutIdler.java    From samples-android with Apache License 2.0 5 votes vote down vote up
public PollingTimeoutIdler(ViewInteraction viewInteraction, ViewAssertion viewAssertion, long timeout) {
    mViewAssertion = viewAssertion;
    mTimeout = timeout;
    mStartTime = System.currentTimeMillis();

    viewInteraction.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            mTestView = view;
        }
    });
}
 
Example #23
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 #24
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 #25
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 #26
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 #27
Source File: WayTodayStartStopTest.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 #28
Source File: RegistrationScreenInteractor.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
private ViewInteraction onCreateAccountButton() {
    return onView(withId(R.id.create_account_tv));
}
 
Example #29
Source File: RegistrationScreenInteractor.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
private ViewInteraction onEmailView() {
    return onView(withTagValue(is((Object) "email")));
}
 
Example #30
Source File: RegistrationScreenInteractor.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
private ViewInteraction onNameView() {
    return onView(withTagValue(is((Object) "name")));
}