android.support.test.espresso.Espresso#onView ( )源码实例Demo

下面列出了android.support.test.espresso.Espresso#onView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
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));
}
 
源代码3 项目: Awesome-WanAndroid   文件: TestActivityTest.java
@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"))));
}
 
源代码4 项目: Awesome-WanAndroid   文件: TestActivityTest.java
@Test
public void hasSibling() {
    Espresso.onView(Matchers.allOf(ViewMatchers.withText("7"),
            ViewMatchers.hasSibling(ViewMatchers.withText("item: 1"))));
}
 
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;
}
 
源代码6 项目: flowless   文件: MainPage.java
public ViewInteraction drawerLayout() {
    return Espresso.onView(ViewMatchers.withId(R.id.drawer_layout));
}
 
源代码7 项目: flowless   文件: MainPage.java
public ViewInteraction root() {
    return Espresso.onView(ViewMatchers.withId(R.id.root));
}
 
源代码8 项目: flowless   文件: MainPage.java
public ViewInteraction hiddenToolbar() {
    return Espresso.onView(ViewMatchers.withId(R.id.hidden_toolbar));
}
 
源代码9 项目: flowless   文件: MainPage.java
public ViewInteraction toolbarText() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_text));
}
 
源代码10 项目: flowless   文件: MainPage.java
public ViewInteraction toolbar() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar));
}
 
源代码11 项目: flowless   文件: MainPage.java
public ViewInteraction toolbarDrawerToggle() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_drawer_toggle));
}
 
源代码12 项目: flowless   文件: MainPage.java
public ViewInteraction toolbarGoPrevious() {
    return Espresso.onView(ViewMatchers.withId(R.id.toolbar_go_previous));
}
 
源代码13 项目: flowless   文件: LoginPage.java
public ViewInteraction loginView() {
    return Espresso.onView(ViewMatchers.isAssignableFrom(LoginView.class));
}
 
源代码14 项目: flowless   文件: LoginPage.java
public ViewInteraction username() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_username));
}
 
源代码15 项目: flowless   文件: LoginPage.java
public ViewInteraction password() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_password));
}
 
源代码16 项目: flowless   文件: LoginPage.java
public ViewInteraction loginButton() {
    return Espresso.onView(ViewMatchers.withId(R.id.login_login));
}
 
源代码17 项目: flowless   文件: RepositoriesPage.java
public ViewInteraction repositoriesView() {
    return Espresso.onView(ViewMatchers.isAssignableFrom(RepositoriesView.class));
}