Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivityScenario changes behavior of Navigation Component and breaks backstack #759

Open
lwasyl opened this issue Oct 8, 2020 · 3 comments

Comments

@lwasyl
Copy link

lwasyl commented Oct 8, 2020

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

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

fragmentA is never shown again

@lwasyl
Copy link
Author

lwasyl commented Oct 8, 2020

Possibly related #427

@bastienpaulfr
Copy link

Same issue here, I have the backtstack f***cked up because of BootstrapActivity

@bastienpaulfr
Copy link

This repo show the issue with another use case : https://github.com/bastienpaulfr/ActivityScenarioBug/tree/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants