使用Patrol测试包做谷歌登录集成测试时遇NativeAutomator未初始化错误

我在测试谷歌登录功能时,无法选择指定的邮箱账号。
遇到的错误如下:
_AssertionError ('package:patrol/src/custom_finders/patrol_tester.dart': Failed assertion: line 131 pos 7: 'nativeAutomator != null': NativeAutomator未初始化,请确保已向patrolTest()传入
nativeAutomation: true,且未在测试中初始化任何绑定。)
以下是代码片段:
void main() { patrolTest( 'signs up', (PatrolTester $) async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); configureDependencies(testing: true); // runZoneGuarded(() => runApp(MyApp)); await $.pumpWidget(const MyApp()); final getStartedButton = find.byKey(const Key("getStartedButton")); await $.tap(getStartedButton); await $.pumpAndSettle(); await $('LOGIN WITH GOOGLE').tap(); await $.native.tap(Selector(text: 'Neel Kothari')); await $.pumpAndSettle(); }, ); }
解决办法
- 开启原生自动化支持:在
patrolTest的参数里添加nativeAutomation: true,这是调用$.native相关方法的必要前提。 - 移除手动绑定初始化:删掉
IntegrationTestWidgetsFlutterBinding.ensureInitialized();,Patrol会自动处理绑定初始化,手动初始化会导致NativeAutomator无法正常实例化。
修改后的代码:
void main() { patrolTest( 'signs up', (PatrolTester $) async { await Firebase.initializeApp(); configureDependencies(testing: true); await $.pumpWidget(const MyApp()); final getStartedButton = find.byKey(const Key("getStartedButton")); await $.tap(getStartedButton); await $.pumpAndSettle(); await $('LOGIN WITH GOOGLE').tap(); await $.native.tap(Selector(text: 'Neel Kothari')); await $.pumpAndSettle(); }, nativeAutomation: true, // 新增配置 ); }
内容的提问来源于stack exchange,提问作者neelkothari6191
相关产品推荐
相关产品推荐

