android / android/android-test

ActivityScenario changes behavior of Navigation Component and breaks backstack

Offen
#759 3 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
1.2k
Forks
342
Ø Merge
11 Std. 29 Min.
Gemergte PRs (30 T.)
2

Beschreibung

### Description
When using `ActivityScenario`, backstack doesn't work as expected when launching deeplinks.

### Steps to Reproduce
Please see the repro project at https://github.com/lwasyl/activity-scenario-navigation-issue.
1. Navigation library is set up with navigation graph that defines deeplinks
2. Press the button to display a notification. The notification opens the app on FragmentB, with fragmentA in the backstack.
3. Press back button

### Expected Results
Fragment A is visible, as it's the previous one on the backstack.

### Actual Results
When starting main activity normally (via launcher), backstack works as expected: after clicking the notification, fragment B is visible. Then, after pressing back button, fragment A is visible.

When starting main activity via `ActivityScenario`, backstack doesn't work as expected: after clicking the notification, fragment B is visible, however after pressing back button, _app exits_.

Please note that the behavior was correct (that is, consistent with how the app behaves outside the tests) with `ActivityTestRule`, which is now deprecated. There's no clear migration path to test the now-failing case with `ActivityScenario`.

### AndroidX Test and Android OS Versions
`androidx.test.ext:junit-ktx:1.1.2`
Checked on various emulators and it doesn't seem to be related to OS version. Reproduced on API 26, 29, 30 (https://github.com/lwasyl/activity-scenario-navigation-issue/actions/runs/295793564)

### Link to a public git repo demonstrating the problem:
https://github.com/lwasyl/activity-scenario-navigation-issue

Here's how the app behaves normally:
![running-from-launcher](https://user-images.githubusercontent.com/3951580/95485496-1d840a80-0992-11eb-8f07-30fe2885028c.gif)

When pressing back, app properly cycles through the backstack.

Here's UI tests that uses `ActivityScenario` and performs exactly the same steps as I did manually in the gif above (run the main activity, press button, press on notification, press back button):
![running-test](https://user-images.githubusercontent.com/3951580/95485579-3db3c980-0992-11eb-8c06-776b24e985b9.gif)

fragmentA is never shown again

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem verlinkten Repro-Projekt und seinem UI-Test mit ActivityScenario; vergleiche anschließend dessen Lifecycle- und Backstack-Verhalten mit dem normalen Launcher-Flow und der veralteten ActivityTestRule. Reproduziere den Notification-Deeplink auf den aufgeführten API-Levels und ermittle, warum das Drücken von Zurück beendet, statt FragmentA anzuzeigen; fertig ist es, wenn der Test-Flow dem normalen App-Verhalten entspricht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, java
Bereich
mobile-dev, testing
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.