Search in sources :

Example 1 with ViewInteraction

use of androidx.test.espresso.ViewInteraction in project quickstart-android by firebase.

the class MainActivityTest method selectFavoriteFoodIfPossible.

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
    }
}
Also used : ViewInteraction(androidx.test.espresso.ViewInteraction) NoMatchingViewException(androidx.test.espresso.NoMatchingViewException)

Example 2 with ViewInteraction

use of androidx.test.espresso.ViewInteraction in project SeriesGuide by UweTrottmann.

the class ShowsActivityTest method testAddShowAndSetWatchedThenReturn.

@Test
public void testAddShowAndSetWatchedThenReturn() {
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction floatingActionButton = onView(allOf(withId(R.id.buttonShowsAdd), withContentDescription(R.string.action_shows_add), childAtPosition(withId(R.id.rootLayoutShows), 2), isDisplayed()));
    floatingActionButton.perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(700);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction recyclerView = onView(allOf(withId(R.id.recyclerViewShowsDiscover), childAtPosition(withId(R.id.constraintLayoutShowsDiscover), 1)));
    recyclerView.perform(actionOnItemAtPosition(2, click()));
    ViewInteraction appCompatButton = onView(allOf(withId(R.id.buttonPositive), withText(R.string.action_shows_add), childAtPosition(childAtPosition(withClassName(is("android.widget.LinearLayout")), 2), 2), isDisplayed()));
    appCompatButton.perform(click());
    ViewInteraction recyclerView2 = onView(allOf(withId(R.id.recyclerViewShowsDiscover), childAtPosition(withId(R.id.constraintLayoutShowsDiscover), 1)));
    recyclerView2.perform(actionOnItemAtPosition(2, click()));
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction appCompatButton2 = onView(allOf(withId(R.id.buttonEpisodeWatched), withText(R.string.action_watched), withContentDescription(R.string.action_watched), childAtPosition(childAtPosition(withId(R.id.include_buttons), 0), 0), isDisplayed()));
    appCompatButton2.perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    pressBack();
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(700);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    pressBack();
}
Also used : ViewInteraction(androidx.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 3 with ViewInteraction

use of androidx.test.espresso.ViewInteraction in project PocketHub by pockethub.

the class CreateCommentActivityTest method testEmptyCommentIsProhibited.

/**
 * Verify empty comment can't be created
 *
 * @throws Throwable
 */
@Test
public void testEmptyCommentIsProhibited() {
    ViewInteraction createMenu = onView(withId(R.id.m_apply));
    ViewInteraction comment = onView(withId(R.id.et_comment));
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
    closeSoftKeyboard();
    comment.perform(ViewActions.typeText("a"));
    createMenu.check(ViewAssertions.matches(isEnabled()));
    comment.perform(ViewActions.replaceText(""));
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
}
Also used : ViewInteraction(androidx.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 4 with ViewInteraction

use of androidx.test.espresso.ViewInteraction in project PocketHub by pockethub.

the class EditIssueActivityTest method testSaveMenuEnabled.

/**
 * Verify save menu is properly enabled/disable depending on the issue have
 * a non-empty title
 *
 * @throws Throwable
 */
@Test
public void testSaveMenuEnabled() {
    ViewInteraction createMenu = onView(withId(R.id.m_apply));
    ViewInteraction comment = onView(withId(R.id.et_issue_title));
    ViewVisibilityIdlingResource idlingResource = new ViewVisibilityIdlingResource(activityTestRule.getActivity(), R.id.sv_issue_content, View.VISIBLE);
    IdlingRegistry.getInstance().register(idlingResource);
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
    closeSoftKeyboard();
    comment.perform(ViewActions.typeText("a"));
    createMenu.check(ViewAssertions.matches(isEnabled()));
    comment.perform(ViewActions.replaceText(""));
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
    IdlingRegistry.getInstance().unregister(idlingResource);
}
Also used : ViewInteraction(androidx.test.espresso.ViewInteraction) ViewVisibilityIdlingResource(com.github.pockethub.android.tests.ViewVisibilityIdlingResource) Test(org.junit.Test)

Example 5 with ViewInteraction

use of androidx.test.espresso.ViewInteraction in project PocketHub by pockethub.

the class CreateCommentActivityTest method testEmptyCommentIsProhibited.

/**
 * Verify empty comment can't be created
 */
@Test
public void testEmptyCommentIsProhibited() {
    ViewInteraction createMenu = onView(withId(R.id.m_apply));
    ViewInteraction comment = onView(withId(R.id.et_comment));
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
    closeSoftKeyboard();
    comment.perform(ViewActions.typeText("a"));
    createMenu.check(ViewAssertions.matches(isEnabled()));
    comment.perform(ViewActions.replaceText(""));
    createMenu.check(ViewAssertions.matches(not(isEnabled())));
}
Also used : ViewInteraction(androidx.test.espresso.ViewInteraction) Test(org.junit.Test)

Aggregations

ViewInteraction (androidx.test.espresso.ViewInteraction)17 Test (org.junit.Test)16 LargeTest (androidx.test.filters.LargeTest)9 Intent (android.content.Intent)1 CheckBox (android.widget.CheckBox)1 NoMatchingViewException (androidx.test.espresso.NoMatchingViewException)1 UiObject (androidx.test.uiautomator.UiObject)1 UiSelector (androidx.test.uiautomator.UiSelector)1 ViewVisibilityIdlingResource (com.github.pockethub.android.tests.ViewVisibilityIdlingResource)1