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

How to open the Scaffold's drawer using Flutter Driver? #9002

Open
yjbanov opened this issue Mar 24, 2017 · 11 comments

Comments

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Mar 24, 2017

I'm logging this because someone asked and I don't know the answer. I should try it myself and fix it if it's not currently possible.

@yjbanov

This comment has been minimized.

Copy link
Contributor Author

@yjbanov yjbanov commented Apr 12, 2017

Here's the best solution I could think of:

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

void main() {
  group('app drawer', () {
    FlutterDriver driver;

    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    tearDownAll(() async {
      if (driver != null)
        driver.close();
    });

    test('opens and closes', () async {
      final SerializableFinder app = find.byValueKey('Gallery App');
      final SerializableFinder drawerOpenButton = find.byTooltip('Open navigation menu');

      // Open the drawer
      await driver.tap(drawerOpenButton);

      // Swipe to the left across the whole app to close the drawer
      await driver.scroll(app, -300.0, 0.0, const Duration(milliseconds: 300));
    });
  });
}

There are two quirks here:

  1. relying on tooltip text to find the drawer button seems very brittle (what if the app is internationalized) - we could provide a stable Key instead
  2. too many magical numbers used to swipe away the drawer and I'm not sure this will work in all form factors - not sure what a clean solution here yet, perhaps we could allow domain-specific commands that could be sent to widgets?
@Hixie

This comment has been minimized.

Copy link
Contributor

@Hixie Hixie commented Apr 12, 2017

How about looking for the first IconButton of the first AppBar of the Scaffold with the Drawer you want to open?

@yjbanov

This comment has been minimized.

Copy link
Contributor Author

@yjbanov yjbanov commented Apr 12, 2017

We currently do not have a serializable finder that's capable of expressing that. Driver tests run out of process, which makes it tricky to refer to a type. But it would be great if we could express it. Open to ideas.

@Hixie

This comment has been minimized.

Copy link
Contributor

@Hixie Hixie commented Apr 12, 2017

Can't we just serialise the types as strings and then search for things whose type matches that string?

@yjbanov

This comment has been minimized.

Copy link
Contributor Author

@yjbanov yjbanov commented Apr 12, 2017

That's an option, provided:

  • type names are unique enough
  • type names are not mangled by the AOT compiler (we run perf tests in AOT mode; this does happen in dart2js when the compiler tries to minify the code by shortening symbol names)
@Hixie

This comment has been minimized.

Copy link
Contributor

@Hixie Hixie commented Apr 12, 2017

I believe both of those are true.

@eseidelGoogle

This comment has been minimized.

Copy link
Contributor

@eseidelGoogle eseidelGoogle commented Apr 18, 2017

@yjbanov should this still be in M2?

@yjbanov

This comment has been minimized.

Copy link
Contributor Author

@yjbanov yjbanov commented Apr 18, 2017

This bug is related to Flutter Driver only. Unless we consider Flutter Driver a M2 feature, we should remove it from the M2 list.

@zoechi

This comment has been minimized.

Copy link
Contributor

@zoechi zoechi commented Sep 22, 2017

can this be done with #3191 ?

@yjbanov

This comment has been minimized.

Copy link
Contributor Author

@yjbanov yjbanov commented Sep 22, 2017

@zoechi I believe so, but you'll have to implement the "wait for UI to stability before continuing" logic yourself (e.g. wait for transientCallbackCount to hit zero). We recently added more methods to the driver, e.g. a type name-based finder. I should revisit this and see that the best solution is as of today.

@zoechi

This comment has been minimized.

Copy link
Contributor

@zoechi zoechi commented Sep 22, 2017

@yjbanov An runnable example would be great. Is there one somewhere?
I mean about "custom Flutter Driver commands" (#3191)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants
You can’t perform that action at this time.