Skip to content

Commit ae63ff3

Browse files
committed
update to close gracefully
1 parent 3d5ec0c commit ae63ff3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

firebase-crashlytics/test-app/src/androidTest/kotlin/com/google/firebase/testing/crashlytics/FirebaseCrashlyticsIntegrationTest.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import androidx.test.core.app.ApplicationProvider
2222
import androidx.test.ext.junit.runners.AndroidJUnit4
2323
import androidx.test.platform.app.InstrumentationRegistry
2424
import androidx.test.uiautomator.By
25+
import androidx.test.uiautomator.Direction
2526
import androidx.test.uiautomator.UiDevice
2627
import androidx.test.uiautomator.Until
2728
import com.google.common.truth.Truth.assertThat
29+
import com.google.firebase.crashlytics.FirebaseCrashlytics
2830
import org.junit.After
2931
import org.junit.Assert.fail
3032
import 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

Comments
 (0)