From 1a00b4b77943690b82ae40d4f03b27e56fc6c7f5 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Wed, 11 May 2022 18:24:34 +0200 Subject: [PATCH] UI tests slightly more robust. --- .../EspressoEditTrackRecordingTest.java | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/androidTest/java/de/dennisguse/opentracks/EspressoEditTrackRecordingTest.java b/src/androidTest/java/de/dennisguse/opentracks/EspressoEditTrackRecordingTest.java index 2b364e7de..e39957271 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/EspressoEditTrackRecordingTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/EspressoEditTrackRecordingTest.java @@ -5,18 +5,14 @@ import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +import static androidx.test.espresso.action.ViewActions.longClick; import static androidx.test.espresso.action.ViewActions.replaceText; import static androidx.test.espresso.action.ViewActions.scrollTo; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withClassName; 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.is; -import static de.dennisguse.opentracks.util.EspressoUtils.childAtPosition; -import static de.dennisguse.opentracks.util.EspressoUtils.veryLongTouch; import static de.dennisguse.opentracks.util.EspressoUtils.waitFor; import androidx.test.espresso.ViewInteraction; @@ -25,7 +21,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; 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; @@ -58,7 +53,7 @@ public class EspressoEditTrackRecordingTest { ViewInteraction trackControllerStopButton = onView(withId(R.id.track_recording_fab_action)); // wait; stay recording - trackControllerStopButton.perform(waitFor(15000)); + trackControllerStopButton.perform(waitFor(4000)); // open menu openContextualActionModeOverflowMenu(); @@ -67,23 +62,10 @@ public class EspressoEditTrackRecordingTest { onView(withText(R.string.menu_edit)).perform(click()); // change name for "New Name" - ViewInteraction textInputEditText = onView( - allOf(withId(R.id.track_edit_name), - childAtPosition( - childAtPosition( - withClassName(is("com.google.android.material.textfield.TextInputLayout")), - 0), - 1))); + ViewInteraction textInputEditText = onView(withId(R.id.track_edit_name)); textInputEditText.perform(scrollTo(), replaceText("New Name")); - ViewInteraction textInputEditText2 = onView( - allOf(withId(R.id.track_edit_name), withText("New Name"), - childAtPosition( - childAtPosition( - withClassName(is("com.google.android.material.textfield.TextInputLayout")), - 0), - 1), - isDisplayed())); + ViewInteraction textInputEditText2 = onView(allOf(withId(R.id.track_edit_name), withText("New Name"), isDisplayed())); textInputEditText2.perform(closeSoftKeyboard()); // save edition @@ -91,7 +73,7 @@ public class EspressoEditTrackRecordingTest { appCompatButton.perform(click()); // stop; - trackControllerStopButton.perform(veryLongTouch(1600)); + trackControllerStopButton.perform(longClick()); // it's on track stopped activity and there are two buttons ViewInteraction resumeButton = onView(withId(R.id.resume_button)); @@ -100,5 +82,4 @@ public class EspressoEditTrackRecordingTest { finishButton.check(matches(isDisplayed())); } } - }