@Test
  public void deletingListOpensAllLists() {
    openDrawer();
    // Forces test to succeed in case drawer is already open
    openDrawer();

    createList("A");
    createTask("A");

    openDrawer();

    createList("B");
    createTask("B");

    openDrawer();

    createList("C");
    createTask("C");

    openDrawer();

    deleteList("C");

    closeDrawer();

    // Should now display list of all tasks
    ViewInteraction recyclerView = onView(allOf(withId(android.R.id.list), isDisplayed()));

    recyclerView.check(matches(Utils.assertionOnItemAtPosition(0, hasDescendant(withText("A")))));
    recyclerView.check(matches(Utils.assertionOnItemAtPosition(1, hasDescendant(withText("B")))));
  }
 private void closeDrawer() {
   ViewInteraction recyclerView =
       onView(
           allOf(
               withId(R.id.navigation_drawer),
               withParent(
                   allOf(withId(R.id.drawer_layout), withParent(withId(android.R.id.content)))),
               isDisplayed()));
   recyclerView.perform(swipeLeft());
 }
示例#3
0
 public void testChangeText() {
   // 获取某个View
   ViewInteraction viewFocus = Espresso.onView(ViewMatchers.withId(R.id.et));
   // 执行某个动作
   viewFocus.perform(ViewActions.clearText());
   viewFocus.perform(ViewActions.typeText("new"));
   TextView tv = (TextView) activity.findViewById(R.id.et);
   // 检查结果
   EspressoTest.assertEquals("new", tv.getText() + "");
 }
 private void openDrawer() {
   try {
     ViewInteraction imageButton =
         onView(
             allOf(
                 withContentDescription("Open navigation drawer"),
                 withParent(allOf(withId(R.id.toolbar), withParent(withId(R.id.appbar)))),
                 isDisplayed()));
     imageButton.perform(click());
   } catch (NoMatchingViewException ignored) {
     // probably already open
   }
 }
  private void createList(String title) {
    ViewInteraction recyclerView =
        onView(
            allOf(
                withId(R.id.navigation_drawer),
                withParent(
                    allOf(withId(R.id.drawer_layout), withParent(withId(android.R.id.content)))),
                isDisplayed()));
    recyclerView.perform(actionOnItem(hasDescendant(withText(R.string.menu_createnew)), click()));

    ViewInteraction appCompatEditText = onView(allOf(withId(R.id.titleField), isDisplayed()));
    appCompatEditText.perform(click());

    ViewInteraction appCompatEditText2 = onView(allOf(withId(R.id.titleField), isDisplayed()));
    appCompatEditText2.perform(replaceText(title), closeSoftKeyboard());

    ViewInteraction appCompatTextView =
        onView(
            allOf(
                withId(R.id.dialog_yes),
                withText("OK"),
                withParent(withId(R.id.buttons)),
                isDisplayed()));
    appCompatTextView.perform(click());
  }
  private void deleteList(String title) {
    ViewInteraction appCompatTextView4 =
        onView(allOf(withId(android.R.id.text1), withText(title), isDisplayed()));
    appCompatTextView4.perform(longClick());

    ViewInteraction appCompatTextView5 =
        onView(allOf(withId(R.id.deleteButton), withText("Delete list"), isDisplayed()));
    appCompatTextView5.perform(click());

    ViewInteraction appCompatButton =
        onView(
            allOf(
                withId(android.R.id.button1),
                withText("OK"),
                withParent(allOf(withId(R.id.buttonPanel), withParent(withId(R.id.parentPanel)))),
                isDisplayed()));
    appCompatButton.perform(click());
  }
  private void createTask(String title) {
    ViewInteraction floatingActionButton =
        onView(
            allOf(
                withId(R.id.fab),
                withParent(
                    allOf(withId(R.id.main_content), withParent(withId(R.id.drawer_layout)))),
                isDisplayed()));
    floatingActionButton.perform(click());

    ViewInteraction styledEditText = onView(allOf(withId(R.id.taskText), isDisplayed()));
    styledEditText.perform(replaceText(title), closeSoftKeyboard());

    ViewInteraction imageButton2 =
        onView(
            allOf(
                withContentDescription("Navigate up"),
                withParent(allOf(withId(R.id.toolbar), withParent(withId(R.id.appbar)))),
                isDisplayed()));
    imageButton2.perform(click());
  }