@@ -22,9 +22,11 @@ import androidx.test.core.app.ApplicationProvider
2222import androidx.test.ext.junit.runners.AndroidJUnit4
2323import androidx.test.platform.app.InstrumentationRegistry
2424import androidx.test.uiautomator.By
25+ import androidx.test.uiautomator.Direction
2526import androidx.test.uiautomator.UiDevice
2627import androidx.test.uiautomator.Until
2728import com.google.common.truth.Truth.assertThat
29+ import com.google.firebase.crashlytics.FirebaseCrashlytics
2830import org.junit.After
2931import org.junit.Assert.fail
3032import org.junit.Before
@@ -291,7 +293,7 @@ class FirebaseCrashlyticsIntegrationTest {
291293 launchApp()
292294
293295 // Close the app
294- Runtime .getRuntime().exec(arrayOf( " am " , " force-stop " , APP_NAME ) )
296+ closeAppFromRecents(device )
295297
296298 launchApp()
297299 val hasCrashedText = readDidCrashPreviouslyText()
@@ -425,6 +427,30 @@ class FirebaseCrashlyticsIntegrationTest {
425427 // Navigation & UI Helpers
426428 // ---------------------------------------------------------------------------
427429
430+ private fun closeAppFromRecents (
431+ device : UiDevice ,
432+ ) {
433+ // 1) Open Recent Apps
434+ device.pressRecentApps()
435+
436+ // 2) Wait a moment for Recents to appear
437+ Thread .sleep(1000 )
438+
439+ // 3) Swipe upward from the middle of the screen
440+ // to about a quarter of the screen height (adjust as needed).
441+ val startX = device.displayWidth / 2
442+ val startY = device.displayHeight / 2
443+ val endX = device.displayWidth / 2
444+ val endY = device.displayHeight / 4
445+
446+ // 'steps' parameter controls the speed/animation of the swipe
447+ // Larger = slower swipe, smaller = faster
448+ device.swipe(startX, startY, endX, endY, 5 )
449+
450+ // Wait a bit to ensure the system completes the action
451+ Thread .sleep(1000 )
452+ }
453+
428454 companion object {
429455 private const val TEST_APP_PACKAGE = " com.google.firebase.testing.crashlytics"
430456 private const val LAUNCH_TIMEOUT = 5_000L
0 commit comments