From 51442cb047ef47c0ddaf922ffb559804e4100fa8 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Mon, 2 Dec 2019 13:29:06 +0100 Subject: [PATCH] Making sure to not click the wrong list We might have multiple lists with the same ID in the hierarchy --- .../de/test/antennapod/playback/PlaybackTest.java | 13 +++++++++---- .../core/service/download/DownloadService.java | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java index 1a2a7e29e..3d3e50ede 100644 --- a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.view.KeyEvent; +import android.view.View; import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; @@ -22,6 +23,7 @@ import de.danoeh.antennapod.core.util.LongList; import de.test.antennapod.EspressoTestUtils; import de.test.antennapod.ui.UITestUtils; import org.awaitility.Awaitility; +import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -37,6 +39,7 @@ import java.util.concurrent.TimeUnit; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; +import static androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; @@ -233,8 +236,9 @@ public class PlaybackTest { onView(withText(R.string.all_episodes_short_label)).perform(click()); final List episodes = DBReader.getRecentlyPublishedEpisodes(0, 10); - onView(allOf(withId(android.R.id.list), isDisplayed())).perform( - actionOnItemAtPosition(0, clickChildViewWithId(R.id.butSecondaryAction))); + Matcher allEpisodesMatcher = allOf(withId(android.R.id.list), isDisplayed(), hasMinimumChildCount(2)); + onView(isRoot()).perform(waitForView(allEpisodesMatcher, 1000)); + onView(allEpisodesMatcher).perform(actionOnItemAtPosition(0, clickChildViewWithId(R.id.butSecondaryAction))); long mediaId = episodes.get(0).getMedia().getId(); Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { @@ -253,8 +257,9 @@ public class PlaybackTest { protected void playFromQueue(int itemIdx) { final List queue = DBReader.getQueue(); - onView(withId(R.id.recyclerView)).perform( - actionOnItemAtPosition(itemIdx, clickChildViewWithId(R.id.butSecondaryAction))); + Matcher queueMatcher = allOf(withId(R.id.recyclerView), isDisplayed(), hasMinimumChildCount(2)); + onView(isRoot()).perform(waitForView(queueMatcher, 1000)); + onView(queueMatcher).perform(actionOnItemAtPosition(itemIdx, clickChildViewWithId(R.id.butSecondaryAction))); onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000)); long mediaId = queue.get(itemIdx).getMedia().getId(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 04c1190a7..68aab3623 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -219,7 +219,7 @@ public class DownloadService extends Service { downloadCompletionThread.interrupt(); try { - downloadCompletionThread.join(); + downloadCompletionThread.join(1000); } catch (InterruptedException e) { e.printStackTrace(); }