I'm using FlutterDriver to perform integration testing for a Flutter package.
When the platform is Android, an AppBar is used in the scaffold, and when the platform is iOS, a CupertinoNavigationBar is used.
When testing on Android I can find the back button with the following code
await driver.tap(find.byTooltip('Back'));
However this fails on iOS. As the button is generated automatically I'm unable to add a tag programatically. Any suggestions for how to select it on iOS? Bonus points for cross-platform solutions.
Also, any suggestions for simulating an android-device back button tap (outside of the app)?
A BackButton is an IconButton with a "back" icon appropriate for the current TargetPlatform. When pressed, the back button calls Navigator. maybePop to return to the previous route unless a custom onPressed callback is provided. When deciding to display a BackButton, consider using ModalRoute.
Provides API to test Flutter applications that run on real devices and emulators. The application runs in a separate process from the test itself. This is Flutter's version of Selenium WebDriver (generic web), Protractor (Angular), Espresso (Android) or Earl Gray (iOS).
await driver.tap(find.pageBack());
Unfortunately the accepted solution await driver.tap(find.pageBack())
didn't work for me.
So I added Key
to the AppBar
and accessed the BackButton
like below
final appBar = find.byValueKey("appBarKey");
await driver.waitFor(appBar);
final back = find.descendant(
of: appBar,
matching: find.byType('BackButton'),
firstMatchOnly: true,
);
await driver.tap(back);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With