diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-09-15 17:10:17 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-09-15 17:10:17 -0400 |
commit | d703a2b218c7a338d4955f057f21317bd9b0795a (patch) | |
tree | 44d831b277c7c205319ea5c4650b6ee1d268b3da | |
parent | 66d36ec00f4932d17ba10eb0b81ed47c8ea94d49 (diff) | |
parent | b8759628efb307d2572a89437eebfe8ce872096e (diff) | |
download | AntennaPod-d703a2b218c7a338d4955f057f21317bd9b0795a.zip |
Merge pull request #1206 from TomHennen/make_playbacktests_more_reliable
Fix playback tests that don't always work.
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java index b3c2ee2be..a27089726 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java @@ -7,7 +7,9 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.test.ActivityInstrumentationTestCase2; import android.test.FlakyTest; +import android.view.View; import android.widget.ImageButton; +import android.widget.ListView; import com.robotium.solo.Solo; import com.robotium.solo.Timeout; @@ -33,6 +35,8 @@ import de.danoeh.antennapod.core.util.playback.PlaybackController; public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> { private static final String TAG = PlaybackTest.class.getSimpleName(); + public static final int EPISODES_DRAWER_LIST_INDEX = 1; + public static final int QUEUE_DRAWER_LIST_INDEX = 0; private Solo solo; private UITestUtils uiTestUtils; @@ -141,12 +145,20 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> PodDBAdapter.deleteDatabase(); + context = getInstrumentation().getTargetContext(); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit() + .clear() + .putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false) + .putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false) + .commit(); + controller = createController(getActivity()); controller.init(); solo = new Solo(getInstrumentation(), getActivity()); - context = getInstrumentation().getTargetContext(); uiTestUtils = new UITestUtils(context); uiTestUtils.setup(); @@ -154,13 +166,6 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); adapter.close(); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit() - .clear() - .putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false) - .putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false) - .commit(); } @Override @@ -191,12 +196,18 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> } private void startLocalPlayback() { - String allEpisodesLabel = solo.getString(R.string.all_episodes_label); - if(!getActivity().getSupportActionBar().getTitle().equals(allEpisodesLabel)) { - openNavDrawer(); - solo.clickOnText(solo.getString(R.string.episodes_label)); - solo.clickOnText(solo.getString(R.string.all_episodes_short_label)); - } + openNavDrawer(); + // if we try to just click on plain old text then + // we might wind up clicking on the fragment title and not + // the drawer element like we want. + ListView drawerView = (ListView)solo.getView(R.id.nav_list); + // this should be 'Episodes' + View targetView = drawerView.getChildAt(EPISODES_DRAWER_LIST_INDEX); + solo.waitForView(targetView); + solo.clickOnView(targetView); + solo.waitForText(solo.getString(R.string.all_episodes_short_label)); + solo.clickOnText(solo.getString(R.string.all_episodes_short_label)); + final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(10); assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); @@ -215,7 +226,14 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> private void startLocalPlaybackFromQueue() { openNavDrawer(); - solo.clickOnText(solo.getString(R.string.queue_label)); + // if we try to just click on plain old text then + // we might wind up clicking on the fragment title and not + // the drawer element like we want. + ListView drawerView = (ListView)solo.getView(R.id.nav_list); + // this should be 'Queue' + View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX); + solo.waitForView(targetView); + solo.clickOnView(targetView); assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); final List<FeedItem> queue = DBReader.getQueue(); |