From b8759628efb307d2572a89437eebfe8ce872096e Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Tue, 15 Sep 2015 17:09:09 -0400 Subject: Fix playback tests that don't always work. * user the view and not the text * clear preferences earlier in setup --- .../java/de/test/antennapod/ui/PlaybackTest.java | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'app/src/androidTest/java/de/test') 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 { 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 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 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 } 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 episodes = DBReader.getRecentlyPublishedEpisodes(10); assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); @@ -215,7 +226,14 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2 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 queue = DBReader.getQueue(); -- cgit v1.2.3