android.support.test.espresso.ViewInteraction Java Examples

The following examples show how to use android.support.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: MainActivityTest.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void mainActivityTest() {
    // Test send a request to myApi/sayHi with a human's name
    // and expect the response "Hi, Human's Name!"
    ViewInteraction nameInput = onView(allOf(withId(R.id.person_name_input), isDisplayed()));
    nameInput.perform(replaceText("Human 1"));

    ViewInteraction sendButton = onView(
            allOf(withId(R.id.send_bn), withText("Send"), isDisplayed()));
    sendButton.perform(click());

    // Sleep for a 1 second to receive a response and update R.id.response_view
    SystemClock.sleep(1000);

    onView(withId(R.id.response_view)).check(matches(withText("Hi, Human 1!")));
}
 
Example #2
Source File: MainActivityTest.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void mainActivityTest() {
    // Test send a request to myApi/sayHi with a human's name
    // and expect the response "Hi, Human's Name!"
    ViewInteraction nameInput = onView(allOf(withId(R.id.person_name_input), isDisplayed()));
    nameInput.perform(replaceText("Human 1"));

    ViewInteraction sendButton = onView(
            allOf(withId(R.id.send_bn), withText("Send"), isDisplayed()));
    sendButton.perform(click());

    // Sleep for a 1 second to receive a response and update R.id.response_view
    SystemClock.sleep(1000);

    onView(withId(R.id.response_view)).check(matches(withText("Hi, Human 1!")));
}
 
Example #3
Source File: MainActivityTest.java    From MathView with Apache License 2.0 6 votes vote down vote up
@Test
public void mainActivityTest() throws Throwable {
  ViewInteraction webView = onView(
    allOf(childAtPosition(
      allOf(withId(R.id.activity_main),
        childAtPosition(
          withId(android.R.id.content),
          0)),
      0),
      isDisplayed()));
  webView.check(matches(isDisplayed()));

  ViewInteraction editText = onView(
    allOf(withId(R.id.input_view),
      childAtPosition(
        allOf(withId(R.id.activity_main),
          childAtPosition(
            withId(android.R.id.content),
            0)),
        1),
      isDisplayed()));
  editText.check(matches(isDisplayed()));
}
 
Example #4
Source File: NumberPadTimePickerDialogTest.java    From NumberPadTimePicker with Apache License 2.0 6 votes vote down vote up
private static void verifyViewEnabledStates(TestCase test) {
    ViewInteraction[] buttonsInteractions = getButtonInteractions();
    ViewInteraction[] altButtonsInteractions = getAltButtonInteractions();
    for (int digit : test.sequence) {
        buttonsInteractions[digit]
                .check(ViewAssertions.matches(ViewMatchers.isEnabled()))
                .perform(ViewActions.click());
    }
    for (int i = 0; i < 10; i++) {
        buttonsInteractions[i].check(matchesIsEnabled(
                i >= test.numberKeysEnabledStart && i < test.numberKeysEnabledEnd));
        altButtonsInteractions[0].check(matchesIsEnabled(test.leftAltKeyEnabled));
        altButtonsInteractions[1].check(matchesIsEnabled(test.rightAltKeyEnabled));
    }

    Espresso.onView(ViewMatchers.withText(android.R.string.ok))
            .check(matchesIsEnabled(test.okButtonEnabled));

    ViewInteraction backspaceInteraction = Espresso.onView(
            ViewMatchers.withId(R.id.nptp_backspace));
    // Reset after each iteration by backspacing on the button just clicked.
    backspaceInteraction.check(matchesIsEnabled(true))
            .perform(ViewActions.longClick())
            .check(matchesIsEnabled(false));
}
 
Example #5
Source File: NumberPadTimePickerDialogTest.java    From NumberPadTimePicker with Apache License 2.0 6 votes vote down vote up
private static ViewInteraction[] getButtonInteractions() {
    ViewInteraction[] buttonsInteractions = new ViewInteraction[10];
    // We cannot rely on the withDigit() matcher to retrieve these because,
    // after performing a click on a button, the time display will update to
    // take on that button's digit text, and so withDigit() will return a matcher
    // that matches multiple views with that digit text: the button
    // itself and the time display. This will prevent us from performing
    // validation on the same ViewInteractions later.
    buttonsInteractions[0] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text10));
    buttonsInteractions[1] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text0));
    buttonsInteractions[2] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text1));
    buttonsInteractions[3] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text2));
    buttonsInteractions[4] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text3));
    buttonsInteractions[5] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text4));
    buttonsInteractions[6] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text5));
    buttonsInteractions[7] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text6));
    buttonsInteractions[8] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text7));
    buttonsInteractions[9] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text8));
    return buttonsInteractions;
}
 
Example #6
Source File: RoomListTest.java    From Android with MIT License 6 votes vote down vote up
@Test
public void runTest()throws Exception{
    ViewInteraction relativeLayout = onView(
            allOf(withId(R.id.bottom_notify),
                    withParent(withId(R.id.bottom_layout)),
                    isDisplayed()));
    relativeLayout.perform(click());
    ViewInteraction relativeLayout2 = onView(
            allOf(withId(R.id.bottom_notify),
                    withParent(withId(R.id.bottom_layout)),
                    isDisplayed()));
    relativeLayout2.perform(click());

    ViewInteraction relativeLayout3 = onView(
            allOf(withId(R.id.bottom_trash),
                    withParent(withId(R.id.bottom_layout)),
                    isDisplayed()));
    relativeLayout3.perform(click());
}
 
Example #7
Source File: HelpTest.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void helpTest() {
    ViewInteraction appCompatImageButton = onView(
            allOf(withContentDescription("Navigate up"),
                    withParent(withId(R.id.toolbar)),
                    isDisplayed()));
    appCompatImageButton.perform(click());

    ViewInteraction appCompatCheckedTextView = onView(
            allOf(withId(R.id.design_menu_item_text), withText("Help"), isDisplayed()));
    appCompatCheckedTextView.perform(click());

    ViewInteraction webView = onView(
            allOf(childAtPosition(
                    allOf(withId(R.id.linear_layout),
                            childAtPosition(
                                    withId(R.id.contentFrame),
                                    0)),
                    0),
                    isDisplayed()));
    webView.check(matches(isDisplayed()));
}
 
Example #8
Source File: SplashActivityTest.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
@Test
public void verifyMessageSentToMessageActivity() {

    ViewInteraction appCompatTextView2 = onView(
            allOf(withId(R.id.subtitle), withText("NEARBY"), isDisplayed()));
    appCompatTextView2.perform(click());

    // Types a message into a EditText element.
    onView(withId(R.id.searchText))
            .perform(typeText(MESSAGE), closeSoftKeyboard());


    //onView(withId(R.id.submit)).perform(click());

    // Verifies that the DisplayMessageActivity received an intent
    // with the correct package name and message.
    // Check that the text was changed.
    onView(withId(R.id.subtitle))
            .check(matches(withText(MESSAGE)));

}
 
Example #9
Source File: GroupSetTest.java    From Android with MIT License 6 votes vote down vote up
public void managerTest(){
    ViewInteraction groupNameView = onView(allOf(withId(R.id.groupset_manage),isDisplayed()));
    groupNameView.perform(click());

    ViewInteraction openView = onView(allOf(withId(R.id.toggle),withParent(withId(R.id.groupset_sureinvite)), isDisplayed()));
    openView.perform(click());

    ViewInteraction introduceView = onView(allOf(withId(R.id.groupset_introdue), isDisplayed()));
    introduceView.perform(click());
    ViewInteraction introduceEditView = onView(allOf(withId(R.id.edit), isDisplayed()));
    introduceEditView.perform(replaceText("introduce:" + TimeUtil.getTime(TimeUtil.getCurrentTimeInLong(), TimeUtil.DATE_FORMAT_HOUR_MIN)));
    ViewInteraction rightView = onView(allOf(withId(R.id.right_lin), isDisplayed()));
    rightView.perform(click());

    ViewInteraction transferView = onView(allOf(withId(R.id.groupset_transferto), isDisplayed()));
    transferView.perform(click());
    onData(allOf(withId(R.id.recyclerview),isDisplayed())).perform(actionOnItemAtPosition(0,click()));
    ViewInteraction confirmView = onView(allOf(withId(R.id.okBtn), isDisplayed()));
    confirmView.perform(click());
}
 
Example #10
Source File: MainActivityTest.java    From marvel with MIT License 6 votes vote down vote up
@Test
public void shouldBeAbleToSearchForTestCharacter() {
    // Launch the activity
    mainActivity.launchActivity(new Intent());

    // fix Travis locked device issue
    unlockScreen();

    // search for Test Character
    ViewInteraction appCompatAutoCompleteTextView = onView(
            allOf(withId(R.id.character), isDisplayed()));
    appCompatAutoCompleteTextView.perform(replaceText(TEST_CHARACTER_NAME));

    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.show), isDisplayed()));
    appCompatButton.perform(click());

    // Check view is loaded as we expect it to be
    onView(withText(TEST_CHARACTER_NAME)).check(matches(withText(TEST_CHARACTER_NAME)));
    onView(withId(R.id.description)).check(matches(withText(TEST_CHARACTER_DESCRIPTION)));
}
 
Example #11
Source File: GroupSetTest.java    From Android with MIT License 5 votes vote down vote up
public void otherTest() {
    ViewInteraction clearView = onView(withId(R.id.clear));
    clearView.perform(click());
    ViewInteraction cancelView = onView(withId(R.id.tv_popup_cancel)).check(matches(isDisplayed()));
    cancelView.perform(click());
    clearView.perform(click());
    DataInteraction confirmView = onData(anything()).inAdapterView(withId(R.id.list_view)).atPosition(0);
    confirmView.perform(click());

    ViewInteraction exitView = onView(withId(R.id.delete));
    exitView.perform(click());
    ViewInteraction okView = onView(allOf(withId(R.id.okBtn), isDisplayed()));
    okView.perform(click());
}
 
Example #12
Source File: SettingsTest.java    From open_flood with MIT License 5 votes vote down vote up
private static void clickColorButton(int index) {
    ViewInteraction colorButton = onView(
            allOf(withClassName(is("com.gunshippenguin.openflood.ColorButton")),
                    withParent(withId(R.id.buttonLayout)),
                    isDisplayed(),
                    nthChildOf(withId(R.id.buttonLayout), index)));
    colorButton.perform(click());
}
 
Example #13
Source File: SingleSetTest.java    From Android with MIT License 5 votes vote down vote up
public void clearTest() {
    ViewInteraction clearView = onView(withId(R.id.clear));
    clearView.perform(click());
    ViewInteraction cancelView = onView(withId(R.id.tv_popup_cancel)).check(matches(isDisplayed()));
    cancelView.perform(click());

    clearView.perform(click());
    DataInteraction confirmView = onData(anything()).inAdapterView(withId(R.id.list_view)).atPosition(0);
    confirmView.perform(click());
}
 
Example #14
Source File: SingleSetTest.java    From Android with MIT License 5 votes vote down vote up
@After
public void backTest() {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction leftView = onView(withId(R.id.left_rela));
    leftView.perform(click());
}
 
Example #15
Source File: HomeEspressoTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Test
@AllowFlaky(attempts = 5)
public void A2_accept_license() {
    // accept the license agreement
    // TODO note espresso recorder uses hardcoded strings
    ViewInteraction appCompatCheckBox2 = onView(
            allOf(withId(R.id.agreeCheckBox), withText("I UNDERSTAND AND AGREE")));
    appCompatCheckBox2.perform(scrollTo(), click());

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

}
 
Example #16
Source File: DayNightModeTest.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 4 votes vote down vote up
@Test
    public void dayNightModeTest() {
        openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
        
        ViewInteraction appCompatTextView = onView(
allOf(withId(R.id.title), withText("Night Mode"),
childAtPosition(
childAtPosition(
withId(R.id.content),
0),
0),
isDisplayed()));
        appCompatTextView.perform(click());
        
        openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
        
        ViewInteraction textView = onView(
allOf(withId(R.id.title), withText("Day Mode"),
childAtPosition(
childAtPosition(
withId(R.id.content),
0),
0),
isDisplayed()));
        textView.check(matches(withText("Day Mode")));
        
        ViewInteraction appCompatTextView2 = onView(
allOf(withId(R.id.title), withText("Day Mode"),
childAtPosition(
childAtPosition(
withId(R.id.content),
0),
0),
isDisplayed()));
        appCompatTextView2.perform(click());
        
        openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
        
        ViewInteraction textView2 = onView(
allOf(withId(R.id.title), withText("Night Mode"),
childAtPosition(
childAtPosition(
withId(R.id.content),
0),
0),
isDisplayed()));
        textView2.check(matches(withText("Night Mode")));
        }
 
Example #17
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction toolbarGoPrevious() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_go_previous));
}
 
Example #18
Source File: LoginPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction username() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_username));
}
 
Example #19
Source File: ListHivesTest.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void listHivesTest() {
    ViewInteraction floatingActionButton = onView(
            allOf(withId(R.id.fab_add_apiary),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton.perform(click());

    ViewInteraction appCompatEditText = onView(
            withId(R.id.add_apiary_name));
    appCompatEditText.perform(scrollTo(), replaceText("Apiary"), closeSoftKeyboard());

    ViewInteraction floatingActionButton2 = onView(
            allOf(withId(R.id.fab_add_apiary),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton2.perform(click());

    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.apiaries_list),
                    withParent(allOf(withId(R.id.apiariesLL),
                            withParent(withId(R.id.apiariesContainer)))),
                    isDisplayed()));
    recyclerView.perform(actionOnItemAtPosition(0, click()));

    ViewInteraction floatingActionButton3 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton3.perform(click());

    ViewInteraction appCompatEditText2 = onView(
            withId(R.id.add_hive_name));
    appCompatEditText2.perform(scrollTo(), replaceText("H1"), closeSoftKeyboard());

    ViewInteraction floatingActionButton4 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton4.perform(click());

    ViewInteraction floatingActionButton5 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton5.perform(click());

    ViewInteraction appCompatEditText3 = onView(
            withId(R.id.add_hive_name));
    appCompatEditText3.perform(scrollTo(), replaceText("H2"), closeSoftKeyboard());

    ViewInteraction floatingActionButton6 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton6.perform(click());

    ViewInteraction floatingActionButton7 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton7.perform(click());

    ViewInteraction appCompatEditText4 = onView(
            withId(R.id.add_hive_name));
    appCompatEditText4.perform(scrollTo(), replaceText("H3"), closeSoftKeyboard());

    ViewInteraction floatingActionButton8 = onView(
            allOf(withId(R.id.fab_add_hive),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton8.perform(click());

    ViewInteraction textView = onView(
            withText("H1"));
    textView.check(matches(isDisplayed()));
    textView = onView(
            withText("H2"));
    textView.check(matches(isDisplayed()));
    textView = onView(
            withText("H3"));
    textView.check(matches(isDisplayed()));
}
 
Example #20
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
@Override
public final cortado.Unfinished.And.ViewInteraction and() {
    return new cortado.Unfinished(Cortado.this).new And().new ViewInteraction();
}
 
Example #21
Source File: IssuerPage.java    From px-android with MIT License 4 votes vote down vote up
private void selectOption(final int bankOption) {
    ViewInteraction recyclerView = onView(withId(com.mercadopago.android.px.R.id.mpsdkActivityIssuersView));
    recyclerView.perform(scrollToPosition(bankOption));
    recyclerView.perform(RecyclerViewActions.actionOnItemAtPosition(bankOption, click()));
}
 
Example #22
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction toolbarDrawerToggle() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_drawer_toggle));
}
 
Example #23
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
@Override
final Cortado.Or.ViewInteraction returned() {
    return new Cortado.Or().new ViewInteraction();
}
 
Example #24
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
@Override
public final cortado.Unfinished.Or.ViewInteraction or() {
    return new cortado.Unfinished(Cortado.this).new Or().new ViewInteraction();
}
 
Example #25
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
ViewInteraction() {
    super(Cortado.this);
}
 
Example #26
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction toolbarText() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_text));
}
 
Example #27
Source File: ViewApiaryTest.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void viewApiaryTest() {
    ViewInteraction floatingActionButton = onView(
            allOf(withId(R.id.fab_add_apiary),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton.perform(click());

    ViewInteraction appCompatEditText = onView(
            withId(R.id.add_apiary_name));
    appCompatEditText.perform(scrollTo(), replaceText("Apiary"), closeSoftKeyboard());

    ViewInteraction appCompatEditText2 = onView(
            withId(R.id.add_apiary_notes));
    appCompatEditText2.perform(scrollTo(), replaceText("Notes"), closeSoftKeyboard());

    ViewInteraction floatingActionButton2 = onView(
            allOf(withId(R.id.fab_add_apiary),
                    withParent(withId(R.id.coordinatorLayout)),
                    isDisplayed()));
    floatingActionButton2.perform(click());

    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.apiaries_list),
                    withParent(allOf(withId(R.id.apiariesLL),
                            withParent(withId(R.id.apiariesContainer)))),
                    isDisplayed()));
    recyclerView.perform(actionOnItemAtPosition(0, click()));

    ViewInteraction textView = onView(
            withText("Apiary"));
    textView.check(matches(withText("Apiary")));

    ViewInteraction appCompatTextView = onView(
            allOf(withText("Info"), isDisplayed()));
    appCompatTextView.perform(click());

    ViewInteraction textView2 = onView(
            allOf(withId(R.id.notes_content), withText("Notes"),
                    childAtPosition(
                            childAtPosition(
                                    IsInstanceOf.<View>instanceOf(
                                            android.widget.LinearLayout.class), 1),
                            0),
                    isDisplayed()));
    textView2.check(matches(withText("Notes")));

}
 
Example #28
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
ViewInteraction() {
    super(Cortado.this);
}
 
Example #29
Source File: LoginPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction loginView() {
    return Espresso.onView(ViewMatchers.isAssignableFrom(LoginView.class));
}
 
Example #30
Source File: Cortado.java    From cortado with Apache License 2.0 4 votes vote down vote up
ViewInteraction() {
    super(Cortado.this);
}