Java Code Examples for android.support.test.espresso.Espresso#onView()

The following examples show how to use android.support.test.espresso.Espresso#onView() . 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: 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 2
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 3
Source File: TestActivityTest.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Test
public void ViewMatchers() {
    Espresso.onView(ViewMatchers.withId(json.chao.com.wanandroid.R.id.button));
    //onView内部最好不要使用withText()断言处理
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(json.chao.com.wanandroid.R.id.button), ViewMatchers.withText("HaHa")));
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(json.chao.com.wanandroid.R.id.button), Matchers.not(ViewMatchers.withText("HaHa"))));
}
 
Example 4
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 5
Source File: RepositoriesPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction repositoriesView() {
    return Espresso.onView(ViewMatchers.isAssignableFrom(RepositoriesView.class));
}
 
Example 6
Source File: LoginPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction loginButton() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_login));
}
 
Example 7
Source File: LoginPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction password() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_password));
}
 
Example 8
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 9
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 10
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 11
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 12
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction toolbar() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar));
}
 
Example 13
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction hiddenToolbar() {
    return Espresso.onView(ViewMatchers.withId(R.id.hidden_toolbar));
}
 
Example 14
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction root() {
    return Espresso.onView(ViewMatchers.withId(R.id.root));
}
 
Example 15
Source File: MainPage.java    From flowless with Apache License 2.0 4 votes vote down vote up
public ViewInteraction drawerLayout() {
    return Espresso.onView(ViewMatchers.withId(R.id.drawer_layout));
}
 
Example 16
Source File: NumberPadTimePickerDialogTest.java    From NumberPadTimePicker with Apache License 2.0 4 votes vote down vote up
private static ViewInteraction[] getAltButtonInteractions() {
    ViewInteraction[] buttonsInteractions = new ViewInteraction[2];
    buttonsInteractions[0] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text9));
    buttonsInteractions[1] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text11));
    return buttonsInteractions;
}
 
Example 17
Source File: TestActivityTest.java    From Awesome-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Test
public void hasSibling() {
    Espresso.onView(Matchers.allOf(ViewMatchers.withText("7"),
            ViewMatchers.hasSibling(ViewMatchers.withText("item: 1"))));
}