Flutter Driver - 如何知道哪个 "waitFor" 命令失败了?
Flutter Driver - How to know which "waitFor" command has failed?
我正在使用 Flutter Driver 为我们的应用程序编写一些集成测试,我正在尝试使用 waitFor
命令等待元素出现。
该命令运行良好并等待我的元素,或者在找不到它时失败。我的问题是,当它失败时,控制台中的日志不会告诉我哪个 waitFor
调用失败了。
我运行,例如下面代码等待myButton1和myButton2:
Duration timeout = new Duration(seconds: 2);
await _driver.waitFor(myButton1, timeout: timeout);
await _driver.waitFor(myButton2, timeout: timeout);
但是,当我 运行 测试时,它们失败并显示以下错误消息:
00:04 +0 -1: Buttons shown when app is started [E]
DriverError: Error in Flutter application: Timeout while executing waitFor: TimeoutException after 0:00:02.000000: Future not completed
package:flutter_driver/src/driver/vmservice_driver.dart 343:7 VMServiceFlutterDriver.sendCommand
00:04 +0 -1: Buttons (tearDownAll) [ +77 ms] test 0: process with pid 87459 no longer needed by test harness
[ ] test 0: cleaning up...
[ ] test 0: ensuring end-of-process for shell
[ +10 ms] test 0: deleting temporary directory
[ +4 ms] test 0: shutting down test harness socket server
[ +2 ms] test 0: finished
00:04 +0 -1: Some tests failed.
[ +13 ms] Deleting /var/folders/xt/0fckrj2558746_v71h2vwqh00000gn/T/flutter_tools.WEuo76/flutter_test_compiler.u7VNn4...
[ +9 ms] killing pid 87444
[ +37 ms] Deleting /var/folders/xt/0fckrj2558746_v71h2vwqh00000gn/T/flutter_tools.WEuo76/flutter_test_fonts.FDpcXF...
[ +6 ms] test package returned with exit code 1
[ +13 ms] "flutter test" took 4,890ms.
[ +6 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1 TestCommand.runCommand (package:flutter_tools/src/commands/test.dart:292:7)
<asynchronous suspension>
#2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:860:18)
#3 _rootRunUnary (dart:async/zone.dart:1198:47)
#4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#9 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#10 _rootRun (dart:async/zone.dart:1190:13)
#11 _CustomZone.run (dart:async/zone.dart:1093:19)
#12 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#13 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#14 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#15 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#16 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
[ +254 ms] ensureAnalyticsSent: 251ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hook priority 4
[ ] Shutdown hooks complete
[ ] exiting with code 1
此信息没有告诉我失败的是 myButton1 还是 myButton2。它也没有给我测试中的任何代码行来指示哪一行实际上有错误。
对此有什么想法吗?
我还没有想出是否有 built-in 方法可以做到这一点,但我写了一个辅助方法来获取我需要的信息:
Future waitForObject(SerializableFinder object, Duration timeout, {String errorMessage = "waitForObject timed out"}) async {
var message = "ERROR ==> $errorMessage";
return await _driver.waitFor(object, timeout: timeout).catchError((e) { throw(message);});
}
如果未找到对象,超时后仍会抛出错误,但它还会将我指向代码中导致超时的确切行。
我正在使用 Flutter Driver 为我们的应用程序编写一些集成测试,我正在尝试使用 waitFor
命令等待元素出现。
该命令运行良好并等待我的元素,或者在找不到它时失败。我的问题是,当它失败时,控制台中的日志不会告诉我哪个 waitFor
调用失败了。
我运行,例如下面代码等待myButton1和myButton2:
Duration timeout = new Duration(seconds: 2);
await _driver.waitFor(myButton1, timeout: timeout);
await _driver.waitFor(myButton2, timeout: timeout);
但是,当我 运行 测试时,它们失败并显示以下错误消息:
00:04 +0 -1: Buttons shown when app is started [E]
DriverError: Error in Flutter application: Timeout while executing waitFor: TimeoutException after 0:00:02.000000: Future not completed
package:flutter_driver/src/driver/vmservice_driver.dart 343:7 VMServiceFlutterDriver.sendCommand
00:04 +0 -1: Buttons (tearDownAll) [ +77 ms] test 0: process with pid 87459 no longer needed by test harness
[ ] test 0: cleaning up...
[ ] test 0: ensuring end-of-process for shell
[ +10 ms] test 0: deleting temporary directory
[ +4 ms] test 0: shutting down test harness socket server
[ +2 ms] test 0: finished
00:04 +0 -1: Some tests failed.
[ +13 ms] Deleting /var/folders/xt/0fckrj2558746_v71h2vwqh00000gn/T/flutter_tools.WEuo76/flutter_test_compiler.u7VNn4...
[ +9 ms] killing pid 87444
[ +37 ms] Deleting /var/folders/xt/0fckrj2558746_v71h2vwqh00000gn/T/flutter_tools.WEuo76/flutter_test_fonts.FDpcXF...
[ +6 ms] test package returned with exit code 1
[ +13 ms] "flutter test" took 4,890ms.
[ +6 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1 TestCommand.runCommand (package:flutter_tools/src/commands/test.dart:292:7)
<asynchronous suspension>
#2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:860:18)
#3 _rootRunUnary (dart:async/zone.dart:1198:47)
#4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#9 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#10 _rootRun (dart:async/zone.dart:1190:13)
#11 _CustomZone.run (dart:async/zone.dart:1093:19)
#12 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#13 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#14 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#15 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#16 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
[ +254 ms] ensureAnalyticsSent: 251ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hook priority 4
[ ] Shutdown hooks complete
[ ] exiting with code 1
此信息没有告诉我失败的是 myButton1 还是 myButton2。它也没有给我测试中的任何代码行来指示哪一行实际上有错误。
对此有什么想法吗?
我还没有想出是否有 built-in 方法可以做到这一点,但我写了一个辅助方法来获取我需要的信息:
Future waitForObject(SerializableFinder object, Duration timeout, {String errorMessage = "waitForObject timed out"}) async {
var message = "ERROR ==> $errorMessage";
return await _driver.waitFor(object, timeout: timeout).catchError((e) { throw(message);});
}
如果未找到对象,超时后仍会抛出错误,但它还会将我指向代码中导致超时的确切行。