5

In flutter integration test, if we want to tap on a button that is built by ourselves, we can easily do it by:

await driver.tap(find.byValueKey("my_lovely_button_key"));

However, if a widget is not built by us, for example, a date picker, an image picker, etc., how do we tap on any of the buttons there?

Yuchen
  • 30,852
  • 26
  • 164
  • 234
  • Tried [Find a specific widget instance](https://flutter.dev/docs/cookbook/testing/widget/finders#3-find-a-specific-widget-instance) from the flutter docs? – dev-aentgs Jun 20 '20 at 15:58
  • But we still don't know what widget to look for right? – Yuchen Jun 20 '20 at 16:07
  • Right, in cases like custom Button or similar we wont have details about the widget. – dev-aentgs Jun 20 '20 at 16:11
  • 1
    Perhaps you don't have to open a camera at all in your tests. It can be skipped and have `image_picker` lib return you some image immediately after opening camera following this answer to this question: https://stackoverflow.com/questions/56588555/how-to-test-imagepicker-in-flutter-driver – crollywood Jun 20 '20 at 17:20

1 Answers1

1

Regarding the date picker, what I found to be useful is that you can click on any button using:

await driver.tap(find.text('btn_name'));

For example, if you need the date 11 June 2020, you need to do these steps:

  1. await driver.tap(find.text('11'));
    
  2. await Future.delayed(const Duration(seconds: 1));
    
  3. await driver.tap(find.text('OK'));
    

What these steps will do is:

  1. Tap on button which has a text of "11",
  2. Wait for 1 second, and then
  3. Tap on the "OK" button.
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Andrew Arnita
  • 23
  • 1
  • 6