我在 Flutter 中运行集成测试时遇到 Patrol 问题。我需要接受一些权限,并且我想为此目的使用 Petrol 包。但是在终端中出现一个错误,如下所示:
Patrol (native): configure() started
Patrol (native): configure() failed
Patrol (native): configure() failed: (GrpcError: configure() failed with code UNAVAILABLE (Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 53108))
Patrol (native): trying to configure() again in 1 second
这是我的代码,我在其中初始化 NativeAutomator。
void main() async {
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
final automator = NativeAutomator(
config: NativeAutomatorConfig(
packageName: 'my.app.android.id',
bundleId: 'my.app.ios.id',
),
);
await automator.configure();
testWidgets('Log Out', (WidgetTester tester) async {
await SharedPreferencesHelper.clear();
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 15));
await TestHelper.delayUntil(
tester,
find.byType(LoginBody),
);
await Future<void>.delayed(const Duration(seconds: 3));
await tester.enterText(
Consts.email,
);
await delayUI();
await tester.pumpAndSettle();
await tester.enterText(
Consts.password,
);
await delayUI();
await tester.tap(find.byType(Button));
await tester.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 5));
automator.grantPermissionOnlyThisTime();
await Future<void>.delayed(const Duration(seconds: 5));
expect(find.byType(LoginBody), findsOneWidget);
});
}
提前感谢您的帮助:)
您不能在小部件测试中使用巡逻您必须使用patrolTest和patrol_cli 命令是:
patrol test integration_test/example_test.dart
例如:
patrolTest(
'selects an image using a native file picker',
nativeAutomation: true,
($) async {
await $.pumpWidgetAndSettle(
MainApp(
key: UniqueKey(),
),
);
await $('Open file picker').tap();
expect(find.byKey(const Key('image_0')), findsNothing);
await $.native.tap(Selector(text: 'download.jpg'));
await $.pumpAndSettle();
await $.pumpAndSettle();
expect(find.byKey(const Key('image_0')), findsOneWidget);
},
);
下面是我们在使用 hte 应用程序时允许权限的工作代码。
Future<void> allowNativePermissionIfDisplayed(PatrolIntegrationTester $) async {
debugPrint('Wait for permissions dialog and grant permissions');
if (await $.native.isPermissionDialogVisible()) {
debugPrint('Found permissions dialog');
await $.native.grantPermissionWhenInUse();
}
await $.pumpAndSettle();
}
可通过
$.native
访问