Find flutter sandwich menu button using flutter_driver

Issue

Find flutter sandwich menu button using flutter_driver


    Scaffold(
        key: widget.scaffoldKey,
        drawer: Observer(builder: (BuildContext context) {
          return DrawerMenu(
            user: controller.appStore.user,
            onTapLogout: controller.loginController.logout,
          );
        }),
        appBar: widget.appBar,
        body: widget.body);

button to be identified


 test('test by inserting valid username and login', () async {
      await driver.tap(buttonFinder);

      expect(await driver.getText(loginName), "LoginName");
    });

Solution

The sandwich menu you are referring to is called as Drawer, and you can tap on it using it’s toolTip property.
If you long press on the drawer menu, it will show you a tooltip, as below:

enter image description here

Then, in your flutter driver test, you can identify this widget by declaring a finder using byToolTip method, as below:

final drawerFinder = find.byTooltip('Open navigation menu');

And then write your test as:

test('tap on drawer menu', () async {
        await driver.waitFor(drawerFinder);
        await driver.tap(drawerFinder);
        print('clicked on drawer');
      });

Answered By – Darshan

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *