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

The following examples show how to use android.support.test.espresso.Espresso#pressBack() . 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: TaskCreateActivityTest.java    From friendly-plans with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void whenChangedViewChangeNavigationMenuHighlight() {
    onView(withId(R.id.id_et_task_name))
            .perform(replaceText(EXPECTED_NAME));
    closeSoftKeyboard();

    onView(withId(R.id.id_btn_steps))
            .perform(click());
    onView(withId(R.id.id_navigation_steps))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_basic_info))
            .check(matches(not(isEnabled())));

    Espresso.pressBack();
    onView(withId(R.id.id_navigation_basic_info))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_steps))
            .check(matches(not(isEnabled())));

    closeSoftKeyboard();

    List<TaskTemplate> taskTemplates = taskTemplateRepository.get(EXPECTED_NAME);
    idsToDelete.add(taskTemplates.get(0).getId());
}
 
Example 2
Source File: RecyclerViewActionsTest.java    From android-espresso-revealed with Apache License 2.0 5 votes vote down vote up
@Test
public void addNewToDos() throws Exception {
    generateToDos(12);
    onView(withId(R.id.tasks_list))
            .perform(actionOnItemAtPosition(10, scrollTo()));
    onView(withId(R.id.tasks_list))
            .perform(scrollToPosition(1));
    onView(withId(R.id.tasks_list))
            .perform(scrollToPosition(11));
    onView(withId(R.id.tasks_list))
            .perform(actionOnItemAtPosition(11, click()));
    Espresso.pressBack();
    onView(withId(R.id.tasks_list))
            .perform(scrollToPosition(2));
}
 
Example 3
Source File: RecyclerViewActionsTest.java    From android-espresso-revealed with Apache License 2.0 5 votes vote down vote up
@Test
public void addNewToDosChained() throws Exception {
    generateToDos(12);
    onView(withId(R.id.tasks_list))
            .perform(actionOnItemAtPosition(10, scrollTo()))
            .perform(scrollToPosition(1))
            .perform(scrollToPosition(11))
            .perform(actionOnItemAtPosition(11, click()));
    Espresso.pressBack();
    onView(withId(R.id.tasks_list)).perform(scrollToPosition(2));
}
 
Example 4
Source File: TaskCreateActivityTest.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void whenMovingBackFromStepListNewTaskCanBeUpdated() {
    onView(withId(R.id.id_et_task_name))
            .perform(replaceText(EXPECTED_NAME));
    closeSoftKeyboard();

    onView(withId(R.id.id_et_task_duration_time))
            .perform(replaceText(EXPECTED_DURATION_TXT));
    closeSoftKeyboard();

    onView(withId(R.id.id_btn_steps))
            .perform(click());

    Espresso.pressBack();

    closeSoftKeyboard();

    onView(withId(R.id.id_btn_save_and_finish))
            .perform(scrollTo())
            .perform(click());

    List<TaskTemplate> taskTemplates = taskTemplateRepository.get(EXPECTED_NAME);
    idsToDelete.add(taskTemplates.get(0).getId());

    assertThat(taskTemplates.size(), is(1));
    assertThat(taskTemplates.get(0).getName(), is(EXPECTED_NAME));
    assertThat(taskTemplates.get(0).getDurationTime(), is(EXPECTED_DURATION));
    onView(withId(R.id.button_createPlan)).check(matches(isDisplayed()));
}
 
Example 5
Source File: FalconDialogInOnCreateTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesDialogOnCreate() {
  DialogOnCreate activity = _activityRule.getActivity();
  onView(withText(DialogOnCreate.DIALOG_TITLE)).check(matches(isDisplayed()));

  Bitmap withDialog = Falcon.takeScreenshotBitmap(activity);
  Espresso.pressBack();
  onView(withText(DialogOnCreate.DIALOG_TITLE)).check(doesNotExist());

  Bitmap afterDialogDismiss = Falcon.takeScreenshotBitmap(activity);

  assertThatBitmap(withDialog).isDarkerThan(afterDialogDismiss);
}
 
Example 6
Source File: SampleListStepDefinitions.java    From material-activity-chooser with Apache License 2.0 4 votes vote down vote up
@When("^I tap the Back button$")
public void i_tap_the_back_button() {
    Espresso.pressBack();
}
 
Example 7
Source File: PlanCreateActivityTest.java    From friendly-plans with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void whenChangedViewChangeNavigationMenuHighlight() {

    onView(withId(R.id.id_navigation_plan_name))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_plan_tasks))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_prizes))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_interactions))
            .check(matches(not(isEnabled())));

    onView(withId(R.id.id_et_plan_name))
            .perform(replaceText(EXPECTED_NAME));
    closeSoftKeyboard();

    onView(withId(R.id.id_btn_plan_create_tasks))
            .perform(click());

    onView(withId(R.id.id_navigation_plan_tasks))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_plan_name))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_prizes))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_interactions))
            .check(matches(not(isEnabled())));

    Espresso.pressBack();

    onView(withId(R.id.id_btn_plan_create_prizes))
            .perform(click());

    onView(withId(R.id.id_navigation_plan_prizes))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_plan_name))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_tasks))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_interactions))
            .check(matches(not(isEnabled())));

    Espresso.pressBack();

    onView(withId(R.id.id_btn_plan_create_interactions))
            .perform(click());

    onView(withId(R.id.id_navigation_plan_interactions))
            .check(matches(isEnabled()));
    onView(withId(R.id.id_navigation_plan_name))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_prizes))
            .check(matches(not(isEnabled())));
    onView(withId(R.id.id_navigation_plan_tasks))
            .check(matches(not(isEnabled())));

    Espresso.pressBack();


    closeSoftKeyboard();

    List<PlanTemplate> planTemplates = planTemplateRepository.get(EXPECTED_NAME);
    idsToDelete.add(planTemplates.get(0).getId());
}
 
Example 8
Source File: PeopleActivityTest.java    From friendspell with Apache License 2.0 4 votes vote down vote up
@Test
public void tagTwice() {
  TestUtil.setupGoogleApiClientBridgeForNearby(googleApiClientBridge, TestUtil.COLT);

  activityRule.launchActivity(null);

  // Go to NearbyActivity
  onView(withId(R.id.nearby_tip))
      .check(matches(isDisplayed()));
  onView(withId(R.id.action_nearby_add))
      .perform(click());

  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(0)
      .check(matches(withText(TestUtil.COLT.displayName)))
      .check(matches(withCompoundDrawable(0)))
      .check(matches(withCompoundDrawable(2, R.drawable.ic_newly_tagged)));

  // Back to PeopleActivity
  Espresso.pressBack();
  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(0)
      .check(matches(withText(TestUtil.COLT.displayName)))
      .check(matches(withCompoundDrawable(0)))
      .check(matches(withoutCompoundDrawable(2)));

  // Go to NearbyActivity again
  onView(withId(R.id.nearby_tip))
      .check(matches(not(isDisplayed())));
  onView(withId(R.id.action_nearby_add))
      .perform(click());

  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(0)
      .check(matches(withText(TestUtil.COLT.displayName)))
      .check(matches(withCompoundDrawable(0)))
      .check(matches(withoutCompoundDrawable(2)));

  Mockito.verify(googleApiClientBridge, Mockito.times(1)).getProfileImage(TestUtil.COLT.googlePlusId);
  Mockito.verify(googleApiClientBridge, Mockito.times(1)).getProfileImages(
      Mockito.anyString(),
      Mockito.anyListOf(String.class),
      Mockito.any(GoogleApiClientBridge.GetProfileImagesCallback.class));
}
 
Example 9
Source File: WordSetActivityTest.java    From friendspell with Apache License 2.0 4 votes vote down vote up
private void multiSourceOnePerson(boolean first) {
  TestUtil.setupGoogleApiClientBridgeForNearby(googleApiClientBridge, TestUtil.KATHERINE);

  if (!first) {
    TestUtil.setSeenMultiSource(pref);
  }

  Intent intent = new Intent();
  intent.putExtra(Constants.KEY_NAME, "newyork");
  activityRule.launchActivity(intent);

  TestUtil.matchToolbarTitle("New York");

  // Go to SpellActivity with APPLE
  onData(is("APPLE"))
      .perform(click());

  TestUtil.matchToolbarTitle("APPLE");

  // Go to NearbyActivity
  onView(withId(R.id.nearby_tip))
      .check(matches(isDisplayed()));

  TestUtil.verifyMultiSourceTipHidden();

  onView(withId(R.id.action_nearby_add))
      .perform(click());
  onView(allOf(isDescendantOfA(withId(R.id.nearby_header)), withId(R.id.me)))
      .check(matches(withText(TestUtil.ME_DISPLAY_NAME)));

  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(0)
      .check(matches(withText(TestUtil.KATHERINE.displayName)));

  // Back to SpellActivity
  Espresso.pressBack();

  onView(withId(R.id.nearby_tip))
      .check(matches(not(isDisplayed())));

  if (first) {
    TestUtil.verifyMultiSourceTipShown();
  } else {
    TestUtil.verifyMultiSourceTipHidden();
  }

  // Back to WordSetActivity
  TestUtil.clickActionBarHomeButton();

  // Go to SpellActivity with a different word
  onData(is("LIBERTY"))
      .perform(click());
  TestUtil.verifyMultiSourceTipHidden();
}
 
Example 10
Source File: SpellActivityTest.java    From friendspell with Apache License 2.0 4 votes vote down vote up
@Test
public void multiSource() {
  TestUtil.setupGoogleApiClientBridgeForNearby(googleApiClientBridge,
      TestUtil.DIANNE, TestUtil.KATHERINE, TestUtil.CHET, TestUtil.COLT, TestUtil.ADAM, TestUtil.RETO);

  Intent intent = new Intent();
  intent.putExtra(Constants.KEY_NAME, "newyork");
  intent.putExtra(Constants.KEY_WORD, "PIZZA");
  activityRule.launchActivity(intent);

  TestUtil.matchToolbarTitle("PIZZA");

  TestUtil.verifyViewGroupWordColors(
      R.id.word,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING);
  TestUtil.verifyViewGroupWordSources(R.id.sources, 1, 1, 1, 1, 1);

  onView(withId(R.id.nearby_tip))
      .check(matches(isDisplayed()));

  TestUtil.verifyMultiSourceTipHidden();

  onView(withId(R.id.action_nearby_add))
      .perform(click());
  onView(allOf(isDescendantOfA(withId(R.id.nearby_header)), withId(R.id.me)))
      .check(matches(withText(TestUtil.ME_DISPLAY_NAME)));

  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(0)
      .check(matches(withText(TestUtil.ADAM.displayName)));
  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(1)
      .check(matches(withText(TestUtil.CHET.displayName)));
  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(2)
      .check(matches(withText(TestUtil.COLT.displayName)));
  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(3)
      .check(matches(withText(TestUtil.DIANNE.displayName)));
  onData(is(instanceOf(NearbyPerson.class)))
      .atPosition(4)
      .check(matches(withText(TestUtil.KATHERINE.displayName)));

  Espresso.pressBack();

  TestUtil.verifyViewGroupWordColors(
      R.id.word,
      WordUtil.COLOR_COMBO,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_MISSING,
      WordUtil.COLOR_ONE);
  TestUtil.verifyViewGroupWordSources(R.id.sources, 4, 4, 1, 1, 1);

  onView(withId(R.id.nearby_tip))
      .check(matches(not(isDisplayed())));

  TestUtil.verifyMultiSourceTipShown();
}
 
Example 11
Source File: EspDevice.java    From espresso-macchiato with MIT License 2 votes vote down vote up
/**
 * Click androids back button.
 *
 * Perform back button click so that the onBackPressed() method is called for the current activity.
 * This is not the up button from an ActionBar.
 *
 * > Warning: When you back press on your root activity then your application becomes closed.
 * Closing the application let current and all following tests fail.
 * You can avoid closing your application with the <a href="https://github.com/nenick/espresso-macchiato/wiki/Recipe%20Dummy%20Launcher">Dummy Launcher</a> concept.
 *
 * @since Espresso Macchiato 0.2
 */
public void clickBackButton() {
    Espresso.pressBack();
}
 
Example 12
Source File: EspDialog.java    From espresso-macchiato with MIT License 2 votes vote down vote up
/**
 * Dismiss dialog.
 *
 * This is like clicking outside of the dialog instead any dialog button.
 * If the dialog is not cancelable this call have no effect.
 *
 * @since Espresso Macchiato 0.4
 */
public void dismiss() {
    Espresso.pressBack();
}