我正在尝试在颤振应用程序上运行自动化测试,但是当应用程序等待主页加载时会生成以下错误
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: tap message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: tap message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
Exception: DriverError: Error in Flutter application: Uncaught extension error while executing tap: Guarded function conflict.
You must use "await" with all Future-returning test APIs.
The guarded method "tapAt" from class WidgetController was called from package:flutter_driver/src/extension/extension.dart on line 460.
Then, the "_getElementPoint" method (also from class WidgetController) was called again from package:flutter_driver/src/extension/extension.dart on line 460.
The first method (WidgetController.tapAt) had not yet finished executing at the time that the second method (WidgetController._getElementPoint) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.
当第一个方法(WidgetController.tapAt)被调用时,这是堆栈:
#0 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:70:54)
#1 WidgetController.tapAt (package:flutter_test/src/controller.dart:264:27)
#2 WidgetController.tap (package:flutter_test/src/controller.dart:259:12)
#3 FlutterDriverExtension._tap (package:flutter_driver/src/extension/extension.dart:460:19)
<asynchronous suspension>
#4 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:270:53)
#5 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:547:32)
<asynchronous suspension>
#6 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart)
#7 _runExtension (dart:developer-patch/developer.dart:84:23)
#0 TestAsyncUtils.guardSync (package:flutter_test/src/test_async_utils.dart:268:5)
#1 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:817:20)
#2 WidgetController.getCenter (package:flutter_test/src/controller.dart:790:12)
#3 WidgetController.tap (package:flutter_test/src/controller.dart:259:18)
#4 FlutterDriverExtension._tap (package:flutter_driver/src/extension/extension.dart:460:19)
<asynchronous suspension>
#5 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:270:53)
#6 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:547:32)
<asynchronous suspension>
#7 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart)
#8 _runExtension (dart:developer-patch/developer.dart:84:23)
Exception: DriverError: Error in Flutter application: Uncaught extension error while executing tap: Guarded function conflict.
You must use "await" with all Future-returning test APIs.
The guarded method "tapAt" from class WidgetController was called from package:flutter_driver/src/extension/extension.dart on line 460.
Then, the "_getElementPoint" method (also from class WidgetController) was called again from package:flutter_driver/src/extension/extension.dart on line 460.
The first method (WidgetController.tapAt) had not yet finished executing at the time that the second method (WidgetController._getElementPoint) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.
当第一个方法(WidgetController.tapAt)被调用时,这是堆栈:
#0 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:70:54)
#1 WidgetController.tapAt (package:flutter_test/src/controller.dart:264:27)
#2 WidgetController.tap (package:flutter_test/src/controller.dart:259:12)
#3 FlutterDriverExtension._tap (package:flutter_driver/src/extension/extension.dart:460:19)
<asynchronous suspension>
#4 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:270:53)
#5 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:547:32)
<asynchronous suspension>
#6 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart)
#7 _runExtension (dart:developer-patch/developer.dart:84:23)
#0 TestAsyncUtils.guardSync (package:flutter_test/src/test_async_utils.dart:268:5)
#1 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:817:20)
#2 WidgetController.getCenter (package:flutter_test/src/controller.dart:790:12)
#3 WidgetController.tap (package:flutter_test/src/controller.dart:259:18)
#4 FlutterDriverExtension._tap (package:flutter_driver/src/extension/extension.dart:460:19)
<asynchronous suspension>
#5 FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:270:53)
#6 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:547:32)
<asynchronous suspension>
#7 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart)
#8 _runExtension (dart:developer-patch/developer.dart:84:23)
我的 home_screen 代码
import 'package:flutter_driver/flutter_driver.dart';
class HomeScreen {
FlutterDriver _driver;
//Constructor
HomeScreen(FlutterDriver driver) {
this._driver = driver;
}
//Elements
final btnHamburger = find.byType("InkWell");
//Actions
Future<void> waitBtnHamburger() async {
await _driver.waitFor(btnHamburger);
await print("Ok Hamburguer");
}
}
我的 home_step 代码
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
import '../screens/home_screen.dart';
class HomeValidarScreen extends ThenWithWorld<FlutterWorld> {
HomeValidarScreen()
: super(StepDefinitionConfiguration()..timeout = Duration(seconds: 20));
@override
RegExp get pattern => RegExp(r"sou direcionado para a Home do aplicativo");
@override
Future<void> executeStep() async {
HomeScreen homeScreen = new HomeScreen(world.driver);
await homeScreen.waitBtnHamburger();
}
}