@@ -7,6 +7,7 @@ import 'package:appium_flutter_server/src/exceptions/flutter_automation_error.da
77import 'package:appium_flutter_server/src/internal/element_lookup_strategy.dart' ;
88import 'package:appium_flutter_server/src/internal/flutter_element.dart' ;
99import 'package:appium_flutter_server/src/logger.dart' ;
10+ import 'package:appium_flutter_server/src/models/api/drag_drop.dart' ;
1011import 'package:appium_flutter_server/src/models/api/gesture.dart' ;
1112import 'package:appium_flutter_server/src/models/api/find_element.dart' ;
1213import 'package:appium_flutter_server/src/models/session.dart' ;
@@ -71,7 +72,7 @@ class ElementHelper {
7172 static Future <void > click (FlutterElement element) async {
7273 WidgetTester tester = _getTester ();
7374 await tester.tap (element.by);
74- await tester. pumpAndSettle ();
75+ await pumpAndTrySettle ();
7576 }
7677
7778 static Future <void > setText (FlutterElement element, String text) async {
@@ -117,7 +118,7 @@ class ElementHelper {
117118 await tester.pump (kDoubleTapMinTime);
118119 await tester.tapAt (Offset (bounds.left + doubleClickModel.offset! .x,
119120 bounds.top + doubleClickModel.offset! .y));
120- await tester. pumpAndSettle ();
121+ await pumpAndTrySettle ();
121122 }
122123 }
123124 });
@@ -128,7 +129,7 @@ class ElementHelper {
128129 await tester.tap (element.by);
129130 await tester.pump (kDoubleTapMinTime);
130131 await tester.tap (element.by);
131- await tester. pumpAndSettle ();
132+ await pumpAndTrySettle ();
132133 }
133134
134135 static Future <void > longPress (GestureModel longPressModel) async {
@@ -162,7 +163,7 @@ class ElementHelper {
162163 log ("Click by offset $bounds " );
163164 await tester.longPressAt (
164165 Offset (longPressModel.offset! .x, longPressModel.offset! .y));
165- await tester. pumpAndSettle ();
166+ await pumpAndTrySettle ();
166167 }
167168 }
168169 });
@@ -444,12 +445,30 @@ class ElementHelper {
444445 : 'Timed out waiting for condition' );
445446 }
446447 if (Platform .isAndroid) {
447- await tester. pumpAndSettle ( );
448+ await pumpAndTrySettle (timeout : const Duration (milliseconds : 200 ) );
448449 }
449450 await Future .delayed (const Duration (milliseconds: 100 ));
450451 } while (! (await predicate ()));
451452 }
452453
454+ static Future <void > dragAndDrop (DragAndDropModel model) async {
455+ return TestAsyncUtils .guard (() async {
456+ WidgetTester tester = _getTester ();
457+ final String sourceElementId = model.source.id;
458+ final String targetElementId = model.target.id;
459+ Session session = FlutterDriver .instance.getSessionOrThrow ()! ;
460+ FlutterElement sourceEl = await session.elementsCache.get (sourceElementId);
461+ FlutterElement targetEl = await session.elementsCache.get (targetElementId);
462+ final Offset sourceElementLocation = tester.getCenter (sourceEl.by);
463+ final Offset targetElementLocation = tester.getCenter (targetEl.by);
464+ final TestGesture gesture = await tester.startGesture (sourceElementLocation, pointer: 7 );
465+ await gesture.moveTo (targetElementLocation);
466+ await tester.pump ();
467+ await gesture.up ();
468+ await tester.pump ();
469+ });
470+ }
471+
453472 static Future <Finder > scrollUntilVisible ({
454473 required FindElementModel finder,
455474 FindElementModel ? scrollView,
@@ -540,4 +559,25 @@ class ElementHelper {
540559 return const Uuid ().v4 ();
541560 }
542561 }
562+ static Future <void > pumpAndTrySettle ({
563+ Duration duration = const Duration (milliseconds: 100 ),
564+ EnginePhase phase = EnginePhase .sendSemanticsUpdate,
565+ Duration timeout = const Duration (milliseconds: 200 ),
566+ }) async {
567+ try {
568+ WidgetTester tester = _getTester ();
569+ await tester.pumpAndSettle (
570+ duration,
571+ phase,
572+ timeout,
573+ );
574+ } on FlutterError catch (err) {
575+ if (err.message == 'pumpAndSettle timed out' ) {
576+ //This method ignores pumpAndSettle timeouts on purpose
577+ } else {
578+ rethrow ;
579+ }
580+ }
581+ }
582+
543583}
0 commit comments