Flutter integration test to tap on allow button in dialog fail on iOS

Viewed 1231

Flutter integration test to tap on allow button in dialog fail on iOS. anyone can help to make this work?

enter image description here

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

Future<void> delay([int milliseconds = 250]) async {
  await Future<void>.delayed(Duration(milliseconds: milliseconds));
}

void main() {
  group('My App', () {

    FlutterDriver driver;

    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    // Close the connection to the driver after the tests have completed.
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    }); 



     test('Allow Notification', () async {
        SerializableFinder appBarTitle = find.text("Happy");
        await driver.waitFor(appBarTitle);
        // await delay(3000); // for video capture
        expect(await driver.getText(appBarTitle), isNotEmpty);
     });

  });
}

DriverError: Failed to fulfill WaitFor due to remote error
Original error: Bad state: The client closed with pending request "ext.flutter.driver". Original stack trace: #0 new Client.withoutJson. (package:json_rpc_2/src/client.dart:70:24) #1
StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:209:15) #2
StackZoneSpecification._registerCallback. (package:stack_trace/src/stack_zone_specification.dart:119:48) #3
_rootRun (dart:async/zone.dart:1122:38) #4 _CustomZone.run (dart:async/zone.dart:1023:19) #5
_FutureListener.handleWhenComplete (dart:async/future_impl.dart:163:18) #6
Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:650:39) #7
Future._propagateToListeners (dart:async/future_impl.dart:706:37) #8 Future._propagateToListeners (dart:async/future_impl.dart:607:9) #9 Future._completeWithValue (dart:async/future_impl.dart:524:5) #10
Future._asyncComplete. (dart:async/future_impl.dart:554:7) #11
StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:209:15) #12
StackZoneSpecification._registerCallback. (package:stack_trace/src/stack_zone_specification.dart:119:48) #13
_rootRun (dart:async/zone.dart:1126:13) #14 _CustomZone.run (dart:async/zone.dart:1023:19) #15 _CustomZone.runGuarded (dart:async/zone.dart:925:7) #16
_CustomZone.bindCallbackGuarded. (dart:async/zone.dart:965:23) #17 _microtaskLoop (dart:async/schedule_microtask.dart:43:21) #18
_startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5) #19 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:393:30) #20 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5) #21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

package:flutter_driver/src/driver/driver.dart 449:7
FlutterDriver._sendCommand ===== asynchronous gap =========================== dart:async/zone.dart 1064:19 _CustomZone.registerBinaryCallback dart:async-patch/async_patch.dart 82:23 _asyncErrorWrapperHelper
package:test_api/src/backend/invoker.dart
Invoker.waitForOutstandingCallbacks. dart:async/zone.dart 1126:13 _rootRun
dart:async/zone.dart 1023:19
_CustomZone.run dart:async/zone.dart 1518:10 _runZoned dart:async/zone.dart 1465:12 runZoned package:test_api/src/backend/invoker.dart 239:5
Invoker.waitForOutstandingCallbacks
package:test_api/src/backend/declarer.dart 169:33
Declarer.test.. dart:async/zone.dart 1126:13
_rootRun dart:async/zone.dart 1023:19 _CustomZone.run dart:async/zone.dart 1518:10 _runZoned dart:async/zone.dart 1465:12 runZoned package:test_api/src/backend/declarer.dart 168:13
Declarer.test. package:test_api/src/backend/invoker.dart 392:25 Invoker._onRun.... dart:async/future.dart 176:37
new Future.
package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback. dart:async/zone.dart 1122:38 _rootRun
dart:async/zone.dart 1023:19
_CustomZone.run dart:async/zone.dart 925:7 _CustomZone.runGuarded dart:async/zone.dart 965:23 _CustomZone.bindCallbackGuarded. package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback. dart:async/zone.dart 1126:13 _rootRun
dart:async/zone.dart 1023:19
_CustomZone.run dart:async/zone.dart 949:23 _CustomZone.bindCallback. dart:async-patch/timer_patch.dart 23:15 Timer._createTimer.
dart:isolate-patch/timer_impl.dart 384:19
_Timer._runTimers dart:isolate-patch/timer_impl.dart 418:5 _Timer._handleMessage dart:isolate-patch/isolate_patch.dart 174:12 _RawReceivePortImpl._handleMessage ===== asynchronous gap =========================== dart:async/zone.dart 1047:19 _CustomZone.registerCallback dart:async/zone.dart 964:22 _CustomZone.bindCallbackGuarded dart:async/timer.dart 54:45 new Timer dart:async/timer.dart 91:9
Timer.run dart:async/future.dart 174:11
new Future package:test_api/src/backend/invoker.dart 391:21
Invoker._onRun... dart:async/zone.dart 1126:13
_rootRun dart:async/zone.dart 1023:19 _CustomZone.run dart:async/zone.dart 1518:10 _runZoned dart:async/zone.dart 1465:12 runZoned package:test_api/src/backend/invoker.dart 378:9
Invoker._onRun.. package:test_api/src/backend/invoker.dart 430:15 Invoker._guardIfGuarded
package:test_api/src/backend/invoker.dart 377:7
Invoker._onRun. package:stack_trace/src/chain.dart 101:24
Chain.capture. dart:async/zone.dart 1126:13
_rootRun dart:async/zone.dart 1023:19 _CustomZone.run dart:async/zone.dart 1518:10 _runZoned dart:async/zone.dart 1465:12 runZoned package:stack_trace/src/chain.dart 99:12
Chain.capture package:test_api/src/backend/invoker.dart 376:11
Invoker._onRun
package:test_api/src/backend/live_test_controller.dart 185:5 LiveTestController._run
package:test_api/src/backend/live_test_controller.dart 40:37 _LiveTest.run dart:async/future.dart 202:37 new Future.microtask. dart:async/zone.dart 1122:38
_rootRun dart:async/zone.dart 1023:19 _CustomZone.run dart:async/zone.dart 925:7 _CustomZone.runGuarded dart:async/zone.dart 965:23 _CustomZone.bindCallbackGuarded. dart:async/zone.dart 1126:13 _rootRun dart:async/zone.dart 1023:19 _CustomZone.run dart:async/zone.dart 925:7 _CustomZone.runGuarded dart:async/zone.dart 965:23 _CustomZone.bindCallbackGuarded. dart:async/schedule_microtask.dart 43:21
_microtaskLoop dart:async/schedule_microtask.dart 52:5 _startMicrotaskLoop dart:isolate-patch/timer_impl.dart 393:30 _Timer._runTimers dart:isolate-patch/timer_impl.dart 418:5 _Timer._handleMessage dart:isolate-patch/isolate_patch.dart 174:12 _RawReceivePortImpl._handleMessage

00:31 +1 -1: Some tests failed.

Unhandled exception: Dummy exception to set exit code.

0 _rootHandleUncaughtError. (dart:async/zone.dart:1114:29)

1 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)

2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)

3 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:393:30)

4 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)

5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12) Stopping application

instance. Driver tests failed: 255 [warning] FlutterDriver: waitFor message is taking a long time to complete...

1 Answers

I hope my finding will be able to help someone.

I got the error "DriverError: Failed to fulfill Tap due to remote error" and "VMServiceFlutterDriver: tap message is taking a long time to complete.."

In my case, Flutter Driver was not able to find the widgets to test because I was using 'find.byType'.

Once, I have given 'keys' for all widget, and pass to use 'find.byValueKey' instead 'find.byType', the widgets were localized and everything worked perfectly.

Thats my code:

void main() {
  group('reversor app integration test', () {
    FlutterDriver driver;

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

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

    // find.byType was the cause for the error 'DriverError: Failed to fulfill Tap due to remote error'
    // Given key for the three below widgets, and after hat using 'find.byValueKey', solved the problem
    var field = find.byValueKey("TextField");
    var btn = find.byValueKey("button");
    var reverse = find.byValueKey("response");

    test('Reversing the string', () async {
      await driver.clearTimeline();
      await driver.tap(field);
      await driver.enterText("Hello222");
      await driver.waitForAbsent(reverse);
      await driver.tap(btn);
      await driver.waitFor(reverse);
      await driver.waitUntilNoTransientCallbacks();
      assert(reverse != null);
    });
  });
}
Related