Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find iOS back button programatically with FlutterDriver

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)?

like image 617
hunter Avatar asked Jul 10 '18 04:07

hunter


People also ask

How do I get the back button in Flutter?

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.

What is Flutter driver?

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).


2 Answers

await driver.tap(find.pageBack());
like image 72
jeroentrappers Avatar answered Nov 15 '22 09:11

jeroentrappers


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);
like image 26
tomrozb Avatar answered Nov 15 '22 09:11

tomrozb