【问题标题】:Flutter integration test to tap on allow button in dialog fail on iOS在 iOS 上点击对话框中的允许按钮的 Flutter 集成测试失败
【发布时间】:2020-06-26 15:36:04
【问题描述】:

在 iOS 上点击对话框中允许按钮的 Flutter 集成测试失败。任何人都可以帮助完成这项工作?

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:由于远程错误而无法完成 WaitFor
原始错误:错误状态:客户端因未决请求而关闭 “ext.flutter.driver”。原始堆栈跟踪:#0 新 Client.withoutJson。 (包: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 ===== 异步间隙 =========================== dart:async/zone.dart 1064:19 _CustomZone.registerBinaryCallback dart:async-patch/async_patch.dart 82 :23 _asyncErrorWrapperHelper
包:test_api/src/backend/invoker.dart
Invoker.waitForOutstandingCallbacks。飞镖:异步/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
包:test_api/src/backend/declarer.dart 169:33
声明者.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
声明者.test。包:test_api/src/backend/invoker.dart 392:25 Invoker._onRun.... dart:async/future.dart 176:37
新的未来。
包:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
包:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback。飞镖:异步/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。包:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
包:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback。飞镖:异步/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 ===== 异步间隙 ========== ================ dart:async/zone.dart 1047:19 _CustomZone.registerCallback dart:async/zone.dart 964:22 _CustomZone.bindCallbackGuarded dart:async/timer.dart 54:45 新计时器 dart:async/timer.dart 91:9
Timer.run dart:async/future.dart 174:11
新的未来包: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.. 包:test_api/src/backend/invoker.dart 430:15 调用者._guardIfGuarded
包:test_api/src/backend/invoker.dart 377:7
调用者._onRun。包:stack_trace/src/chain.dart 101:24
链捕获。 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 包:test_api/src/backend/invoker.dart 376:11
调用者._onRun
包:test_api/src/backend/live_test_controller.dart 185:5 LiveTestController._run
包:test_api/src/backend/live_test_controller.dart 40:37 _LiveTest.run dart:async/future.dart 202:37 新的 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。飞镖 174:12 _RawReceivePortImpl._handleMessage

00:31 +1 -1:一些测试失败。

未处理的异常:设置退出代码的虚拟异常。

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) 停止应用程序

实例。驱动程序测试失败:255 [警告] FlutterDriver:waitFor 消息需要很长时间才能完成...

【问题讨论】:

标签: flutter dart integration-testing


【解决方案1】:

我希望我的发现能够对某人有所帮助。

我收到错误“DriverError:由于远程错误而无法完成 Tap”和“VMServiceFlutterDriver:tap 消息需要很长时间才能完成..”

就我而言,Flutter Driver 无法找到要测试的小部件,因为我使用的是“find.byType”。

有一次,我为所有小部件提供了“键”,并传递给使用“find.byValueKey”而不是“find.byType”,小部件已本地化并且一切正常。

这是我的代码:

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);
    });
  });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2020-12-06
    • 1970-01-01
    • 2017-02-28
    相关资源
    最近更新 更多