3

I am trying to do a long-press with flutter drive integration test.

using

await driver.tap(longPressButtonFinder);

does not help, is there something better than that?

Thomas Frick
  • 189
  • 1
  • 2
  • 12

2 Answers2

12

Update

The longPress method has been added to the WidgetTester class

Original

FlutterDriver doesn't seem to have this method out of the box.

A workaround is to scroll with a 0 delta. That will lead the driver to do what effectively is a long press.

await driver.scroll(target, 0, 0, Duration(milliseconds: 400));
joshpetit
  • 677
  • 6
  • 17
Edman
  • 5,335
  • 29
  • 32
  • thank you for your answer, unfortunately driver is a FlutterDriver and there is no longPress or is there a way to create the WidgetTester for integration test? – Thomas Frick Feb 05 '19 at 06:11
  • Would you mind sharing a bit more of your code? The widget tester should be available inside your test methods. – Edman Feb 05 '19 at 07:19
  • @ThomasFrick I dug around a bit and updated my answer. – Edman Feb 05 '19 at 08:11
  • @ThomasFrick FlutterDriver is pretty dumb. It's for runtime testing and performance profiling. WidgetTester is for instant testing in your IDE, without deploying a real build into your device, and it has much more capabillities. – Sergey Molchanovsky Jun 21 '20 at 20:03
  • As of Flutter 2 you can now long press. Look at the answer underneath – joshpetit Oct 13 '21 at 10:43
1

Starting with Flutter 2 there is the following method available within WidgetTester class.

longPress

This is more explained in the above link.

Spatz
  • 18,640
  • 7
  • 62
  • 66
Kaan
  • 23
  • 7