0

I have problem with Patrol while running integration test in Flutter. I need to accept some permissions and I want to use to this purpose Petrol package.But in terminal there is an error which seems like this:

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

Here is my code, in which I initialize 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);
  });
}

Thanks in advance for help :)

2 Answers 2

0

You can Not Use patrol in widget test You have to use patrolTest and patrol_cli and command would be :

patrol test integration_test/example_test.dart

eg:

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);
},
 );
Sign up to request clarification or add additional context in comments.

2 Comments

According to the documentation you can use patrol in widget test. patrol.leancode.co/native/advanced
Try to run with patrol_cli command. and according to me u can't use integration test binding while u using patrol.
0

Below is our working code to allow permissions while using hte app.

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

Its accessed via $.native

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.