leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
854 stars 127 forks source link

Full close app (no app in background, or paused state in android) #2149

Open jttuboi opened 6 months ago

jttuboi commented 6 months ago

Use case

I need a test which simulates run again the loading of the app in the same tests.

To do this in manual test, I close the app (ex: clicking in home button), click in overview button (or recent apps button), swipe to up to close the app in background, and open the app again.

I did this using patrol:

  patrolTest('close app in background', ($) async {
    await app.main();
    await $.pumpAndSettle();

    await $.native.pressHome();
    await $.native.pressRecentApps();
    await $.native.swipe(from: const Offset(0.5, 0.5), to: const Offset(0.5, 0));

    // ... open app and check loading
  });

Proposal

Continuing...

And oks for me. But it's good to have a function to do this like as $.native.closeNotifications() to simplify this feature. In android, I know some versions you need to swipe up, but it has old ones you need swipe right, so my tests would break because of this. Of course I will not use an emulator which needs swipe right, this is only a motivation to have an official close app in background method.

Maybe a good name for this method is $.native.closeAppInBackground(), and instead do these steps, only force close (if it is possible, I didn't check if automator can do this).

  patrolTest('close app in background', ($) async {
    await app.main();
    await $.pumpAndSettle();

    await $.native.closeAppInBackground();

    // ... open app and check loading
  });
bartekpacia commented 6 months ago

This is impossible to do with Patrol's current architecture. See #1374 for more details.