diff --git a/app/src/androidTest/java/com/futsch1/medtimer/BasicUITest.java b/app/src/androidTest/java/com/futsch1/medtimer/BasicUITest.java index 85aa87e1..bbb29d1a 100644 --- a/app/src/androidTest/java/com/futsch1/medtimer/BasicUITest.java +++ b/app/src/androidTest/java/com/futsch1/medtimer/BasicUITest.java @@ -14,7 +14,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withClassName; import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withParent; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anything; @@ -28,7 +27,6 @@ import androidx.test.filters.LargeTest; import androidx.test.rule.GrantPermissionRule; -import org.hamcrest.core.IsInstanceOf; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,8 +49,7 @@ public void basicUITest() { AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.MEDICINES); ViewInteraction extendedFloatingActionButton = onView( - allOf(withId(R.id.addMedicine), withText("Add medicine"), withContentDescription("Add medicine"), - isDisplayed())); + withId(R.id.addMedicine)); extendedFloatingActionButton.perform(click()); ViewInteraction textInputEditText = onView( @@ -65,29 +62,15 @@ public void basicUITest() { textInputEditText.perform(replaceText("Test"), closeSoftKeyboard()); ViewInteraction materialButton = onView( - allOf(withId(android.R.id.button1), withText("OK"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); + allOf(withId(android.R.id.button1), withText("OK"))); materialButton.perform(scrollTo(), click()); ViewInteraction recyclerView = onView( - allOf(withId(R.id.medicineList), - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0))); + allOf(withId(R.id.medicineList))); recyclerView.perform(actionOnItemAtPosition(0, click())); ViewInteraction extendedFloatingActionButton2 = onView( - allOf(withId(R.id.addReminder), withText("Add reminder"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(R.id.navHost), - 0), - 1), - isDisplayed())); + allOf(withId(R.id.addReminder))); extendedFloatingActionButton2.perform(click()); ViewInteraction textInputEditText2 = onView( @@ -100,24 +83,14 @@ public void basicUITest() { textInputEditText2.perform(replaceText("1"), closeSoftKeyboard()); ViewInteraction materialButton2 = onView( - allOf(withId(android.R.id.button1), withText("OK"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); + allOf(withId(android.R.id.button1), withText("OK"))); materialButton2.perform(scrollTo(), click()); ViewInteraction materialButton3 = onView( - allOf(withId(com.google.android.material.R.id.material_timepicker_ok_button), withText("OK"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(android.R.id.content), - 0), - 5), - isDisplayed())); + allOf(withId(com.google.android.material.R.id.material_timepicker_ok_button), withText("OK"))); materialButton3.perform(click()); + onView(isRoot()).perform(AndroidTestHelper.waitFor(1000)); ViewInteraction materialButton4 = onView( allOf(withId(R.id.open_advanced_settings), withText("Advanced settings"), AndroidTestHelper.childAtPosition( @@ -126,7 +99,6 @@ public void basicUITest() { 0), 1), isDisplayed())); - onView(isRoot()).perform(AndroidTestHelper.waitFor(1000)); materialButton4.perform(click()); ViewInteraction checkableImageButton = onView( @@ -148,106 +120,51 @@ public void basicUITest() { materialTextView.perform(click()); ViewInteraction appCompatImageButton = onView( - allOf(withContentDescription("Navigate up"), - AndroidTestHelper.childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton.perform(click()); ViewInteraction materialButton5 = onView( - allOf(withId(R.id.open_advanced_settings), withText("Advanced settings"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(R.id.advanced_settings), - 0), - 1), - isDisplayed())); + allOf(withId(R.id.open_advanced_settings))); materialButton5.perform(click()); ViewInteraction editText = onView( - allOf(withId(R.id.editInstructions), withText("before the meal"), - withParent(withParent(withId(R.id.editInstructionsLayout))), - isDisplayed())); + allOf(withId(R.id.editInstructions), withText("before the meal"))); editText.check(matches(withText("before the meal"))); ViewInteraction appCompatImageButton2 = onView( - allOf(withContentDescription("Navigate up"), - AndroidTestHelper.childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton2.perform(click()); ViewInteraction textInputEditText3 = onView( - allOf(withId(R.id.editAmount), withText("1"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("com.google.android.material.textfield.TextInputLayout")), - 0), - 0), - isDisplayed())); + allOf(withId(R.id.editAmount), withText("1"))); textInputEditText3.perform(replaceText("2")); ViewInteraction textInputEditText4 = onView( - allOf(withId(R.id.editAmount), withText("2"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("com.google.android.material.textfield.TextInputLayout")), - 0), - 0), - isDisplayed())); + allOf(withId(R.id.editAmount), withText("2"))); textInputEditText4.perform(closeSoftKeyboard()); ViewInteraction appCompatImageButton3 = onView( - allOf(withContentDescription("Navigate up"), - AndroidTestHelper.childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton3.perform(click()); - ViewInteraction recyclerView2 = onView( - allOf(withId(R.id.medicineList), - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0))); onView(isRoot()).perform(AndroidTestHelper.waitFor(100)); + ViewInteraction recyclerView2 = onView( + allOf(withId(R.id.medicineList))); recyclerView2.perform(actionOnItemAtPosition(0, click())); ViewInteraction editText2 = onView( - allOf(withId(R.id.editAmount), withText("2"), - withParent(withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout.class))), - isDisplayed())); + allOf(withId(R.id.editAmount), withText("2"))); editText2.check(matches(withText("2"))); ViewInteraction appCompatImageButton4 = onView( - allOf(withContentDescription("Navigate up"), - AndroidTestHelper.childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton4.perform(click()); AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.OVERVIEW); onView(isRoot()).perform(AndroidTestHelper.waitFor(1000)); ViewInteraction textView = onView( - allOf(withId(R.id.nextReminderInfo), - withParent(withParent(IsInstanceOf.instanceOf(androidx.cardview.widget.CardView.class))), - isDisplayed())); + allOf(withId(R.id.nextReminderInfo))); textView.check(matches(withText(startsWith("2 of Test")))); } diff --git a/app/src/androidTest/java/com/futsch1/medtimer/StatisticsTest.java b/app/src/androidTest/java/com/futsch1/medtimer/StatisticsTest.java index 6ba88565..54bbd175 100644 --- a/app/src/androidTest/java/com/futsch1/medtimer/StatisticsTest.java +++ b/app/src/androidTest/java/com/futsch1/medtimer/StatisticsTest.java @@ -56,23 +56,11 @@ public void statisticsTest() { onView(isRoot()).perform(AndroidTestHelper.waitFor(1000)); ViewInteraction overflowMenuButton = onView( - allOf(withContentDescription("More options"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.action_bar), - 1), - 0), - isDisplayed())); + allOf(withContentDescription("More options"))); overflowMenuButton.perform(click()); ViewInteraction materialTextView = onView( - allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(androidx.appcompat.R.id.content), - 1), - 0), - isDisplayed())); + allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data"))); materialTextView.perform(click()); onView(isRoot()).perform(AndroidTestHelper.waitFor(4000)); @@ -95,13 +83,7 @@ public void statisticsTest() { AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.ANALYSIS); ViewInteraction appCompatSpinner = onView( - allOf(withId(R.id.timeSpinner), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.LinearLayout")), - 0), - 2), - isDisplayed())); + allOf(withId(R.id.timeSpinner))); appCompatSpinner.perform(click()); DataInteraction materialTextView2 = onData(anything()) @@ -112,13 +94,7 @@ public void statisticsTest() { materialTextView2.perform(click()); ViewInteraction materialButton = onView( - allOf(withId(R.id.reminderTableButton), withText("Tabular view"), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("android.widget.LinearLayout")), - 0), - 0), - isDisplayed())); + allOf(withId(R.id.reminderTableButton), withText("Tabular view"))); materialButton.perform(click()); ViewInteraction linearLayout = onView( @@ -141,13 +117,7 @@ public void statisticsTest() { textView.check(matches(withText(startsWith("Selen (200 µg)")))); ViewInteraction textInputEditText = onView( - allOf(withId(R.id.filter), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withId(R.id.filterLayout), - 0), - 0), - isDisplayed())); + allOf(withId(R.id.filter))); textInputEditText.perform(replaceText("B"), closeSoftKeyboard()); ViewInteraction textView3 = onView( @@ -155,13 +125,7 @@ public void statisticsTest() { textView3.check(matches(withText("B12 (500µg)"))); ViewInteraction checkableImageButton = onView( - allOf(withId(com.google.android.material.R.id.text_input_end_icon), - AndroidTestHelper.childAtPosition( - AndroidTestHelper.childAtPosition( - withClassName(is("com.google.android.material.textfield.EndCompoundLayout")), - 1), - 0), - isDisplayed())); + allOf(withId(com.google.android.material.R.id.text_input_end_icon))); checkableImageButton.perform(click()); } diff --git a/app/src/androidTest/java/com/futsch1/medtimer/TestDataAndDeleteAndManualDoseTest.java b/app/src/androidTest/java/com/futsch1/medtimer/TestDataAndDeleteAndManualDoseTest.java index ec5f9e72..aa8c6cfb 100644 --- a/app/src/androidTest/java/com/futsch1/medtimer/TestDataAndDeleteAndManualDoseTest.java +++ b/app/src/androidTest/java/com/futsch1/medtimer/TestDataAndDeleteAndManualDoseTest.java @@ -49,23 +49,11 @@ public class TestDataAndDeleteAndManualDoseTest { @Test public void testDataAndDeleteAndManualDoseTest() { ViewInteraction overflowMenuButton = onView( - allOf(withContentDescription("More options"), - childAtPosition( - childAtPosition( - withId(androidx.appcompat.R.id.action_bar), - 1), - 0), - isDisplayed())); + allOf(withContentDescription("More options"))); overflowMenuButton.perform(click()); ViewInteraction materialTextView = onView( - allOf(withId(androidx.recyclerview.R.id.title), withText("Settings"), - childAtPosition( - childAtPosition( - withId(androidx.appcompat.R.id.content), - 1), - 0), - isDisplayed())); + allOf(withId(androidx.recyclerview.R.id.title), withText("Settings"))); materialTextView.perform(click()); ViewInteraction recyclerView = onView( @@ -84,14 +72,7 @@ public void testDataAndDeleteAndManualDoseTest() { appCompatCheckedTextView.perform(click()); ViewInteraction appCompatImageButton = onView( - allOf(withContentDescription("Navigate up"), - childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton.perform(click()); ViewInteraction overflowMenuButton2 = onView( @@ -105,86 +86,42 @@ public void testDataAndDeleteAndManualDoseTest() { overflowMenuButton2.perform(click()); ViewInteraction materialTextView2 = onView( - allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data"), - childAtPosition( - childAtPosition( - withId(androidx.appcompat.R.id.content), - 1), - 0), - isDisplayed())); + allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data"))); materialTextView2.perform(click()); onView(isRoot()).perform(AndroidTestHelper.waitFor(2000)); AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.MEDICINES); ViewInteraction recyclerView2 = onView( - allOf(withId(R.id.medicineList), - childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0))); + allOf(withId(R.id.medicineList))); recyclerView2.perform(actionOnItemAtPosition(0, longClick())); ViewInteraction materialTextView3 = onView( - allOf(withId(android.R.id.title), withText("Delete"), - childAtPosition( - childAtPosition( - withId(android.R.id.content), - 0), - 0), - isDisplayed())); + allOf(withId(android.R.id.title), withText("Delete"))); materialTextView3.perform(click()); ViewInteraction materialButton = onView( - allOf(withId(android.R.id.button1), withText("Yes"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); + allOf(withId(android.R.id.button1), withText("Yes"))); materialButton.perform(scrollTo(), click()); ViewInteraction recyclerView3 = onView( - allOf(withId(R.id.medicineList), - childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0))); + allOf(withId(R.id.medicineList))); recyclerView3.perform(actionOnItemAtPosition(2, click())); ViewInteraction recyclerView4 = onView( - allOf(withId(R.id.reminderList), - childAtPosition( - withClassName(is("android.widget.LinearLayout")), - 2))); + allOf(withId(R.id.reminderList))); recyclerView4.perform(actionOnItemAtPosition(1, longClick())); ViewInteraction materialTextView4 = onView( - allOf(withId(android.R.id.title), withText("Delete"), - childAtPosition( - childAtPosition( - withId(android.R.id.content), - 0), - 0), - isDisplayed())); + allOf(withId(android.R.id.title), withText("Delete"))); materialTextView4.perform(click()); ViewInteraction materialButton2 = onView( - allOf(withId(android.R.id.button1), withText("Yes"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); + allOf(withId(android.R.id.button1), withText("Yes"))); materialButton2.perform(scrollTo(), click()); ViewInteraction appCompatImageButton2 = onView( - allOf(withContentDescription("Navigate up"), - childAtPosition( - allOf(withId(androidx.appcompat.R.id.action_bar), - childAtPosition( - withId(androidx.appcompat.R.id.action_bar_container), - 0)), - 2), - isDisplayed())); + allOf(withContentDescription("Navigate up"))); appCompatImageButton2.perform(click()); AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.OVERVIEW); @@ -212,12 +149,7 @@ public void testDataAndDeleteAndManualDoseTest() { textInputEditText.perform(replaceText("1"), closeSoftKeyboard()); ViewInteraction materialButton4 = onView( - allOf(withId(android.R.id.button1), withText("OK"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); + allOf(withId(android.R.id.button1), withText("OK"))); materialButton4.perform(scrollTo(), click()); ViewInteraction materialButton5 = onView(