下面列出了android.support.test.espresso.Espresso#pressBack ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
@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));
}
@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));
}
@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()));
}
@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);
}
@When("^I tap the Back button$")
public void i_tap_the_back_button() {
Espresso.pressBack();
}
@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());
}
@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));
}
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();
}
@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();
}
/**
* 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();
}
/**
* 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();
}