From 75bee889c92e1997a08e160c05a04ac9754a0504 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 6 Feb 2018 12:52:28 +0530 Subject: [PATCH] Issue #330 - Added the espresso test for invalid age error toast (#402) --- .../glucosio/android/HelloActivityTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/androidTest/java/org/glucosio/android/HelloActivityTest.java b/app/src/androidTest/java/org/glucosio/android/HelloActivityTest.java index 872139b5..7ec3e4ff 100644 --- a/app/src/androidTest/java/org/glucosio/android/HelloActivityTest.java +++ b/app/src/androidTest/java/org/glucosio/android/HelloActivityTest.java @@ -39,11 +39,13 @@ import static android.support.test.espresso.action.ViewActions.scrollTo; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.RootMatchers.withDecorView; import static android.support.test.espresso.matcher.ViewMatchers.isChecked; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText; +import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; @@ -189,4 +191,20 @@ public void check_009_IfICanSubmitAnyData() { onView(withId(R.id.activity_hello_button_start)) .perform(scrollTo(), click()); } + + @Test + public void check_010_IfIEnterWrongAge() { + // Entering invalid age + onView(withId(R.id.activity_hello_age)) + .perform(typeText("0"), closeSoftKeyboard()); + + // Click on GET STARTED button + onView(withId(R.id.activity_hello_button_start)) + .perform(scrollTo(), click()); + + // Checking the toast is displayed with invalid message + onView(withText(R.string.helloactivity_age_invalid)) + .inRoot(withDecorView(not(mRule.getActivity().getWindow().getDecorView()))) + .check(matches(isDisplayed())); + } }