summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
diff options
context:
space:
mode:
authorH. Lehmann <ByteHamster@users.noreply.github.com>2019-12-20 00:12:51 +0100
committerGitHub <noreply@github.com>2019-12-20 00:12:51 +0100
commit707fcdbc7fc874b99cc08e14906310c718b5e8a7 (patch)
tree6de1485cb2494299b39e70488e68c658ee8fb442 /app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
parent19890afc663d067f70e0286eeaa73cb8cb7acbad (diff)
parent6dc361c5424a9b5b3f516cd2aa531b88011a3413 (diff)
downloadAntennaPod-707fcdbc7fc874b99cc08e14906310c718b5e8a7.zip
Merge pull request #3654 from ByteHamster/emulator-test
Run integration tests on CI
Diffstat (limited to 'app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java67
1 files changed, 62 insertions, 5 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
index c76cd2032..bbd8a705c 100644
--- a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
+++ b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
@@ -1,6 +1,8 @@
package de.test.antennapod;
import android.content.Context;
+import android.content.Intent;
+import androidx.annotation.IdRes;
import androidx.annotation.StringRes;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.PerformException;
@@ -14,11 +16,16 @@ import androidx.test.espresso.util.TreeIterables;
import android.view.View;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.core.service.download.DownloadService;
+import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.dialog.RatingDialog;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionTimeoutException;
import org.hamcrest.Matcher;
import java.io.File;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static androidx.test.espresso.Espresso.onView;
@@ -77,6 +84,31 @@ public class EspressoTestUtils {
}
/**
+ * Perform action of waiting for a specific view id.
+ * https://stackoverflow.com/a/30338665/
+ * @param id The id of the child to click.
+ */
+ public static ViewAction clickChildViewWithId(final @IdRes int id) {
+ return new ViewAction() {
+ @Override
+ public Matcher<View> getConstraints() {
+ return null;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Click on a child view with specified id.";
+ }
+
+ @Override
+ public void perform(UiController uiController, View view) {
+ View v = view.findViewById(id);
+ v.performClick();
+ }
+ };
+ }
+
+ /**
* Clear all app databases
*/
public static void clearPreferences() {
@@ -127,12 +159,37 @@ public class EspressoTestUtils {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
}
- public static void closeNavDrawer() {
- onView(isRoot()).perform(waitForView(withId(R.id.drawer_layout), 1000));
- onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());
- }
-
public static ViewInteraction onDrawerItem(Matcher<View> viewMatcher) {
return onView(allOf(viewMatcher, withId(R.id.txtvTitle)));
}
+
+ public static void tryKillPlaybackService() {
+ Context context = InstrumentationRegistry.getTargetContext();
+ context.stopService(new Intent(context, PlaybackService.class));
+ try {
+ // Android has no reliable way to stop a service instantly.
+ // Calling stopSelf marks allows the system to destroy the service but the actual call
+ // to onDestroy takes until the next GC of the system, which we can not influence.
+ // Try to wait for the service at least a bit.
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
+ } catch (ConditionTimeoutException e) {
+ e.printStackTrace();
+ }
+ androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ }
+
+ public static void tryKillDownloadService() {
+ Context context = InstrumentationRegistry.getTargetContext();
+ context.stopService(new Intent(context, DownloadService.class));
+ try {
+ // Android has no reliable way to stop a service instantly.
+ // Calling stopSelf marks allows the system to destroy the service but the actual call
+ // to onDestroy takes until the next GC of the system, which we can not influence.
+ // Try to wait for the service at least a bit.
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !DownloadService.isRunning);
+ } catch (ConditionTimeoutException e) {
+ e.printStackTrace();
+ }
+ androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ }
}